修改接口的url路由,并修改文件中报错问题

This commit is contained in:
wanglei 2025-11-12 09:36:00 +08:00
parent 953e805a6b
commit c41075f2b5
16 changed files with 78 additions and 76 deletions

View File

@ -2,48 +2,48 @@
### 接口相关控制接口文件需要使用jwt进行token验证 ### ### 接口相关控制接口文件需要使用jwt进行token验证 ###
###################################################### ######################################################
#用户认证登陆相关 #用户认证登陆相关
location /api/user { location /yum/v1/system/user {
content_by_lua_file '${APP_PATH}/src/api/system/login.lua'; content_by_lua_file '${APP_PATH}/src/api/system/login.lua';
} }
#账号信息数据接口 #账号信息数据接口
location /api/system/accounts { location /yum/v1/system/accounts {
access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua'; access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua';
content_by_lua_file '${APP_PATH}/src/api/system/account.lua'; content_by_lua_file '${APP_PATH}/src/api/system/account.lua';
} }
#应用程序信息数据接口 #应用程序信息数据接口
location /api/system/applications { location /yum/v1/system/applications {
access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua'; access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua';
content_by_lua_file '${APP_PATH}/src/api/system/application.lua'; content_by_lua_file '${APP_PATH}/src/api/system/application.lua';
} }
#组织(岗位)信息数据接口 #组织(岗位)信息数据接口
location /api/system/departments { location /yum/v1/system/departments {
access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua'; access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua';
content_by_lua_file '${APP_PATH}/src/api/system/department.lua'; content_by_lua_file '${APP_PATH}/src/api/system/department.lua';
} }
#权限信息数据接口 #权限信息数据接口
location /api/system/permissions { location /yum/v1/system/permissions {
access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua'; access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua';
content_by_lua_file '${APP_PATH}/src/api/system/permission.lua'; content_by_lua_file '${APP_PATH}/src/api/system/permission.lua';
} }
#岗位信息数据接口 #岗位信息数据接口
location /api/system/positions { location /yum/v1/system/positions {
access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua'; access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua';
content_by_lua_file '${APP_PATH}/src/api/system/position.lua'; content_by_lua_file '${APP_PATH}/src/api/system/position.lua';
} }
#账号信息数据接口 #账号信息数据接口
location /api/system/roles { location /yum/v1/system/roles {
access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua'; access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua';
content_by_lua_file '${APP_PATH}/src/api/system/role.lua'; content_by_lua_file '${APP_PATH}/src/api/system/role.lua';
} }
#用户信息数据接口 #用户信息数据接口
location /api/system/users { location /yum/v1/system/users {
access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua'; access_by_lua_file '${APP_PATH}/src/auth/jwt-auth.lua';
content_by_lua_file '${APP_PATH}/src/api/system/user.lua'; content_by_lua_file '${APP_PATH}/src/api/system/user.lua';
} }
@ -52,6 +52,6 @@ location /api/system/users {
### oauth2.0 + openIDC 接口文件处理 ### ### oauth2.0 + openIDC 接口文件处理 ###
###################################################### ######################################################
#用户认证登陆相关 #用户认证登陆相关
location /api/oauth/v2 { location /yum/v1/oauth/v2 {
content_by_lua_file '${APP_PATH}/src/api/oauth/oauth.lua'; content_by_lua_file '${APP_PATH}/src/api/oauth/oauth.lua';
} }

View File

@ -15,43 +15,43 @@ local routes = {
-------------------------------------------- --------------------------------------------
--获取授权码 --获取授权码
{ {
paths = { "/api/oauth/v2/authorize" }, paths = { "/yum/v1/oauth/v2/authorize" },
methods = { "POST" }, methods = { "POST" },
handler = oauthService.authorize, handler = oauthService.authorize,
}, },
--根据授权码获取Access-Token --根据授权码获取Access-Token
{ {
paths = { "/api/oauth/v2/token" }, paths = { "/yum/v1/oauth/v2/token" },
methods = { "POST" }, methods = { "POST" },
handler = oauthService.token, handler = oauthService.token,
}, },
--通过用户名和密码进行验证 --通过用户名和密码进行验证
{ {
paths = { "/api/oauth/v2/login" }, paths = { "/yum/v1/oauth/v2/login" },
methods = { "POST" }, methods = { "POST" },
handler = oauthService.login, handler = oauthService.login,
}, },
--根据Access-Token获取相应用户的账户信息 --根据Access-Token获取相应用户的账户信息
{ {
paths = { "/api/oauth/v2/userinfo" }, paths = { "/yum/v1/oauth/v2/userinfo" },
methods = { "POST" }, methods = { "POST" },
handler = oauthService.userinfo, handler = oauthService.userinfo,
}, },
--回收Access-Token --回收Access-Token
{ {
paths = { "/api/oauth/v2/logout" }, paths = { "/yum/v1/oauth/v2/logout" },
methods = { "POST" }, methods = { "POST" },
handler = oauthService.logout, handler = oauthService.logout,
}, },
--根据Refresh-Token刷新Access-Token --根据Refresh-Token刷新Access-Token
{ {
paths = { "/api/oauth/v2/refresh" }, paths = { "/yum/v1/oauth/v2/refresh" },
methods = { "POST" }, methods = { "POST" },
handler = oauthService.refresh, handler = oauthService.refresh,
}, },
--验证token是否有效 --验证token是否有效
{ {
paths = { "/api/oauth/v2/checklogin" }, paths = { "/yum/v1/oauth/v2/checklogin" },
methods = { "POST" }, methods = { "POST" },
handler = oauthService.checklogin, handler = oauthService.checklogin,
}, },

View File

@ -13,7 +13,7 @@ local systemAccount = require("service.system.account")
local routes = { local routes = {
--账户相关路由接口 --账户相关路由接口
{ {
paths = { "/api/system/accounts" }, paths = { "/yum/v1/system/accounts" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::accounts::list" ngx.ctx.perms = "system::accounts::list"
@ -22,7 +22,7 @@ local routes = {
handler = systemAccount.getSystemAccounts, handler = systemAccount.getSystemAccounts,
}, },
{ {
paths = { "/api/system/accounts/:id" }, paths = { "/yum/v1/system/accounts/:id" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::accounts::view" ngx.ctx.perms = "system::accounts::view"
@ -31,7 +31,7 @@ local routes = {
handler = systemAccount.getSystemAccount, handler = systemAccount.getSystemAccount,
}, },
{ {
paths = { "/api/system/accounts" }, paths = { "/yum/v1/system/accounts" },
methods = { "POST" }, methods = { "POST" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::accounts::add" ngx.ctx.perms = "system::accounts::add"
@ -40,7 +40,7 @@ local routes = {
handler = systemAccount.addSystemAccount, handler = systemAccount.addSystemAccount,
}, },
{ {
paths = { "/api/system/accounts/:id" }, paths = { "/yum/v1/system/accounts/:id" },
methods = { "DELETE" }, methods = { "DELETE" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::accounts::delete" ngx.ctx.perms = "system::accounts::delete"
@ -49,7 +49,7 @@ local routes = {
handler = systemAccount.deleteSystemAccount, handler = systemAccount.deleteSystemAccount,
}, },
{ {
paths = { "/api/system/accounts/:id" }, paths = { "/yum/v1/system/accounts/:id" },
methods = { "PUT" }, methods = { "PUT" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::accounts::edit" ngx.ctx.perms = "system::accounts::edit"

View File

@ -13,7 +13,7 @@ local systemApplication = require("service.system.application")
local routes = { local routes = {
--应用相关路由接口 --应用相关路由接口
{ {
paths = { "/api/system/applications" }, paths = { "/yum/v1/system/applications" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::applications::list" ngx.ctx.perms = "system::applications::list"
@ -22,7 +22,7 @@ local routes = {
handler = systemApplication.getSystemApplications, handler = systemApplication.getSystemApplications,
}, },
{ {
paths = { "/api/system/applications/:id" }, paths = { "/yum/v1/system/applications/:id" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::applications::view" ngx.ctx.perms = "system::applications::view"
@ -31,7 +31,7 @@ local routes = {
handler = systemApplication.getSystemApplication, handler = systemApplication.getSystemApplication,
}, },
{ {
paths = { "/api/system/applications" }, paths = { "/yum/v1/system/applications" },
methods = { "POST" }, methods = { "POST" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::applications::add" ngx.ctx.perms = "system::applications::add"
@ -40,7 +40,7 @@ local routes = {
handler = systemApplication.addSystemApplication, handler = systemApplication.addSystemApplication,
}, },
{ {
paths = { "/api/system/applications/:id" }, paths = { "/yum/v1/system/applications/:id" },
methods = { "DELETE" }, methods = { "DELETE" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::applications::delete" ngx.ctx.perms = "system::applications::delete"
@ -49,7 +49,7 @@ local routes = {
handler = systemApplication.deleteSystemApplication, handler = systemApplication.deleteSystemApplication,
}, },
{ {
paths = { "/api/system/applications/:id" }, paths = { "/yum/v1/system/applications/:id" },
methods = { "PUT" }, methods = { "PUT" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::applications::edit" ngx.ctx.perms = "system::applications::edit"

View File

@ -13,7 +13,7 @@ local systemDepartment = require("service.system.department")
local routes = { local routes = {
--组织(部门)相关路由接口 --组织(部门)相关路由接口
{ {
paths = { "/api/system/departments" }, paths = { "/yum/v1/system/departments" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::departments::list" ngx.ctx.perms = "system::departments::list"
@ -22,7 +22,7 @@ local routes = {
handler = systemDepartment.getSystemDepartments, handler = systemDepartment.getSystemDepartments,
}, },
{ {
paths = { "/api/system/departments/:id" }, paths = { "/yum/v1/system/departments/:id" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::departments::view" ngx.ctx.perms = "system::departments::view"
@ -31,7 +31,7 @@ local routes = {
handler = systemDepartment.getSystemDepartment, handler = systemDepartment.getSystemDepartment,
}, },
{ {
paths = { "/api/system/departments" }, paths = { "/yum/v1/system/departments" },
methods = { "POST" }, methods = { "POST" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::departments::add" ngx.ctx.perms = "system::departments::add"
@ -40,7 +40,7 @@ local routes = {
handler = systemDepartment.addSystemDepartment, handler = systemDepartment.addSystemDepartment,
}, },
{ {
paths = { "/api/system/departments/:id" }, paths = { "/yum/v1/system/departments/:id" },
methods = { "DELETE" }, methods = { "DELETE" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::departments::delete" ngx.ctx.perms = "system::departments::delete"
@ -49,7 +49,7 @@ local routes = {
handler = systemDepartment.deleteSystemDepartment, handler = systemDepartment.deleteSystemDepartment,
}, },
{ {
paths = { "/api/system/departments/:id" }, paths = { "/yum/v1/system/departments/:id" },
methods = { "PUT" }, methods = { "PUT" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::departments::edit" ngx.ctx.perms = "system::departments::edit"

View File

@ -15,31 +15,31 @@ local routes = {
-------------------------------------------- --------------------------------------------
--用户登录路由接口 --用户登录路由接口
{ {
paths = { "/api/user/login" }, paths = { "/yum/v1/system/user/login" },
methods = { "POST" }, methods = { "POST" },
handler = loginService.login, handler = loginService.login,
}, },
--用户注册路由接口 --用户注册路由接口
{ {
paths = { "/api/user/signup" }, paths = { "/yum/v1/system/user/signup" },
methods = { "POST" }, methods = { "POST" },
handler = loginService.signup, handler = loginService.signup,
}, },
--用户退出路由接口 --用户退出路由接口
{ {
paths = { "/api/user/logout" }, paths = { "/yum/v1/system/user/logout" },
methods = { "POST" }, methods = { "POST" },
handler = loginService.logout, handler = loginService.logout,
}, },
--根据token信息获取用户信息数据 --根据token信息获取用户信息数据
{ {
paths = { "/api/user/user" }, paths = { "/yum/v1/system/user/user" },
methods = { "GET" }, methods = { "GET" },
handler = loginService.user, handler = loginService.user,
}, },
--根据token信息获取用户权限数据 --根据token信息获取用户权限数据
{ {
paths = { "/api/user/permission" }, paths = { "/yum/v1/system/user/permission" },
methods = { "GET" }, methods = { "GET" },
handler = loginService.permission, handler = loginService.permission,
}, },

View File

@ -13,7 +13,7 @@ local systemPermission = require("service.system.permission")
local routes = { local routes = {
--权限相关路由接口 --权限相关路由接口
{ {
paths = { "/api/system/permissions" }, paths = { "/yum/v1/system/permissions" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::permissions::list" ngx.ctx.perms = "system::permissions::list"
@ -22,7 +22,7 @@ local routes = {
handler = systemPermission.getSystemPermissions, handler = systemPermission.getSystemPermissions,
}, },
{ {
paths = { "/api/system/permissions/:id" }, paths = { "/yum/v1/system/permissions/:id" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::permissions::view" ngx.ctx.perms = "system::permissions::view"
@ -31,7 +31,7 @@ local routes = {
handler = systemPermission.getSystemPermission, handler = systemPermission.getSystemPermission,
}, },
{ {
paths = { "/api/system/permissions" }, paths = { "/yum/v1/system/permissions" },
methods = { "POST" }, methods = { "POST" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::permissions::add" ngx.ctx.perms = "system::permissions::add"
@ -40,7 +40,7 @@ local routes = {
handler = systemPermission.addSystemPermission, handler = systemPermission.addSystemPermission,
}, },
{ {
paths = { "/api/system/permissions/:id" }, paths = { "/yum/v1/system/permissions/:id" },
methods = { "DELETE" }, methods = { "DELETE" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::permissions::delete" ngx.ctx.perms = "system::permissions::delete"
@ -49,7 +49,7 @@ local routes = {
handler = systemPermission.deleteSystemPermission, handler = systemPermission.deleteSystemPermission,
}, },
{ {
paths = { "/api/system/permissions/:id" }, paths = { "/yum/v1/system/permissions/:id" },
methods = { "PUT" }, methods = { "PUT" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::permissions::edit" ngx.ctx.perms = "system::permissions::edit"

View File

@ -13,7 +13,7 @@ local systemPosition = require("service.system.position")
local routes = { local routes = {
--岗位相关路由接口 --岗位相关路由接口
{ {
paths = { "/api/system/positions" }, paths = { "/yum/v1/system/positions" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::positions::list" ngx.ctx.perms = "system::positions::list"
@ -22,7 +22,7 @@ local routes = {
handler = systemPosition.getSystemPositions, handler = systemPosition.getSystemPositions,
}, },
{ {
paths = { "/api/system/positions/:id" }, paths = { "/yum/v1/system/positions/:id" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::positions::view" ngx.ctx.perms = "system::positions::view"
@ -31,7 +31,7 @@ local routes = {
handler = systemPosition.getSystemPosition, handler = systemPosition.getSystemPosition,
}, },
{ {
paths = { "/api/system/positions" }, paths = { "/yum/v1/system/positions" },
methods = { "POST" }, methods = { "POST" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::positions::add" ngx.ctx.perms = "system::positions::add"
@ -40,7 +40,7 @@ local routes = {
handler = systemPosition.addSystemPosition, handler = systemPosition.addSystemPosition,
}, },
{ {
paths = { "/api/system/positions/:id" }, paths = { "/yum/v1/system/positions/:id" },
methods = { "DELETE" }, methods = { "DELETE" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::positions::delete" ngx.ctx.perms = "system::positions::delete"
@ -49,7 +49,7 @@ local routes = {
handler = systemPosition.deleteSystemPosition, handler = systemPosition.deleteSystemPosition,
}, },
{ {
paths = { "/api/system/positions/:id" }, paths = { "/yum/v1/system/positions/:id" },
methods = { "PUT" }, methods = { "PUT" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::positions::edit" ngx.ctx.perms = "system::positions::edit"

View File

@ -13,7 +13,7 @@ local systemRole = require("service.system.role")
local routes = { local routes = {
--角色相关路由接口 --角色相关路由接口
{ {
paths = { "/api/system/roles" }, paths = { "/yum/v1/system/roles" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::roles::list" ngx.ctx.perms = "system::roles::list"
@ -22,7 +22,7 @@ local routes = {
handler = systemRole.getSystemRoles, handler = systemRole.getSystemRoles,
}, },
{ {
paths = { "/api/system/roles/:id" }, paths = { "/yum/v1/system/roles/:id" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::roles::view" ngx.ctx.perms = "system::roles::view"
@ -31,7 +31,7 @@ local routes = {
handler = systemRole.getSystemRole, handler = systemRole.getSystemRole,
}, },
{ {
paths = { "/api/system/roles" }, paths = { "/yum/v1/system/roles" },
methods = { "POST" }, methods = { "POST" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::roles::add" ngx.ctx.perms = "system::roles::add"
@ -40,7 +40,7 @@ local routes = {
handler = systemRole.addSystemRole, handler = systemRole.addSystemRole,
}, },
{ {
paths = { "/api/system/roles/:id" }, paths = { "/yum/v1/system/roles/:id" },
methods = { "DELETE" }, methods = { "DELETE" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::roles::delete" ngx.ctx.perms = "system::roles::delete"
@ -49,7 +49,7 @@ local routes = {
handler = systemRole.deleteSystemRole, handler = systemRole.deleteSystemRole,
}, },
{ {
paths = { "/api/system/roles/:id" }, paths = { "/yum/v1/system/roles/:id" },
methods = { "PUT" }, methods = { "PUT" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::roles::edit" ngx.ctx.perms = "system::roles::edit"

View File

@ -13,7 +13,7 @@ local routes = {
--用户相关路由接口 --用户相关路由接口
--获取所有用户信息数据 --获取所有用户信息数据
{ {
paths = { "/api/system/users" }, paths = { "/yum/v1/system/users" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::users::list" ngx.ctx.perms = "system::users::list"
@ -23,7 +23,7 @@ local routes = {
}, },
--根据用户id获取用户详情信息 --根据用户id获取用户详情信息
{ {
paths = { "/api/system/users/:id" }, paths = { "/yum/v1/system/users/:id" },
methods = { "GET" }, methods = { "GET" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::users::view" ngx.ctx.perms = "system::users::view"
@ -33,7 +33,7 @@ local routes = {
}, },
--根据增加新的用户信息 --根据增加新的用户信息
{ {
paths = { "/api/system/users" }, paths = { "/yum/v1/system/users" },
methods = { "POST" }, methods = { "POST" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::users::add" ngx.ctx.perms = "system::users::add"
@ -43,7 +43,7 @@ local routes = {
}, },
--根据用户id删除用户信息 --根据用户id删除用户信息
{ {
paths = { "/api/system/users/:id" }, paths = { "/yum/v1/system/users/:id" },
methods = { "DELETE" }, methods = { "DELETE" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::users::delete" ngx.ctx.perms = "system::users::delete"
@ -53,7 +53,7 @@ local routes = {
}, },
--根据用户id编辑用户信息 --根据用户id编辑用户信息
{ {
paths = { "/api/system/users/:id" }, paths = { "/yum/v1/system/users/:id" },
methods = { "PUT" }, methods = { "PUT" },
filter_fun = function(vars) filter_fun = function(vars)
ngx.ctx.perms = "system::users::edit" ngx.ctx.perms = "system::users::edit"

View File

@ -53,7 +53,7 @@ end
-- write the uid variable -- write the uid variable
ngx.ctx.userid = jwt_obj.payload.userid ngx.ctx.userid = jwt_obj.payload.userid
ngx.ctx.username = jwt_obj.payload.username ngx.ctx.username = jwt_obj.payload.username
ngx.ctx.role = jwt_obj.payload.role ngx.ctx.role = jwt_obj.payload.role_name
ngx.log(ngx.WARN, "claims: ".. cjson.encode(jwt_obj.payload)) ngx.log(ngx.WARN, "claims: ".. cjson.encode(jwt_obj.payload))
--全部校验完成后,说明令牌有效,返回令牌数据 --全部校验完成后,说明令牌有效,返回令牌数据

View File

@ -108,7 +108,7 @@ function _M:adjustUser(name, passwd)
if name == nil or passwd == nil then if name == nil or passwd == nil then
return 0x010003, nil return 0x010003, nil
end end
local pwdMd5 = ngx.md5(passwd) local pwdMd5 = passwd--ngx.md5(passwd)
--根据用户进行验证用户是否存在 --根据用户进行验证用户是否存在
local code, res = userModel:where("username", "=", name):where("password", "=", pwdMd5):get() local code, res = userModel:where("username", "=", name):where("password", "=", pwdMd5):get()
if code == 0 and res ~= nil then if code == 0 and res ~= nil then

View File

@ -54,18 +54,16 @@ function _M.getSystemUser(m)
local role = ngx.ctx.role local role = ngx.ctx.role
--权限数据 --权限数据
local perms = ngx.ctx.perms local perms = ngx.ctx.perms
print("get getSystemUser", role, perms)
--判断当前接口用户和角色是否有权限 --判断当前接口用户和角色是否有权限
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 payload = ngx.var.uid local payload = ngx.var.uid
local metadata = m.metadata
ngx.log(ngx.INFO, "metadata value:"..metadata)
local userid = getUserId() local userid = getUserId()
if userid ~= m.id then if userid ~= m.id then
ngx.log(ngx.WARN, "用户与使用token中的用户id不一致") ngx.log(ngx.WARN, "用户与使用token中的用户id不一致", userid, m.id)
ngx.status = ngx.HTTP_NOT_ALLOWED ngx.status = ngx.HTTP_NOT_ALLOWED
ngx.exit(ngx.HTTP_NOT_ALLOWED) ngx.exit(ngx.HTTP_NOT_ALLOWED)
end end

View File

@ -24,6 +24,7 @@ function _M:hasPermission(role_name, permission)
-- 检查直接权限 -- 检查直接权限
local key = role_name.."-"..permission local key = role_name.."-"..permission
print("get permission key:", key)
local res, err = red:get(key) local res, err = red:get(key)
if res ~= nil then if res ~= nil then
return true return true

View File

@ -44,10 +44,12 @@ function _M:validatorToken(jsonData)
end end
local schemaLogin = { local schemaLogin = {
{type = "object", properties = { type = "object",
{name = "username", type = "string"}, properties = {
{name = "password", type = "string"}, username = { type = "string" },
}, required = {"username", "password"}} password = { type = "string" },
},
required = {"username", "password"}
} }
--回收Access-Token --回收Access-Token

View File

@ -9,16 +9,17 @@ local _M = {}
-- 定义一个JSON Schema -- 定义一个JSON Schema
local schema = { local schema = {
{type = "object", properties = { type = "object",
{name = "username", type = "string", minLength = 8, maxLength = 20}, properties = {
{name = "phone", type = "string",minLength = 11}, username = { type = "string" },
{name = "email", type = "string"}, phone = { type = "string" },
{name = "idcard", type = "string"}, email = { type = "string" },
{name = "name", type = "string"}, idcard = { type = "string" },
{name = "office_phone", type = "string"}, office_phone = { type = "string" },
{name = "telephone", type = "string",minLength = 11}, telephone = { type = "string" },
{name = "display_name", type = "string"}, display_name = { type = "string" },
}, required = {"username", "phone", "email", "idcard"}} },
required = { "username", "phone", "email", "idcard" }
} }
function _M.validatorJson(jsonData) function _M.validatorJson(jsonData)