Compare commits
2 Commits
e75cbc7282
...
7ab44b198e
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ab44b198e | |||
|
|
b450ff0413 |
|
|
@ -75,7 +75,7 @@ http {
|
||||||
token_endpoint = "http://localhost:9080yum/v1/oauth/v2/token",
|
token_endpoint = "http://localhost:9080yum/v1/oauth/v2/token",
|
||||||
userinfo_endpoint = "http://localhost:9080yum/v1/oauth/v2/userinfo",
|
userinfo_endpoint = "http://localhost:9080yum/v1/oauth/v2/userinfo",
|
||||||
--jwks_uri = "http://localhost:9080/jwks", -- 公钥端点(可选)
|
--jwks_uri = "http://localhost:9080/jwks", -- 公钥端点(可选)
|
||||||
grant_types_supported = [ "authorization_code", "token", "refresh_token" ], -- 新增支持 refresh_token
|
grant_types_supported = { "authorization_code", "token", "refresh_token" }, -- 新增支持 refresh_token
|
||||||
response_types_supported = { "code" },
|
response_types_supported = { "code" },
|
||||||
subject_types_supported = { "public" },
|
subject_types_supported = { "public" },
|
||||||
id_token_signing_alg_values_supported = { "HS256" },
|
id_token_signing_alg_values_supported = { "HS256" },
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@ local red = require("share.redis")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
--获取授权码
|
--获取uri中所携带的参数信息
|
||||||
function _M:authorize()
|
local function getUriArgs()
|
||||||
local args = ngx.req.get_uri_args()
|
local args = ngx.req.get_uri_args()
|
||||||
if ngx.req.get_method() == "POST" then
|
if ngx.req.get_method() == "POST" then
|
||||||
-- 读取请求体的数据
|
-- 读取请求体的数据
|
||||||
|
|
@ -30,12 +30,21 @@ function _M:authorize()
|
||||||
if not ok then
|
if not ok then
|
||||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
||||||
end
|
end
|
||||||
-- 校验客户端请求参数
|
args = data
|
||||||
ok = validator.validateAuthorize(data)
|
elseif ngx.req.get_method() == "GET" then
|
||||||
--验证失败则返回
|
args = ngx.req.get_uri_args()
|
||||||
if not ok then
|
end
|
||||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
return args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--获取授权码
|
||||||
|
function _M:authorize()
|
||||||
|
local args = getUriArgs()
|
||||||
|
-- 校验客户端请求参数
|
||||||
|
local ok = validator.validateAuthorize(args)
|
||||||
|
--验证失败则返回
|
||||||
|
if not ok then
|
||||||
|
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
||||||
end
|
end
|
||||||
-- 校验 response_type 必须为 "code"(授权码模式)
|
-- 校验 response_type 必须为 "code"(授权码模式)
|
||||||
if args.response_type ~= "code" then
|
if args.response_type ~= "code" then
|
||||||
|
|
@ -63,8 +72,7 @@ function _M:authorize()
|
||||||
local login_url = "/login?redirect=" .. ngx.escape_uri(ngx.var.request_uri)
|
local login_url = "/login?redirect=" .. ngx.escape_uri(ngx.var.request_uri)
|
||||||
--print("authorize login_url:", login_url)
|
--print("authorize login_url:", login_url)
|
||||||
--ngx.redirect(login_url)
|
--ngx.redirect(login_url)
|
||||||
local result = resp:json(ngx.HTTP_MOVED_TEMPORARILY, login_url)
|
resp:response(ngx.HTTP_MOVED_TEMPORARILY, login_url)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 4. 生成授权码(随机字符串,确保唯一性)(用户ID、客户端ID、scope、生成时间)
|
-- 4. 生成授权码(随机字符串,确保唯一性)(用户ID、客户端ID、scope、生成时间)
|
||||||
|
|
@ -80,24 +88,21 @@ function _M:authorize()
|
||||||
rest.redirect_uri = redirect_uri
|
rest.redirect_uri = redirect_uri
|
||||||
rest.code = auth_code
|
rest.code = auth_code
|
||||||
rest.state = args.state
|
rest.state = args.state
|
||||||
local result = resp:json(ngx.HTTP_OK, rest)
|
resp:response(ngx.HTTP_OK, rest)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 通过用户名认证用户和应用是否存在状态
|
-- 通过用户名认证用户和应用是否存在状态
|
||||||
local function authorizatePassword(args)
|
local function authorizatePassword(args)
|
||||||
-- 1.校验必填参数验证数据是否符合json
|
-- 1.校验必填参数验证数据是否符合json
|
||||||
local ok = validator.validateLogin(args)
|
local ok = validator.validateUserPasswd(args)
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 2.验证用户名和密码,应用程序id和应用程序密钥
|
-- 2.验证用户名和密码,应用程序id和应用程序密钥
|
||||||
local code, res = oauthDao.authenticateUserPasswd(args.username, args.password)
|
local code, res = oauthDao.authenticateUserPasswd(args.username, args.password)
|
||||||
if code ~= 0 or res == nil then
|
if code ~= 0 or res == nil then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
print("验证用户名和密码: ", args.username)
|
print("验证用户名和密码: ", args.username)
|
||||||
|
|
@ -107,8 +112,7 @@ local function authorizatePassword(args)
|
||||||
local client_secret = args.client_secret
|
local client_secret = args.client_secret
|
||||||
code, res = oauthDao.getApplicationByUserid(userid, client_id, client_secret)
|
code, res = oauthDao.getApplicationByUserid(userid, client_id, client_secret)
|
||||||
if code ~= 0 or res == nil then
|
if code ~= 0 or res == nil then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local redirect_uri = res[1].redirect_uris
|
local redirect_uri = res[1].redirect_uris
|
||||||
|
|
@ -124,8 +128,7 @@ local function authorizatePassword(args)
|
||||||
local rest = {}
|
local rest = {}
|
||||||
rest.redirect_uri = redirect_uri
|
rest.redirect_uri = redirect_uri
|
||||||
rest.code = auth_code
|
rest.code = auth_code
|
||||||
local result = resp:json(ngx.HTTP_OK, rest)
|
resp:response(ngx.HTTP_OK, rest)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 通过code形式进行认证
|
-- 通过code形式进行认证
|
||||||
|
|
@ -133,8 +136,7 @@ local function authorizateCode(args)
|
||||||
-- 1.校验必填参数验证数据是否符合json
|
-- 1.校验必填参数验证数据是否符合json
|
||||||
local ok = validator.validateToken(args)
|
local ok = validator.validateToken(args)
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 2.校验 code 有效性
|
-- 2.校验 code 有效性
|
||||||
|
|
@ -149,16 +151,14 @@ local function authorizateCode(args)
|
||||||
if request_uri ~= args.redirect_uri then
|
if request_uri ~= args.redirect_uri then
|
||||||
print("token redirect_url:", request_uri, args.redirect_uri)
|
print("token redirect_url:", request_uri, args.redirect_uri)
|
||||||
local login_url = "/login?redirect=" .. ngx.escape_uri(request_uri)
|
local login_url = "/login?redirect=" .. ngx.escape_uri(request_uri)
|
||||||
local result = resp:json(ngx.HTTP_MOVED_TEMPORARILY, login_url)
|
resp:response(ngx.HTTP_MOVED_TEMPORARILY, login_url)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 4.生成密钥对
|
-- 4.生成密钥对
|
||||||
--local pub_key, priv_key, err = rsa.generate_rsa_keys(2048)
|
--local pub_key, priv_key, err = rsa.generate_rsa_keys(2048)
|
||||||
--if err then
|
--if err then
|
||||||
-- print("密钥生成失败: ", err)
|
-- print("密钥生成失败: ", err)
|
||||||
-- local result = resp:json(0x00001)
|
-- resp:response(0x00001)
|
||||||
-- resp:send(result)
|
|
||||||
-- return
|
-- return
|
||||||
--end
|
--end
|
||||||
--print("token pubkey:", pub_key)
|
--print("token pubkey:", pub_key)
|
||||||
|
|
@ -185,13 +185,11 @@ local function authorizateCode(args)
|
||||||
-- 6.将生成的数据存储到数据库中
|
-- 6.将生成的数据存储到数据库中
|
||||||
local code, res = oauthDao.updateApplicationToken(client_id, ret)
|
local code, res = oauthDao.updateApplicationToken(client_id, ret)
|
||||||
if code ~= 0 then
|
if code ~= 0 then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 7.返回结果
|
-- 7.返回结果
|
||||||
local result = resp:json(ngx.HTTP_OK, ret)
|
resp:response(ngx.HTTP_OK, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 刷新令牌
|
-- 刷新令牌
|
||||||
|
|
@ -199,8 +197,7 @@ local function authorizateRefresh(args)
|
||||||
-- 1.校验必填参数验证数据是否符合json
|
-- 1.校验必填参数验证数据是否符合json
|
||||||
local res = validator.validateRefresh(args)
|
local res = validator.validateRefresh(args)
|
||||||
if not res then
|
if not res then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 2.验证并消费 refresh_token(滚动刷新:生成新的 rt)
|
-- 2.验证并消费 refresh_token(滚动刷新:生成新的 rt)
|
||||||
|
|
@ -227,39 +224,13 @@ local function authorizateRefresh(args)
|
||||||
ret.expires_in = conf.access_token_ttl
|
ret.expires_in = conf.access_token_ttl
|
||||||
ret.id_token = new_id_token
|
ret.id_token = new_id_token
|
||||||
-- 4.返回结果
|
-- 4.返回结果
|
||||||
local result = resp:json(ngx.HTTP_OK, ret)
|
resp:response(ngx.HTTP_OK, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 根据授权码获取Access-Token
|
-- 根据授权码获取Access-Token
|
||||||
function _M:token()
|
function _M:token()
|
||||||
-- 1. 解析请求参数(支持 form-data 和 json)
|
-- 1. 解析请求参数(支持 form-data 和 json)
|
||||||
local content_type = ngx.req.get_headers()["Content-Type"] or ""
|
local args = getUriArgs()
|
||||||
local args = {}
|
|
||||||
--print("token content_type:", content_type)
|
|
||||||
if string.find(content_type, "application/json") then
|
|
||||||
-- 读取请求体的数据
|
|
||||||
ngx.req.read_body()
|
|
||||||
-- 获取请求数据
|
|
||||||
local body_data = ngx.req.get_body_data()
|
|
||||||
if not body_data then
|
|
||||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
|
||||||
end
|
|
||||||
-- 验证json数据是否正确
|
|
||||||
local ok, data = pcall(cjson.decode, body_data)
|
|
||||||
if not ok then
|
|
||||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
|
||||||
end
|
|
||||||
args = data
|
|
||||||
else
|
|
||||||
if ngx.req.get_method() == "POST" then
|
|
||||||
-- 默认解析 form-urlencoded
|
|
||||||
args = ngx.req.get_post_args()
|
|
||||||
elseif ngx.req.get_method() == "GET" then
|
|
||||||
args = ngx.req.get_uri_args()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local grant_type = args.grant_type
|
local grant_type = args.grant_type
|
||||||
--print("grant_type类型: ", grant_type)
|
--print("grant_type类型: ", grant_type)
|
||||||
if grant_type == "password" then
|
if grant_type == "password" then
|
||||||
|
|
@ -299,8 +270,7 @@ function _M:userinfo()
|
||||||
--local pub_key, priv_key, err = rsa.generate_rsa_keys(2048)
|
--local pub_key, priv_key, err = rsa.generate_rsa_keys(2048)
|
||||||
--if err then
|
--if err then
|
||||||
-- --print("密钥生成失败: ", err)
|
-- --print("密钥生成失败: ", err)
|
||||||
-- local result = resp:json(0x00001)
|
-- resp:response(0x00001)
|
||||||
-- resp:send(result)
|
|
||||||
-- return
|
-- return
|
||||||
--end
|
--end
|
||||||
-- 4.对token进行验证
|
-- 4.对token进行验证
|
||||||
|
|
@ -329,8 +299,7 @@ function _M:userinfo()
|
||||||
local code, rest = oauthDao.getUser(user_id)
|
local code, rest = oauthDao.getUser(user_id)
|
||||||
--读取数据错误
|
--读取数据错误
|
||||||
if code ~= 0 or rest == nil then
|
if code ~= 0 or rest == nil then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 5.获取token中的信息进行所需用户的信息返回
|
-- 5.获取token中的信息进行所需用户的信息返回
|
||||||
|
|
@ -341,44 +310,18 @@ function _M:userinfo()
|
||||||
ret.real_name = rest[1].realname
|
ret.real_name = rest[1].realname
|
||||||
ret.office_phone = rest[1].office_phone
|
ret.office_phone = rest[1].office_phone
|
||||||
ret.email = rest[1].email
|
ret.email = rest[1].email
|
||||||
local result = resp:json(ngx.HTTP_OK, ret)
|
resp:response(ngx.HTTP_OK, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--回收token
|
--回收token
|
||||||
function _M:logout()
|
function _M:logout()
|
||||||
-- 1. 解析请求参数(支持 form-data 和 json)
|
-- 1. 解析请求参数(支持 form-data 和 json)
|
||||||
local content_type = ngx.req.get_headers()["Content-Type"] or ""
|
local args = getUriArgs()
|
||||||
local args = {}
|
|
||||||
print("logout token content_type:", content_type)
|
|
||||||
if string.find(content_type, "application/json") then
|
|
||||||
-- 读取请求体的数据
|
|
||||||
ngx.req.read_body()
|
|
||||||
-- 获取请求数据
|
|
||||||
local body_data = ngx.req.get_body_data()
|
|
||||||
if not body_data then
|
|
||||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
|
||||||
end
|
|
||||||
-- 验证json数据是否正确
|
|
||||||
local ok, data = pcall(cjson.decode, body_data)
|
|
||||||
if not ok then
|
|
||||||
return ngx.exit(ngx.HTTP_BAD_REQUEST)
|
|
||||||
end
|
|
||||||
args = data
|
|
||||||
else
|
|
||||||
if ngx.req.get_method() == "POST" then
|
|
||||||
-- 默认解析 form-urlencoded
|
|
||||||
args = ngx.req.get_post_args()
|
|
||||||
elseif ngx.req.get_method() == "GET" then
|
|
||||||
args = ngx.req.get_uri_args()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- 1、校验客户端id和redirect_uri是否存在数据库
|
-- 1、校验客户端id和redirect_uri是否存在数据库
|
||||||
local ok = validator.validateLogout(args)
|
local ok = validator.validateLogout(args)
|
||||||
if not ok then
|
if not ok then
|
||||||
print("validateLogout:", args)
|
print("validateLogout:", args)
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local token = args.access_token
|
local token = args.access_token
|
||||||
|
|
@ -433,9 +376,7 @@ function _M:logout()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- 5.获取token中的信息进行所需用户的信息返回
|
-- 5.获取token中的信息进行所需用户的信息返回
|
||||||
local ret = {}
|
resp:response(ngx.HTTP_OK)
|
||||||
local result = resp:json(ngx.HTTP_OK, ret)
|
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
@ -22,9 +22,8 @@ function _M.getSystemAccounts()
|
||||||
end
|
end
|
||||||
local pageNum = ngx.var.pagenum or 1
|
local pageNum = ngx.var.pagenum or 1
|
||||||
local pageSize = ngx.var.pagesize or 10
|
local pageSize = ngx.var.pagesize or 10
|
||||||
local code,ret = accountDao.getSystemAccounts(pageNum, pageSize)
|
local code, ret = accountDao.getSystemAccounts(pageNum, pageSize)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账户id获取账户信息
|
--根据账户id获取账户信息
|
||||||
|
|
@ -37,9 +36,8 @@ function _M.getSystemAccount(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local id = m.id
|
local id = m.id
|
||||||
local code,ret = accountDao.getSystemAccount(id)
|
local code, ret = accountDao.getSystemAccount(id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账户id获取账户信息
|
--根据账户id获取账户信息
|
||||||
|
|
@ -59,14 +57,12 @@ function _M.addSystemAccount()
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
-- 添加系统账户
|
||||||
local code, ret = accountDao.addSystemAccount(cjson.decode(body_data))
|
local code, ret = accountDao.addSystemAccount(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账户id删除账户信息
|
--根据账户id删除账户信息
|
||||||
|
|
@ -79,8 +75,7 @@ function _M.deleteSystemAccount(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code, ret = accountDao.deleteSystemAccount(m.id)
|
local code, ret = accountDao.deleteSystemAccount(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账户id删除账户信息
|
--根据账户id删除账户信息
|
||||||
|
|
@ -100,13 +95,11 @@ function _M.updateSystemAccount(m)
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = accountDao.updateSystemAccount(m.id, cjson.decode(body_data))
|
local code, ret = accountDao.updateSystemAccount(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,8 @@ function _M.getSystemApplications()
|
||||||
--获取页码和请求的数据量
|
--获取页码和请求的数据量
|
||||||
local pageNum = ngx.var.pagenum or 1
|
local pageNum = ngx.var.pagenum or 1
|
||||||
local pageSize = ngx.var.pagesize or 10
|
local pageSize = ngx.var.pagesize or 10
|
||||||
local code,ret = applicationDao.getSystemApplications()
|
local code, ret = applicationDao.getSystemApplications()
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据应用id获取应用信息
|
--根据应用id获取应用信息
|
||||||
|
|
@ -38,8 +37,7 @@ function _M.getSystemApplication(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code,ret = applicationDao.getSystemApplication(m.id)
|
local code,ret = applicationDao.getSystemApplication(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据组织id获取应用信息
|
--根据组织id获取应用信息
|
||||||
|
|
@ -51,9 +49,8 @@ function _M.getOrganizationApplication(m)
|
||||||
if perm:hasPermission(role, perms) == false then
|
if perm:hasPermission(role, perms) == false then
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code,ret = applicationDao.getOrganizationApplication(m.id)
|
local code, ret = applicationDao.getOrganizationApplication(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据用户id获取应用的信息
|
--根据用户id获取应用的信息
|
||||||
|
|
@ -65,9 +62,8 @@ function _M.getUserApplication(m)
|
||||||
if perm:hasPermission(role, perms) == false then
|
if perm:hasPermission(role, perms) == false then
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code,ret = applicationDao.getUserApplication(m.id)
|
local code, ret = applicationDao.getUserApplication(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据应用id获取应用信息
|
--根据应用id获取应用信息
|
||||||
|
|
@ -87,14 +83,12 @@ function _M.addSystemApplication()
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
-- 添加应用程序
|
||||||
local code, ret = applicationDao.addApplication(cjson.decode(body_data))
|
local code, ret = applicationDao.addApplication(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据应用id删除应用信息
|
--根据应用id删除应用信息
|
||||||
|
|
@ -107,8 +101,7 @@ function _M.deleteSystemApplication(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code, ret = applicationDao.deleteApplication(m.id)
|
local code, ret = applicationDao.deleteApplication(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据应用id删除应用信息
|
--根据应用id删除应用信息
|
||||||
|
|
@ -128,13 +121,11 @@ function _M.updateSystemApplication(m)
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = applicationDao.updateSystemApplication(m.id, cjson.decode(body_data))
|
local code, ret = applicationDao.updateSystemApplication(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,8 @@ function _M.getSystemDepartments()
|
||||||
if perm:hasPermission(role, perms) == false then
|
if perm:hasPermission(role, perms) == false then
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code,ret = departmentDao.getSystemDepartments()
|
local code, ret = departmentDao.getSystemDepartments()
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据组织id获取组织架构信息
|
--根据组织id获取组织架构信息
|
||||||
|
|
@ -34,9 +33,8 @@ function _M.getSystemDepartment(m)
|
||||||
if perm:hasPermission(role, perms) == false then
|
if perm:hasPermission(role, perms) == false then
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code,ret = departmentDao.getSystemDepartment(m.id)
|
local code, ret = departmentDao.getSystemDepartment(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据组织id添加组织架构信息
|
--根据组织id添加组织架构信息
|
||||||
|
|
@ -56,14 +54,12 @@ function _M.addSystemDepartment()
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = departmentDao.addSystemDepartment(cjson.decode(body_data))
|
local code, ret = departmentDao.addSystemDepartment(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据组织id删除组织架构信息
|
--根据组织id删除组织架构信息
|
||||||
|
|
@ -77,8 +73,7 @@ function _M.deleteSystemDepartment(m)
|
||||||
end
|
end
|
||||||
--删除部门数据
|
--删除部门数据
|
||||||
local code, ret = departmentDao.deleteSystemDepartment(m.id)
|
local code, ret = departmentDao.deleteSystemDepartment(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据组织id删除组织架构信息
|
--根据组织id删除组织架构信息
|
||||||
|
|
@ -98,13 +93,11 @@ function _M.updateSystemDepartment(m)
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = departmentDao.updateSystemDepartment(m.id, cjson.decode(body_data))
|
local code, ret = departmentDao.updateSystemDepartment(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@ function _M.login()
|
||||||
local ok, data = pcall(cjson.decode, body_data)
|
local ok, data = pcall(cjson.decode, body_data)
|
||||||
if not ok then
|
if not ok then
|
||||||
print("JSON解析失败:", data)
|
print("JSON解析失败:", data)
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 验证数据是否符合json
|
-- 验证数据是否符合json
|
||||||
|
|
@ -33,16 +32,14 @@ function _M.login()
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not valid then
|
if not valid then
|
||||||
print("验证失败: ", errors)
|
print("验证失败: ", errors)
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = loginDao.login(data)
|
local code, ret = loginDao.login(data)
|
||||||
--读取数据错误
|
--读取数据错误
|
||||||
if code ~= 0 or table.getn(ret) < 0 then
|
if code ~= 0 or table.getn(ret) < 0 then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local id = ret[1].id
|
local id = ret[1].id
|
||||||
|
|
@ -54,8 +51,7 @@ function _M.login()
|
||||||
local data = {}
|
local data = {}
|
||||||
data["token"] = jwt_token
|
data["token"] = jwt_token
|
||||||
data["userInfo"] = ret
|
data["userInfo"] = ret
|
||||||
local result = resp:json(code, data)
|
resp:response(code, data)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--用户注册业务逻辑处理
|
--用户注册业务逻辑处理
|
||||||
|
|
@ -68,29 +64,25 @@ function _M.signup()
|
||||||
local ok, data = pcall(cjson.decode, body_data)
|
local ok, data = pcall(cjson.decode, body_data)
|
||||||
if not ok then
|
if not ok then
|
||||||
print("JSON解析失败:", data)
|
print("JSON解析失败:", data)
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- 验证数据是否符合json
|
-- 验证数据是否符合json
|
||||||
local retJson = validator.validateJson(data)
|
local retJson = validator.validateJson(data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not retJson then
|
if not retJson then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = loginDao.signup(data)
|
local code, ret = loginDao.signup(data)
|
||||||
--读取数据错误
|
--读取数据错误
|
||||||
if code ~= 0 or table.getn(ret) < 0 then
|
if code ~= 0 or table.getn(ret) < 0 then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--返回注册成功信息
|
--返回注册成功信息
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--用户登出业务逻辑处理
|
--用户登出业务逻辑处理
|
||||||
|
|
@ -102,8 +94,7 @@ function _M.logout()
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
local code = ret["code"]
|
local code = ret["code"]
|
||||||
if code ~= 200 then
|
if code ~= 200 then
|
||||||
local result = resp:json(code, ret["message"])
|
resp:response(code, ret["message"])
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--验证成功记录登出的日志信息
|
--验证成功记录登出的日志信息
|
||||||
|
|
@ -112,8 +103,7 @@ function _M.logout()
|
||||||
local role_id = ret["body"]["payload"]["role_id"]
|
local role_id = ret["body"]["payload"]["role_id"]
|
||||||
local role_name = ret["body"]["payload"]["role_name"]
|
local role_name = ret["body"]["payload"]["role_name"]
|
||||||
ngx.log(ngx.INFO, "userid:"..userid.." username:"..username.." role_id:"..role_id.." role_name:"..role_name.." logout system")
|
ngx.log(ngx.INFO, "userid:"..userid.." username:"..username.." role_id:"..role_id.." role_name:"..role_name.." logout system")
|
||||||
local result = resp:json(0, "用户退出系统成功")
|
resp:response(0, "用户退出系统成功")
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据token获取用户信息
|
--根据token获取用户信息
|
||||||
|
|
@ -125,8 +115,7 @@ function _M.user()
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
local code = retToken["code"]
|
local code = retToken["code"]
|
||||||
if code ~= 200 then
|
if code ~= 200 then
|
||||||
local result = resp:json(code, retToken["message"])
|
resp:response(code, retToken["message"])
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--验证成功获取用户id信息
|
--验证成功获取用户id信息
|
||||||
|
|
@ -134,13 +123,11 @@ function _M.user()
|
||||||
local code, ret = loginDao.getUser(userid)
|
local code, ret = loginDao.getUser(userid)
|
||||||
--读取数据错误
|
--读取数据错误
|
||||||
if code ~= 0 or table.getn(ret) < 0 then
|
if code ~= 0 or table.getn(ret) < 0 then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--获取的登陆的用户信息
|
--返回登陆的用户信息
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据token获取用户登录权限
|
--根据token获取用户登录权限
|
||||||
|
|
@ -152,8 +139,7 @@ function _M.permission()
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
local code = retToken["code"]
|
local code = retToken["code"]
|
||||||
if code ~= 200 then
|
if code ~= 200 then
|
||||||
local result = resp:json(code, retToken["message"])
|
resp:response(code, retToken["message"])
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--验证成功获取用户id信息
|
--验证成功获取用户id信息
|
||||||
|
|
@ -165,13 +151,11 @@ function _M.permission()
|
||||||
local code, ret = loginDao.getUser(userid)
|
local code, ret = loginDao.getUser(userid)
|
||||||
--读取数据错误
|
--读取数据错误
|
||||||
if code ~= 0 or table.getn(ret) < 0 then
|
if code ~= 0 or table.getn(ret) < 0 then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--返回用户权限信息
|
--返回用户权限信息
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
@ -24,8 +24,7 @@ function _M.getSystemPermissions()
|
||||||
local pageNum = ngx.var.pagenum or 1
|
local pageNum = ngx.var.pagenum or 1
|
||||||
local pageSize = ngx.var.pagesize or 10
|
local pageSize = ngx.var.pagesize or 10
|
||||||
local code,ret = permissionDao.getSystemPermissions(pageNum, pageSize)
|
local code,ret = permissionDao.getSystemPermissions(pageNum, pageSize)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据权限id获取权限信息
|
--根据权限id获取权限信息
|
||||||
|
|
@ -38,8 +37,7 @@ function _M.get_permission(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code,ret = permissionDao.getPermission(m.id)
|
local code,ret = permissionDao.getPermission(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据角色id获取使用的权限
|
--根据角色id获取使用的权限
|
||||||
|
|
@ -52,8 +50,7 @@ function _M.getSystemPermissionByRole(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code,ret = dao.getPermissionByRole(m.id)
|
local code,ret = dao.getPermissionByRole(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据权限id获取账号信息
|
--根据权限id获取账号信息
|
||||||
|
|
@ -73,14 +70,12 @@ function _M.addSystemPermission()
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = permissionDao.addPermission(cjson.decode(body_data))
|
local code, ret = permissionDao.addPermission(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账号id删除账号信息
|
--根据账号id删除账号信息
|
||||||
|
|
@ -93,8 +88,7 @@ function _M.deleteSystemPermission(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code, ret = permissionDao.deleteSystemPermission(m.id)
|
local code, ret = permissionDao.deleteSystemPermission(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据账号id删除账号信息
|
--根据账号id删除账号信息
|
||||||
|
|
@ -114,13 +108,11 @@ function _M.updateSystemPermission(m)
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = permissionDao.updatePermission(m.id, cjson.decode(body_data))
|
local code, ret = permissionDao.updatePermission(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@ function _M.getSystemPositions()
|
||||||
local pageNum = ngx.var.pagenum or 1
|
local pageNum = ngx.var.pagenum or 1
|
||||||
local pageSize = ngx.var.pagesize or 10
|
local pageSize = ngx.var.pagesize or 10
|
||||||
local code,ret = positionDao.getSystemPositions(pageNum, pageSize)
|
local code,ret = positionDao.getSystemPositions(pageNum, pageSize)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据岗位id获取岗位信息
|
--根据岗位id获取岗位信息
|
||||||
|
|
@ -38,8 +37,7 @@ function _M.getSystemPosition(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code,ret = positionDao.getSystemPosition(m.id)
|
local code,ret = positionDao.getSystemPosition(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据岗位id添加岗位信息
|
--根据岗位id添加岗位信息
|
||||||
|
|
@ -59,14 +57,12 @@ function _M.addSystemPosition()
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = positionDao.addSystemPosition(cjson.decode(body_data))
|
local code, ret = positionDao.addSystemPosition(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据岗位id删除岗位信息
|
--根据岗位id删除岗位信息
|
||||||
|
|
@ -79,8 +75,7 @@ function _M.deleteSystemPosition(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code, ret = positionDao.deleteSystemPosition(m.id)
|
local code, ret = positionDao.deleteSystemPosition(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据岗位id删除岗位信息
|
--根据岗位id删除岗位信息
|
||||||
|
|
@ -100,13 +95,11 @@ function _M.updateSystemPosition(m)
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = positionDao.updateSystemPosition(m.id, cjson.decode(body_data))
|
local code, ret = positionDao.updateSystemPosition(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ function _M.getSystemRoles()
|
||||||
local pageNum = ngx.var.pagenum or 1
|
local pageNum = ngx.var.pagenum or 1
|
||||||
local pageSize = ngx.var.pagesize or 10
|
local pageSize = ngx.var.pagesize or 10
|
||||||
local code,ret = roleDao.getSystemRoles(pageNum, pageSize)
|
local code,ret = roleDao.getSystemRoles(pageNum, pageSize)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据角色id获取角色信息
|
--根据角色id获取角色信息
|
||||||
|
|
@ -39,8 +38,7 @@ function _M.getSystemRole(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code,ret = roleDao.getSystemRole(m.id)
|
local code,ret = roleDao.getSystemRole(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据角色id获取角色信息
|
--根据角色id获取角色信息
|
||||||
|
|
@ -60,14 +58,12 @@ function _M.addSystemRole()
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = roleDao.addSystemRole(cjson.decode(body_data))
|
local code, ret = roleDao.addSystemRole(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据角色id删除角色信息
|
--根据角色id删除角色信息
|
||||||
|
|
@ -80,8 +76,7 @@ function _M.deleteSystemRole(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code, ret = roleDao.deleteSystemRole(m.id)
|
local code, ret = roleDao.deleteSystemRole(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据角色id删除角色信息
|
--根据角色id删除角色信息
|
||||||
|
|
@ -101,13 +96,11 @@ function _M.updateSystemRole(m)
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = roleDao.updateSystemRole(m.id, cjson.decode(body_data))
|
local code, ret = roleDao.updateSystemRole(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,7 @@ function _M.getSystemUsers(m)
|
||||||
local pageNum = ngx.var.pagenum or 1
|
local pageNum = ngx.var.pagenum or 1
|
||||||
local pageSize = ngx.var.pagesize or 10
|
local pageSize = ngx.var.pagesize or 10
|
||||||
local code,ret = userDao.getSystemUsers(pageNum, pageSize)
|
local code,ret = userDao.getSystemUsers(pageNum, pageSize)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据用户id获取用户信息
|
--根据用户id获取用户信息
|
||||||
|
|
@ -68,8 +67,7 @@ function _M.getSystemUser(m)
|
||||||
ngx.exit(ngx.HTTP_NOT_ALLOWED)
|
ngx.exit(ngx.HTTP_NOT_ALLOWED)
|
||||||
end
|
end
|
||||||
local code,ret = userDao.getSystemUser(m.id)
|
local code,ret = userDao.getSystemUser(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据用户id获取用户信息
|
--根据用户id获取用户信息
|
||||||
|
|
@ -89,16 +87,14 @@ function _M.addSystemUser(m)
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local jsonData = cjson.decode(body_data)
|
local jsonData = cjson.decode(body_data)
|
||||||
--ngx.say(jsonData)
|
--ngx.say(jsonData)
|
||||||
local code, ret = userDao.addSystemUser(jsonData)
|
local code, ret = userDao.addSystemUser(jsonData)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据用户id删除用户信息
|
--根据用户id删除用户信息
|
||||||
|
|
@ -111,8 +107,7 @@ function _M.deleteSystemUser(m)
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
local code, ret = userDao.deleteSystemUser(m.id)
|
local code, ret = userDao.deleteSystemUser(m.id)
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--根据用户id删除用户信息
|
--根据用户id删除用户信息
|
||||||
|
|
@ -138,14 +133,12 @@ function _M.updateSystemUser(m)
|
||||||
local ok = validator.validateJson(body_data)
|
local ok = validator.validateJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
resp:response(0x000001)
|
||||||
resp:send(result)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--将数据更新到数据表中
|
--将数据更新到数据表中
|
||||||
local code, ret = userDao.updateSystemUser(m.id, cjson.decode(body_data))
|
local code, ret = userDao.updateSystemUser(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
resp:response(code, ret)
|
||||||
resp:send(result)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -77,4 +77,9 @@ function _M:send(response)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function _M:response(code, result)
|
||||||
|
local response = self:json(code, result)
|
||||||
|
self:send(response)
|
||||||
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,24 @@ local jsonschema = require("jsonschema")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
-- 定义一个JSON Schema
|
||||||
|
local schemaLogin = {
|
||||||
|
type = "object",
|
||||||
|
properties = {
|
||||||
|
client_id = { type = "string" },
|
||||||
|
client_secret = { type = "string" },
|
||||||
|
},
|
||||||
|
required = { "client_id", "client_secret" }
|
||||||
|
}
|
||||||
|
|
||||||
|
--通过用户名和密码进行认证
|
||||||
|
function _M.validateLogin(jsonData)
|
||||||
|
-- 验证数据是否符合schema
|
||||||
|
local validator = jsonschema.generate_validator(schemaLogin)
|
||||||
|
local result = validator(jsonData)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
-- 定义一个JSON Schema
|
||||||
local schemaAuth = {
|
local schemaAuth = {
|
||||||
type = "object",
|
type = "object",
|
||||||
|
|
@ -29,7 +47,7 @@ function _M.validateAuthorize(jsonData)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
-- 定义一个JSON Schema
|
||||||
local schemaLogin = {
|
local schemaUserPasswd = {
|
||||||
type = "object",
|
type = "object",
|
||||||
properties = {
|
properties = {
|
||||||
grant_type = { type = "string" },
|
grant_type = { type = "string" },
|
||||||
|
|
@ -42,9 +60,9 @@ local schemaLogin = {
|
||||||
}
|
}
|
||||||
|
|
||||||
--通过用户名和密码进行认证
|
--通过用户名和密码进行认证
|
||||||
function _M.validateLogin(jsonData)
|
function _M.validateUserPasswd(jsonData)
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local validator = jsonschema.generate_validator(schemaLogin)
|
local validator = jsonschema.generate_validator(schemaUserPasswd)
|
||||||
local result = validator(jsonData)
|
local result = validator(jsonData)
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user