接口返回统一增加时间戳,修改系统注册接口进行数据的注册
This commit is contained in:
parent
c72efce288
commit
0a5c44eea0
|
|
@ -32,7 +32,7 @@ local routes = {
|
||||||
handler = systemUser.deleteSystemUser,
|
handler = systemUser.deleteSystemUser,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
paths = { "/api/system/user/:id" },
|
paths = { "/api/system/users/:id" },
|
||||||
methods = { "PUT" },
|
methods = { "PUT" },
|
||||||
handler = systemUser.updateSystemUser,
|
handler = systemUser.updateSystemUser,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -69,6 +69,11 @@ function _M.logout(jsonData)
|
||||||
return code, ret
|
return code, ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--用户注册业务逻辑处理
|
||||||
|
function _M.signup(jsonData)
|
||||||
|
return userModel:addSystemUser(jsonData)
|
||||||
|
end
|
||||||
|
|
||||||
function _M.getUser(userid)
|
function _M.getUser(userid)
|
||||||
return userModel:find(userid)
|
return userModel:find(userid)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -65,23 +65,15 @@ function _M.signup()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = authDao.login(cjson.decode(body_data))
|
local code, ret = authDao.signup(cjson.decode(body_data))
|
||||||
--读取数据错误
|
--读取数据错误
|
||||||
if code ~= 0 or table.getn(ret) < 0 then
|
if code ~= 0 or table.getn(ret) < 0 then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--获取的登陆的用户信息,返回tocken
|
--返回注册成功信息
|
||||||
obj.payload.userid = ret["id"]
|
local result = resp:json(code, ret)
|
||||||
obj.payload.username = ret["name"]
|
|
||||||
obj.payload.role = ""
|
|
||||||
local jwt_token = jwt:sign(conf.secret_key, obj)
|
|
||||||
--ngx.say(jwt_token)
|
|
||||||
local data = {}
|
|
||||||
data["token"] = jwt_token
|
|
||||||
data["userInfo"] = ret
|
|
||||||
local result = resp:json(code, data)
|
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -135,36 +127,29 @@ end
|
||||||
|
|
||||||
--根据token获取用户登录权限
|
--根据token获取用户登录权限
|
||||||
function _M.permission()
|
function _M.permission()
|
||||||
--读取请求体的数据
|
--获取请求头中的令牌数据
|
||||||
ngx.req.read_body()
|
local auth_header = ngx.var.http_Authorization
|
||||||
--获取请求数据
|
--验证数据的正确性
|
||||||
local body_data = ngx.req.get_body_data()
|
local retToken = token.authorizationToken(auth_header)
|
||||||
-- 验证数据是否符合json
|
|
||||||
local retJson = validator.validatorJson(body_data)
|
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not retJson then
|
local code = retToken["code"]
|
||||||
local result = resp:json(0x000001)
|
if code ~= 200 then
|
||||||
|
local result = resp:json(code, retToken["message"])
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--验证成功获取用户id信息
|
||||||
local code, ret = authDao.login(cjson.decode(body_data))
|
local userid = retToken["body"]["payload"]["userid"]
|
||||||
|
--通过用户id查询到用户的权限信息
|
||||||
|
local code, ret = authDao.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)
|
local result = resp:json(0x000001)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--获取的登陆的用户信息,返回tocken
|
--返回用户权限信息
|
||||||
obj.payload.userid = ret["id"]
|
local result = resp:json(code, ret)
|
||||||
obj.payload.username = ret["name"]
|
|
||||||
obj.payload.role = ""
|
|
||||||
local jwt_token = jwt:sign(conf.secret_key, obj)
|
|
||||||
--ngx.say(jwt_token)
|
|
||||||
local data = {}
|
|
||||||
data["token"] = jwt_token
|
|
||||||
data["userInfo"] = ret
|
|
||||||
local result = resp:json(code, data)
|
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ function _M:json(status, message, data, http_status)
|
||||||
--end
|
--end
|
||||||
msg = error_code[status]
|
msg = error_code[status]
|
||||||
end
|
end
|
||||||
local response = {status=status, msg=msg, data=data}
|
local response = {status=status, msg=msg, data=data,timestamp=os.time()}
|
||||||
if not response.status then
|
if not response.status then
|
||||||
response.status = -1
|
response.status = -1
|
||||||
response.message = 'not find status code'
|
response.message = 'not find status code'
|
||||||
|
|
@ -34,7 +34,7 @@ function _M:json(status, data, http_status)
|
||||||
local response_status = http_status or ngx.OK
|
local response_status = http_status or ngx.OK
|
||||||
msg = error_code[status]
|
msg = error_code[status]
|
||||||
|
|
||||||
local response = {status=status, msg=msg, data=data}
|
local response = {status=status, msg=msg, data=data,timestamp=os.time()}
|
||||||
if not response.status then
|
if not response.status then
|
||||||
response.status = -1
|
response.status = -1
|
||||||
response.message = 'not find status code'
|
response.message = 'not find status code'
|
||||||
|
|
@ -50,7 +50,8 @@ function _M:raw(http_status, http_body)
|
||||||
return {
|
return {
|
||||||
status = http_status,
|
status = http_status,
|
||||||
headers = {},
|
headers = {},
|
||||||
body = http_body
|
body = http_body,
|
||||||
|
timestamp = os.time()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -58,7 +59,8 @@ function _M:error(http_status, http_headers, http_body)
|
||||||
return {
|
return {
|
||||||
status = http_status,
|
status = http_status,
|
||||||
headers = http_headers,
|
headers = http_headers,
|
||||||
body = http_body
|
body = http_body,
|
||||||
|
timestamp = ngx.now()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@ function _M.authorizationToken(auth_header)
|
||||||
return response
|
return response
|
||||||
end
|
end
|
||||||
--判断token是否超时
|
--判断token是否超时
|
||||||
if jwt_obj.payload.exp and ngx.time() > jwt_obj.payload.exp then
|
if jwt_obj.payload.exp and os.time() > jwt_obj.payload.exp then
|
||||||
response["code"] = 401
|
response["code"] = 401
|
||||||
response["message"] = "令牌已过期"
|
response["message"] = "令牌已过期"
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user