接口返回统一增加时间戳,修改系统注册接口进行数据的注册

This commit is contained in:
wanglei 2025-10-31 16:28:00 +08:00
parent c72efce288
commit 0a5c44eea0
5 changed files with 29 additions and 37 deletions

View File

@ -32,7 +32,7 @@ local routes = {
handler = systemUser.deleteSystemUser,
},
{
paths = { "/api/system/user/:id" },
paths = { "/api/system/users/:id" },
methods = { "PUT" },
handler = systemUser.updateSystemUser,
},

View File

@ -69,6 +69,11 @@ function _M.logout(jsonData)
return code, ret
end
--用户注册业务逻辑处理
function _M.signup(jsonData)
return userModel:addSystemUser(jsonData)
end
function _M.getUser(userid)
return userModel:find(userid)
end

View File

@ -65,23 +65,15 @@ function _M.signup()
return
end
--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
local result = resp:json(0x000001)
resp:send(result)
return
end
--获取的登陆的用户信息返回tocken
obj.payload.userid = ret["id"]
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)
--返回注册成功信息
local result = resp:json(code, ret)
resp:send(result)
end
@ -135,36 +127,29 @@ end
--根据token获取用户登录权限
function _M.permission()
--读取请求体的数据
ngx.req.read_body()
--获取请求数据
local body_data = ngx.req.get_body_data()
-- 验证数据是否符合json
local retJson = validator.validatorJson(body_data)
--获取请求头中的令牌数据
local auth_header = ngx.var.http_Authorization
--验证数据的正确性
local retToken = token.authorizationToken(auth_header)
--验证失败则返回
if not retJson then
local result = resp:json(0x000001)
local code = retToken["code"]
if code ~= 200 then
local result = resp:json(code, retToken["message"])
resp:send(result)
return
end
--ngx.say(body_data)
local code, ret = authDao.login(cjson.decode(body_data))
--验证成功获取用户id信息
local userid = retToken["body"]["payload"]["userid"]
--通过用户id查询到用户的权限信息
local code, ret = authDao.getUser(userid)
--读取数据错误
if code ~= 0 or table.getn(ret) < 0 then
local result = resp:json(0x000001)
resp:send(result)
return
end
--获取的登陆的用户信息返回tocken
obj.payload.userid = ret["id"]
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)
--返回用户权限信息
local result = resp:json(code, ret)
resp:send(result)
end

View File

@ -16,7 +16,7 @@ function _M:json(status, message, data, http_status)
--end
msg = error_code[status]
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
response.status = -1
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
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
response.status = -1
response.message = 'not find status code'
@ -50,7 +50,8 @@ function _M:raw(http_status, http_body)
return {
status = http_status,
headers = {},
body = http_body
body = http_body,
timestamp = os.time()
}
end
@ -58,7 +59,8 @@ function _M:error(http_status, http_headers, http_body)
return {
status = http_status,
headers = http_headers,
body = http_body
body = http_body,
timestamp = ngx.now()
}
end

View File

@ -64,7 +64,7 @@ function _M.authorizationToken(auth_header)
return response
end
--判断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["message"] = "令牌已过期"
return response