diff --git a/src/api/system/user.lua b/src/api/system/user.lua index 8ef7015..444cdee 100644 --- a/src/api/system/user.lua +++ b/src/api/system/user.lua @@ -32,7 +32,7 @@ local routes = { handler = systemUser.deleteSystemUser, }, { - paths = { "/api/system/user/:id" }, + paths = { "/api/system/users/:id" }, methods = { "PUT" }, handler = systemUser.updateSystemUser, }, diff --git a/src/dao/auth.lua b/src/dao/auth.lua index 1c26e25..8c1da3f 100644 --- a/src/dao/auth.lua +++ b/src/dao/auth.lua @@ -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 diff --git a/src/service/auth/auth.lua b/src/service/auth/auth.lua index 0029f4c..500ea81 100644 --- a/src/service/auth/auth.lua +++ b/src/service/auth/auth.lua @@ -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 diff --git a/src/util/response.lua b/src/util/response.lua index f19248b..6f33ccd 100644 --- a/src/util/response.lua +++ b/src/util/response.lua @@ -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 diff --git a/src/util/token.lua b/src/util/token.lua index 0da0262..cc98abf 100644 --- a/src/util/token.lua +++ b/src/util/token.lua @@ -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