Compare commits
No commits in common. "0a5c44eea0e7bd650b0c37620f977b45abc2ae5f" and "4022a395c81d0e1290d90d222b732ad06e3a5f2a" have entirely different histories.
0a5c44eea0
...
4022a395c8
|
|
@ -1,4 +1,4 @@
|
||||||
#API接口文件
|
#API接口文件
|
||||||
location /api/auth {
|
location /api/auth {
|
||||||
content_by_lua_file '${APP_PATH}/src/api/auth/auth.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/auth/auth.lua';
|
||||||
}
|
}
|
||||||
|
|
@ -8,12 +8,11 @@ events {
|
||||||
}
|
}
|
||||||
|
|
||||||
http {
|
http {
|
||||||
|
|
||||||
##lua_need_request_body on; #开启读取请求体数据
|
##lua_need_request_body on; #开启读取请求体数据
|
||||||
client_max_body_size 1024M; #允许最大100k的请求体
|
client_max_body_size 1024M; #允许最大100k的请求体
|
||||||
client_body_buffer_size 1024M; #设置缓冲区大小
|
client_body_buffer_size 1024M; #设置缓冲区大小
|
||||||
|
|
||||||
lua_package_path '$prefix/src/?/?.lua;$prefix/src/?.lua;/home/frankly/work/AuthPlatform/src/?/?.lua;/home/frankly/work/AuthPlatform/src/?.lua;;';
|
lua_package_path '$prefix/src/?/?.lua;$prefix/src/?.lua;/home/frankly/work/AuthPlatform/src/?.lua;/home/frankly/work/AuthPlatform/src/?/?.lua;;';
|
||||||
lua_package_cpath '$prefix/src/share/lib/?.so;;';
|
lua_package_cpath '$prefix/src/share/lib/?.so;;';
|
||||||
|
|
||||||
# Path of the file with trusted CA certificates.
|
# Path of the file with trusted CA certificates.
|
||||||
|
|
@ -30,12 +29,9 @@ http {
|
||||||
log_not_found off;
|
log_not_found off;
|
||||||
access_log off;
|
access_log off;
|
||||||
}
|
}
|
||||||
## 应用路径
|
|
||||||
set $APP_PATH '/home/frankly/work/AuthPlatform';
|
|
||||||
|
|
||||||
#登录认证配置
|
|
||||||
include 'auth/auth.conf';
|
include 'auth/auth.conf';
|
||||||
#数据列表配置
|
|
||||||
include 'system/account.conf';
|
include 'system/account.conf';
|
||||||
include 'system/application.conf';
|
include 'system/application.conf';
|
||||||
include 'system/department.conf';
|
include 'system/department.conf';
|
||||||
|
|
@ -43,17 +39,13 @@ http {
|
||||||
include 'system/role.conf';
|
include 'system/role.conf';
|
||||||
include 'system/user.conf';
|
include 'system/user.conf';
|
||||||
|
|
||||||
#测试接口配置
|
#测试接口文件
|
||||||
location /testSQL {
|
location /testSQL {
|
||||||
content_by_lua_file '${APP_PATH}/src/test/testPostgres.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testPostgres.lua';
|
||||||
}
|
}
|
||||||
|
|
||||||
location /cjson {
|
location /cjson {
|
||||||
content_by_lua_file '${APP_PATH}/src/test/test.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/test.lua';
|
||||||
}
|
|
||||||
#jwt验证进行测试
|
|
||||||
location /api/test {
|
|
||||||
access_by_lua_file '${APP_PATH}/src/util/jwt-auth.lua';
|
|
||||||
proxy_pass http://192.168.147.1:3000;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#API接口文件
|
#API接口文件
|
||||||
location /api/system/accounts {
|
location /api/system/accounts {
|
||||||
content_by_lua_file '${APP_PATH}/src/api/system/account.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/account.lua';
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#API接口文件
|
#API接口文件
|
||||||
location /api/system/applications {
|
location /api/system/applications {
|
||||||
content_by_lua_file '${APP_PATH}/src/api/system/application.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/application.lua';
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#API接口文件
|
#API接口文件
|
||||||
location /api/system/organizations {
|
location /api/system/organizations {
|
||||||
content_by_lua_file '${APP_PATH}/src/api/system/organization.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/organization.lua';
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#API接口文件
|
#API接口文件
|
||||||
location /api/system/permissions {
|
location /api/system/permissions {
|
||||||
content_by_lua_file '${APP_PATH}/src/api/system/permission.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/permission.lua';
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#API接口文件
|
#API接口文件
|
||||||
location /api/system/roles {
|
location /api/system/roles {
|
||||||
content_by_lua_file '${APP_PATH}/src/api/system/role.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/role.lua';
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#API接口文件
|
#API接口文件
|
||||||
location /api/system/users {
|
location /api/system/users {
|
||||||
content_by_lua_file '${APP_PATH}/src/api/system/user.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/system/user.lua';
|
||||||
}
|
}
|
||||||
|
|
@ -11,7 +11,7 @@ local authService = require("service.auth.auth")
|
||||||
--定义相关路由,前端接口url地址
|
--定义相关路由,前端接口url地址
|
||||||
local routes = {
|
local routes = {
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
-------------用户认证相关路由配置--------------
|
-------------用户登录相关路由配置--------------
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
--用户登录路由接口
|
--用户登录路由接口
|
||||||
{
|
{
|
||||||
|
|
@ -19,30 +19,12 @@ local routes = {
|
||||||
methods = { "POST" },
|
methods = { "POST" },
|
||||||
handler = authService.login,
|
handler = authService.login,
|
||||||
},
|
},
|
||||||
--用户注册路由接口
|
|
||||||
{
|
|
||||||
paths = { "/api/auth/signup" },
|
|
||||||
methods = { "POST" },
|
|
||||||
handler = authService.signup,
|
|
||||||
},
|
|
||||||
--用户退出路由接口
|
--用户退出路由接口
|
||||||
{
|
{
|
||||||
paths = { "/api/auth/logout" },
|
paths = { "/api/auth/logout/:id" },
|
||||||
methods = { "POST" },
|
methods = { "POST" },
|
||||||
handler = authService.logout,
|
handler = authService.logout,
|
||||||
},
|
},
|
||||||
--根据token信息获取用户信息数据
|
|
||||||
{
|
|
||||||
paths = { "/api/auth/user" },
|
|
||||||
methods = { "GET" },
|
|
||||||
handler = authService.user,
|
|
||||||
},
|
|
||||||
--根据token信息获取用户权限数据
|
|
||||||
{
|
|
||||||
paths = { "/api/auth/permission" },
|
|
||||||
methods = { "GET" },
|
|
||||||
handler = authService.permission,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
-- 初始化路由
|
-- 初始化路由
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ local routes = {
|
||||||
handler = systemUser.deleteSystemUser,
|
handler = systemUser.deleteSystemUser,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
paths = { "/api/system/users/:id" },
|
paths = { "/api/system/user/:id" },
|
||||||
methods = { "PUT" },
|
methods = { "PUT" },
|
||||||
handler = systemUser.updateSystemUser,
|
handler = systemUser.updateSystemUser,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,7 @@
|
||||||
--- Created by frankly.
|
--- Created by frankly.
|
||||||
--- DateTime: 2025/10/29 23:36
|
--- DateTime: 2025/10/29 23:36
|
||||||
---
|
---
|
||||||
--引用使用的库文件
|
local userDao = require("dao.user")
|
||||||
local model = require("share.model")
|
|
||||||
--创建一个数据表相关的模型
|
|
||||||
local userModel = model:new('sys_user')
|
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -21,17 +18,17 @@ local function authenticate(name, passwd)
|
||||||
return 0x010002, nil
|
return 0x010002, nil
|
||||||
end
|
end
|
||||||
--根据用户进行验证用户是否存在
|
--根据用户进行验证用户是否存在
|
||||||
local code, res = userModel:where("username", "=", name):where("password", "=", passwd):get()
|
local code, res = userDao:where("name", "=", name):where("password", "=", passwd):get()
|
||||||
if code == 0 and res ~= nil then
|
if code == 0 and res ~= nil then
|
||||||
return code, res
|
return code, res
|
||||||
end
|
end
|
||||||
--根据手机号进行验证用户是否存在
|
--根据手机号进行验证用户是否存在
|
||||||
code, res = userModel:where("phone", "=", name):where("password", "=", passwd):get()
|
code, res = userDao:where("phone", "=", name):where("password", "=", passwd):get()
|
||||||
if code == 0 and res ~= nil then
|
if code == 0 and res ~= nil then
|
||||||
return code, res
|
return code, res
|
||||||
end
|
end
|
||||||
--根据邮箱进行验证用户是否存在
|
--根据邮箱进行验证用户是否存在
|
||||||
code, res = userModel:where("email", "=", name):where("password", "=", passwd):get()
|
code, res = userDao:where("email", "=", name):where("password", "=", passwd):get()
|
||||||
if code == 0 and res ~= nil then
|
if code == 0 and res ~= nil then
|
||||||
return code, res
|
return code, res
|
||||||
end
|
end
|
||||||
|
|
@ -42,7 +39,7 @@ end
|
||||||
--用户登录业务逻辑处理
|
--用户登录业务逻辑处理
|
||||||
function _M.login(jsonData)
|
function _M.login(jsonData)
|
||||||
--解析json中的键和数据值
|
--解析json中的键和数据值
|
||||||
local name = jsonData["username"]
|
local name = jsonData["name"]
|
||||||
local passwd = jsonData["password"]
|
local passwd = jsonData["password"]
|
||||||
local captcha = jsonData["captcha"]
|
local captcha = jsonData["captcha"]
|
||||||
local checkKey = jsonData["checkKey"]
|
local checkKey = jsonData["checkKey"]
|
||||||
|
|
@ -69,13 +66,4 @@ 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)
|
|
||||||
return userModel:find(userid)
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
@ -3,152 +3,82 @@
|
||||||
--- Created by admin.
|
--- Created by admin.
|
||||||
--- DateTime: 2025/10/28 11:09
|
--- DateTime: 2025/10/28 11:09
|
||||||
---
|
---
|
||||||
|
local jsonschema = require("jsonschema")
|
||||||
local resp = require("util.response")
|
local resp = require("util.response")
|
||||||
local authDao = require("dao.auth")
|
local authDao = require("dao.auth")
|
||||||
local validator = require("validator.auth.auth")
|
local jwt = require("resty.jwt")
|
||||||
local cjson = require("cjson.safe")
|
local conf = require("config")
|
||||||
local token = require("util.token")
|
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
-- 定义一个JSON Schema
|
||||||
|
local schema = {
|
||||||
|
{type = "object", properties = {
|
||||||
|
{name = "username", type = "string"},
|
||||||
|
{name = "password", type = "string"},
|
||||||
|
{name = "captcha", type = "string"},
|
||||||
|
{name = "checkKey", type = "string"},
|
||||||
|
}, required = {"username", "password"}}
|
||||||
|
}
|
||||||
|
|
||||||
|
--设置JWT的有效载荷
|
||||||
|
local obj = {
|
||||||
|
header = {typ="JWT", alg="HS256"},
|
||||||
|
payload = { -- 自定义数据
|
||||||
|
username = "",
|
||||||
|
role = "",
|
||||||
|
--iss = "your_issuer", -- 签发者
|
||||||
|
--sub = "1234567890", -- 主题
|
||||||
|
exp = os.time() + 3600, -- 过期时间(例如:当前时间+1小时)
|
||||||
|
iat = os.time() -- 签发时间
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
--用户登录业务逻辑处理
|
--用户登录业务逻辑处理
|
||||||
function _M.login()
|
function _M.login()
|
||||||
--读取请求体的数据
|
--读取请求体的数据
|
||||||
ngx.req.read_body()
|
ngx.req.read_body()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合json
|
-- 验证数据是否符合schema
|
||||||
local retJson = validator.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not retJson then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
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.login(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
|
||||||
local id = ""
|
|
||||||
local username = ""
|
|
||||||
for _, row in ipairs(ret) do
|
|
||||||
id = row.id
|
|
||||||
username = row.username
|
|
||||||
end
|
|
||||||
|
|
||||||
--获取的登陆的用户信息,返回tocken
|
--获取的登陆的用户信息,返回tocken
|
||||||
--ngx.log(ngx.INFO, "userid:"..id.." username:"..username)
|
obj.payload.username = body_data["name"]
|
||||||
local jwt_token = token.generateToken(id, username)
|
obj.payload.role = ""
|
||||||
local data = {}
|
local jwt_token = jwt:sign(conf.secret_key, obj)
|
||||||
data["token"] = jwt_token
|
ngx.say(jwt_token)
|
||||||
data["userInfo"] = ret
|
|
||||||
local result = resp:json(code, data)
|
|
||||||
resp:send(result)
|
|
||||||
end
|
|
||||||
|
|
||||||
--用户注册业务逻辑处理
|
|
||||||
function _M.signup()
|
|
||||||
--读取请求体的数据
|
|
||||||
ngx.req.read_body()
|
|
||||||
--获取请求数据
|
|
||||||
local body_data = ngx.req.get_body_data()
|
|
||||||
-- 验证数据是否符合json
|
|
||||||
local retJson = validator.validatorJson(body_data)
|
|
||||||
--验证失败则返回
|
|
||||||
if not retJson then
|
|
||||||
local result = resp:json(0x000001)
|
|
||||||
resp:send(result)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
--ngx.say(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
|
|
||||||
--返回注册成功信息
|
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
--用户登出业务逻辑处理
|
--用户登出业务逻辑处理
|
||||||
function _M.logout()
|
function _M.logout()
|
||||||
--获取请求头中的令牌数据
|
--读取请求体的数据
|
||||||
local auth_header = ngx.var.http_Authorization
|
ngx.req.read_body()
|
||||||
--验证数据的正确性
|
--获取请求数据
|
||||||
local ret = token.authorizationToken(auth_header)
|
local body_data = ngx.req.get_body_data()
|
||||||
--验证失败则返回
|
--判断请求体数据是否为空
|
||||||
local code = ret["code"]
|
if body_data == nil then
|
||||||
if code ~= 200 then
|
|
||||||
local result = resp:json(code, ret["message"])
|
|
||||||
resp:send(result)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
--验证成功记录登出的日志信息
|
|
||||||
local userid = ret["body"]["payload"]["userid"]
|
|
||||||
local username = ret["body"]["payload"]["username"]
|
|
||||||
ngx.log(ngx.INFO, "userid:"..userid.." username:"..username.." logout system")
|
|
||||||
local result = resp:json(0, "用户退出系统成功")
|
|
||||||
resp:send(result)
|
|
||||||
end
|
|
||||||
|
|
||||||
--根据token获取用户信息
|
|
||||||
function _M.user()
|
|
||||||
--获取请求头中的令牌数据
|
|
||||||
local auth_header = ngx.var.http_Authorization
|
|
||||||
--验证数据的正确性
|
|
||||||
local retToken = token.authorizationToken(auth_header)
|
|
||||||
--验证失败则返回
|
|
||||||
local code = retToken["code"]
|
|
||||||
if code ~= 200 then
|
|
||||||
local result = resp:json(code, retToken["message"])
|
|
||||||
resp:send(result)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
--验证成功获取用户id信息
|
|
||||||
local userid = retToken["body"]["payload"]["userid"]
|
|
||||||
local code, ret = authDao.getUser(userid)
|
|
||||||
--读取数据错误
|
|
||||||
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
|
||||||
--获取的登陆的用户信息
|
--ngx.say(body_data)
|
||||||
local result = resp:json(code, ret)
|
local code, ret = authDao.logout(body_data)
|
||||||
resp:send(result)
|
|
||||||
end
|
|
||||||
|
|
||||||
--根据token获取用户登录权限
|
|
||||||
function _M.permission()
|
|
||||||
--获取请求头中的令牌数据
|
|
||||||
local auth_header = ngx.var.http_Authorization
|
|
||||||
--验证数据的正确性
|
|
||||||
local retToken = token.authorizationToken(auth_header)
|
|
||||||
--验证失败则返回
|
|
||||||
local code = retToken["code"]
|
|
||||||
if code ~= 200 then
|
|
||||||
local result = resp:json(code, retToken["message"])
|
|
||||||
resp:send(result)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
--验证成功获取用户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
|
|
||||||
--返回用户权限信息
|
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,25 @@
|
||||||
--- Created by .
|
--- Created by .
|
||||||
--- DateTime: 2025/9/25 08:25
|
--- DateTime: 2025/9/25 08:25
|
||||||
--- 业务逻辑 对账户数据表进行数据表业务处理
|
--- 业务逻辑 对账户数据表进行数据表业务处理
|
||||||
|
local jsonschema = require("jsonschema")
|
||||||
local resp = require("util.response")
|
local resp = require("util.response")
|
||||||
local accountDao = require("dao.account")
|
local accountDao = require("dao.account")
|
||||||
local validatorJson = require("validator.system.account")
|
|
||||||
local cjson = require("cjson.safe")
|
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
-- 定义一个JSON Schema
|
||||||
|
local schema = {
|
||||||
|
{type = "object", properties = {
|
||||||
|
{name = "name", type = "string"},
|
||||||
|
{name = "password", type = "string"},
|
||||||
|
{name = "real_name", type = "string"},
|
||||||
|
{name = "department", type = "string"},
|
||||||
|
{name = "office_phone", type = "string"},
|
||||||
|
{name = "telephone", type = "string"},
|
||||||
|
{name = "display_name", type = "string"},
|
||||||
|
}, required = {"username"}}
|
||||||
|
}
|
||||||
|
|
||||||
--获取所有账户信息
|
--获取所有账户信息
|
||||||
function _M.getSystemAccounts()
|
function _M.getSystemAccounts()
|
||||||
local pageNum = ngx.var.pagenum or 1
|
local pageNum = ngx.var.pagenum or 1
|
||||||
|
|
@ -34,7 +46,7 @@ function _M.addSystemAccount()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
|
|
@ -42,7 +54,7 @@ function _M.addSystemAccount()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = accountDao.addSystemAccount(cjson.decode(body_data))
|
local code, ret = accountDao.addSystemAccount(body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -60,15 +72,13 @@ function _M.updateSystemAccount(m)
|
||||||
ngx.req.read_body()
|
ngx.req.read_body()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
--判断请求体数据是否为空
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
if body_data == nil then
|
||||||
--验证失败则返回
|
|
||||||
if not ok then
|
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
resp:send(result)
|
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, body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,27 @@
|
||||||
--- Created by .
|
--- Created by .
|
||||||
--- DateTime: 2025/9/27 16:02
|
--- DateTime: 2025/9/27 16:02
|
||||||
--- 业务逻辑 对应用数据表进行数据表业务处理
|
--- 业务逻辑 对应用数据表进行数据表业务处理
|
||||||
|
local jsonschema = require("jsonschema")
|
||||||
local resp = require("util.response")
|
local resp = require("util.response")
|
||||||
local applicationDao = require("dao.application")
|
local applicationDao = require("dao.application")
|
||||||
local validatorJson = require("validator.system.application")
|
|
||||||
local cjson = require("cjson.safe")
|
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
-- 定义一个JSON Schema
|
||||||
|
local schema = {
|
||||||
|
{type = "object", properties = {
|
||||||
|
{name = "name", type = "string"},
|
||||||
|
{name = "display_name", type = "string"},
|
||||||
|
{name = "logo", type = "string"},
|
||||||
|
{name = "title", type = "string"},
|
||||||
|
{name = "name", type = "string"},
|
||||||
|
{name = "favicon", type = "string"},
|
||||||
|
{name = "description", type = "string"},
|
||||||
|
{name = "homepage_url", type = "string"},
|
||||||
|
{name = "redirect_uris", type = "string"},
|
||||||
|
}, required = {"name", "redirect_uris"}}
|
||||||
|
}
|
||||||
|
|
||||||
--获取所有应用程序信息
|
--获取所有应用程序信息
|
||||||
function _M.getSystemApplications()
|
function _M.getSystemApplications()
|
||||||
--获取页码和请求的数据量
|
--获取页码和请求的数据量
|
||||||
|
|
@ -48,7 +62,7 @@ function _M.addSystemApplication()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
|
|
@ -56,7 +70,7 @@ function _M.addSystemApplication()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = applicationDao.addApplication(cjson.decode(body_data))
|
local code, ret = applicationDao.addApplication(body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -75,14 +89,14 @@ function _M.updateSystemApplication(m)
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
resp:send(result)
|
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, body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,26 @@
|
||||||
--- Created by .
|
--- Created by .
|
||||||
--- DateTime: 2025/9/28 10:22
|
--- DateTime: 2025/9/28 10:22
|
||||||
--- 业务逻辑 对组织架构数据表进行数据表业务处理
|
--- 业务逻辑 对组织架构数据表进行数据表业务处理
|
||||||
|
local jsonschema = require("jsonschema")
|
||||||
local resp = require("util.response")
|
local resp = require("util.response")
|
||||||
local departmentDao = require("dao.department")
|
local departmentDao = require("dao.department")
|
||||||
local validatorJson = require("validator.system.department")
|
|
||||||
local cjson = require("cjson.safe")
|
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
-- 定义一个JSON Schema
|
||||||
|
local schema = {
|
||||||
|
{type = "object", properties = {
|
||||||
|
{name = "name", type = "string"},
|
||||||
|
{name = "seq", type = "string"},
|
||||||
|
{name = "description", type = "string"},
|
||||||
|
{name = "create_by", type = "string"},
|
||||||
|
{name = "update_by", type = "string"},
|
||||||
|
{name = "parent_id", type = "string"},
|
||||||
|
{name = "leader", type = "string"},
|
||||||
|
{name = "status", type = "string"},
|
||||||
|
}, required = {"name"}}
|
||||||
|
}
|
||||||
|
|
||||||
--获取所有组织架构信息
|
--获取所有组织架构信息
|
||||||
function _M.getSystemDepartments()
|
function _M.getSystemDepartments()
|
||||||
--获取页码和请求的数据量
|
--获取页码和请求的数据量
|
||||||
|
|
@ -34,7 +47,7 @@ function _M.addSystemDepartment()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
|
|
@ -42,7 +55,7 @@ function _M.addSystemDepartment()
|
||||||
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(body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -61,14 +74,14 @@ function _M.updateSystemDepartment(m)
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
resp:send(result)
|
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, body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,26 @@
|
||||||
--- Created by .
|
--- Created by .
|
||||||
--- DateTime: 2025/9/27 17:06
|
--- DateTime: 2025/9/27 17:06
|
||||||
--- 业务逻辑 对权限数据表进行数据表业务处理
|
--- 业务逻辑 对权限数据表进行数据表业务处理
|
||||||
|
local jsonschema = require("jsonschema")
|
||||||
local resp = require("util.response")
|
local resp = require("util.response")
|
||||||
local permissionDao = require("dao.permission")
|
local permissionDao = require("dao.permission")
|
||||||
local validatorJson = require("validator.system.permission")
|
|
||||||
local cjson = require("cjson.safe")
|
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
-- 定义一个JSON Schema
|
||||||
|
local schema = {
|
||||||
|
{type = "object", properties = {
|
||||||
|
{name = "username", type = "string"},
|
||||||
|
{name = "phone", type = "string"},
|
||||||
|
{name = "email", type = "string"},
|
||||||
|
{name = "idcard", type = "string"},
|
||||||
|
{name = "name", type = "string"},
|
||||||
|
{name = "office_phone", type = "string"},
|
||||||
|
{name = "telephone", type = "string"},
|
||||||
|
{name = "display_name", type = "string"},
|
||||||
|
}, required = {"username", "phone", "email", "idcard"}}
|
||||||
|
}
|
||||||
|
|
||||||
--获取所有权限信息
|
--获取所有权限信息
|
||||||
function _M.getSystemPermissions()
|
function _M.getSystemPermissions()
|
||||||
--获取页码和请求的数据量
|
--获取页码和请求的数据量
|
||||||
|
|
@ -41,7 +54,7 @@ function _M.addSystemPermission()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
|
|
@ -49,7 +62,7 @@ function _M.addSystemPermission()
|
||||||
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(body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -68,14 +81,14 @@ function _M.updateSystemPermission(m)
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
resp:send(result)
|
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, body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,22 @@
|
||||||
--- Created by .
|
--- Created by .
|
||||||
--- DateTime: 2025/9/27 15:19
|
--- DateTime: 2025/9/27 15:19
|
||||||
--- 业务逻辑 对用户角色数据表进行数据表业务处理
|
--- 业务逻辑 对用户角色数据表进行数据表业务处理
|
||||||
|
local jsonschema = require("jsonschema")
|
||||||
local resp = require("util.response")
|
local resp = require("util.response")
|
||||||
local roleDao = require("dao.role")
|
local roleDao = require("dao.role")
|
||||||
local validatorJson = require("validator.system.role")
|
|
||||||
local cjson = require("cjson.safe")
|
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
-- 定义一个JSON Schema
|
||||||
|
local schema = {
|
||||||
|
{type = "object", properties = {
|
||||||
|
{name = "role_name", type = "string"},
|
||||||
|
{name = "description", type = "string"},
|
||||||
|
{name = "create_by", type = "string"},
|
||||||
|
{name = "update_by", type = "string"},
|
||||||
|
}, required = {"role_name"}}
|
||||||
|
}
|
||||||
|
|
||||||
--获取所有角色信息
|
--获取所有角色信息
|
||||||
function _M.getSystemRoles()
|
function _M.getSystemRoles()
|
||||||
--获取页码和请求的数据量
|
--获取页码和请求的数据量
|
||||||
|
|
@ -35,7 +44,7 @@ function _M.addSystemRole()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
|
|
@ -43,7 +52,7 @@ function _M.addSystemRole()
|
||||||
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(body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -62,14 +71,14 @@ function _M.updateSystemRole(m)
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
resp:send(result)
|
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, body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,26 @@
|
||||||
--- Created by .
|
--- Created by .
|
||||||
--- DateTime: 2025/9/25 08:19
|
--- DateTime: 2025/9/25 08:19
|
||||||
--- 业务逻辑 对用户数据表进行数据表业务处理
|
--- 业务逻辑 对用户数据表进行数据表业务处理
|
||||||
|
local jsonschema = require("jsonschema")
|
||||||
local resp = require("util.response")
|
local resp = require("util.response")
|
||||||
local userDao = require("dao.user")
|
local userDao = require("dao.user")
|
||||||
local validatorJson = require("validator.system.user")
|
|
||||||
local cjson = require("cjson.safe")
|
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
-- 定义一个JSON Schema
|
||||||
|
local schema = {
|
||||||
|
{type = "object", properties = {
|
||||||
|
{name = "username", type = "string"},
|
||||||
|
{name = "phone", type = "string"},
|
||||||
|
{name = "email", type = "string"},
|
||||||
|
{name = "idcard", type = "string"},
|
||||||
|
{name = "name", type = "string"},
|
||||||
|
{name = "office_phone", type = "string"},
|
||||||
|
{name = "telephone", type = "string"},
|
||||||
|
{name = "display_name", type = "string"},
|
||||||
|
}, required = {"username", "phone", "email", "idcard"}}
|
||||||
|
}
|
||||||
|
|
||||||
--获取所有用户信息
|
--获取所有用户信息
|
||||||
function _M.getSystemUsers()
|
function _M.getSystemUsers()
|
||||||
--获取页码和请求的数据量
|
--获取页码和请求的数据量
|
||||||
|
|
@ -34,8 +47,8 @@ function _M.addSystemUser()
|
||||||
ngx.req.read_body()
|
ngx.req.read_body()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合json
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
|
|
@ -43,7 +56,7 @@ function _M.addSystemUser()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = userDao.addSystemUser(cjson.decode(body_data))
|
local code, ret = userDao.addSystemUser(body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -61,8 +74,8 @@ function _M.updateSystemUser(m)
|
||||||
ngx.req.read_body()
|
ngx.req.read_body()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合json
|
-- 验证数据是否符合schema
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local ok, err = jsonschema:generate_validator(body_data, schema)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not ok then
|
||||||
local result = resp:json(0x000001)
|
local result = resp:json(0x000001)
|
||||||
|
|
@ -70,7 +83,7 @@ function _M.updateSystemUser(m)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--将数据更新到数据表中
|
--将数据更新到数据表中
|
||||||
local code, ret = userDao.updateSystemUser(m.id, cjson.decode(body_data))
|
local code, ret = userDao.updateSystemUser(m.id, body_data)
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -32,29 +32,6 @@ local pageSize = args["pagesize"] or 10
|
||||||
ngx.say("pageNum:", pageNum, " pageSize:", pageSize)
|
ngx.say("pageNum:", pageNum, " pageSize:", pageSize)
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
|
||||||
local cjson = require "cjson"
|
|
||||||
--local sampleJson = [[{"age":"23","testArray":{"array":[8,9,11,14,25]},"Himi":"himigame.com"}]]
|
|
||||||
local sampleJson = [[{"raw_header":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9","signature":"zkKAmXifqWDrMaLpXe8hrA1JpDRbdlgwS-yxNnQUOBw","raw_payload":"eyJpYXQiOjE3NjE4OTIwNDMsImV4cCI6MTc2MTg5NTY0MywidXNlcmlkIjoiYWRtaW4iLCJyb2xlIjoiIn0","valid":true,"verified":true,"reason":"everything is awesome~ :p","header":{"alg":"HS256","typ":"JWT"},"payload":{"iat":1761892043,"userid":"admin","exp":1761895643,"role":""}}]]
|
|
||||||
--解析json字符串
|
|
||||||
local data = cjson.decode(sampleJson);
|
|
||||||
--打印json字符串中的age字段
|
|
||||||
ngx.say(data["raw_header"]);
|
|
||||||
--打印数组中的第一个值(lua默认是从0开始计数)
|
|
||||||
ngx.say(data["payload"]["userid"]);
|
|
||||||
|
|
||||||
--[[
|
|
||||||
local jwttoken = require("util.token")
|
|
||||||
--获取请求头中的令牌数据
|
|
||||||
local auth_header = ngx.var.http_Authorization
|
|
||||||
--调用令牌校验
|
|
||||||
local result = jwttoken.authorizationToken((auth_header))
|
|
||||||
-- 输出结果
|
|
||||||
ngx.say(cjson.encode(result))
|
|
||||||
ngx.exit(result.code)
|
|
||||||
--]]
|
|
||||||
|
|
||||||
--[[
|
|
||||||
local jsonschema = require("jsonschema")
|
local jsonschema = require("jsonschema")
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
-- 定义一个JSON Schema
|
||||||
|
|
@ -90,7 +67,6 @@ if not ok then
|
||||||
else
|
else
|
||||||
print("Validation succeeded!")
|
print("Validation succeeded!")
|
||||||
end
|
end
|
||||||
--]]
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
local jwt = require("resty.jwt")
|
local jwt = require("resty.jwt")
|
||||||
|
|
|
||||||
|
|
@ -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,timestamp=os.time()}
|
local response = {status=status, msg=msg, data=data}
|
||||||
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,timestamp=os.time()}
|
local response = {status=status, msg=msg, data=data}
|
||||||
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,8 +50,7 @@ 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
|
||||||
|
|
||||||
|
|
@ -59,8 +58,7 @@ 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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by frankly.
|
|
||||||
--- DateTime: 2025/10/31 09:29
|
|
||||||
---
|
|
||||||
|
|
||||||
local jwt = require("resty.jwt")
|
|
||||||
local conf = require("config")
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
--设置JWT的有效载荷
|
|
||||||
local obj = {
|
|
||||||
header = {typ="JWT", alg="HS256"},
|
|
||||||
payload = { -- 自定义数据
|
|
||||||
userid = "", -- 用户id
|
|
||||||
username = "", -- 用户名
|
|
||||||
role = "", -- 角色
|
|
||||||
--iss = "your_issuer", -- 签发者
|
|
||||||
--sub = "1234567890", -- 主题
|
|
||||||
exp = os.time() + 3600, -- 过期时间(例如:当前时间+1小时)
|
|
||||||
iat = os.time() -- 签发时间
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _M.generateToken(userid, username)
|
|
||||||
if userid == nil or username == nil then
|
|
||||||
return ""
|
|
||||||
end
|
|
||||||
|
|
||||||
obj.payload.userid = userid
|
|
||||||
obj.payload.username = username
|
|
||||||
--获取的登陆的用户信息,返回tocken
|
|
||||||
local jwt_token = jwt:sign(conf.secret_key, obj)
|
|
||||||
return jwt_token
|
|
||||||
end
|
|
||||||
|
|
||||||
--令牌校验
|
|
||||||
function _M.authorizationToken(auth_header)
|
|
||||||
--定义响应数据
|
|
||||||
local response = {}
|
|
||||||
--如果请求头中没有令牌,则直接返回401
|
|
||||||
if auth_header == nil or auth_header == "" then
|
|
||||||
response["code"] = 401
|
|
||||||
response["message"] = "没有找到令牌数据"
|
|
||||||
return response
|
|
||||||
end
|
|
||||||
--[[
|
|
||||||
--查找令牌中的Bearer前缀字符,并进行截取
|
|
||||||
local _, _, token = string.find(auth_header, "Bearer%s+(.+)")
|
|
||||||
--如果没有Bearer,则表示令牌无效
|
|
||||||
if token == nil then
|
|
||||||
response["code"] = 401
|
|
||||||
response["message"] = "令牌格式不正确"
|
|
||||||
return response
|
|
||||||
end
|
|
||||||
--]]
|
|
||||||
--校验令牌
|
|
||||||
local jwt_obj = jwt:verify(conf.secret_key, auth_header)
|
|
||||||
--如果校验结果中的verified==false,则表示令牌无效
|
|
||||||
if jwt_obj.verified == false then
|
|
||||||
response["code"] = 401
|
|
||||||
response["message"] = "令牌无效"
|
|
||||||
return response
|
|
||||||
end
|
|
||||||
--判断token是否超时
|
|
||||||
if jwt_obj.payload.exp and os.time() > jwt_obj.payload.exp then
|
|
||||||
response["code"] = 401
|
|
||||||
response["message"] = "令牌已过期"
|
|
||||||
return response
|
|
||||||
end
|
|
||||||
--全部校验完成后,说明令牌有效,返回令牌数据
|
|
||||||
response["code"] = 200
|
|
||||||
response["message"] = "令牌校验通过"
|
|
||||||
response["body"] = jwt_obj
|
|
||||||
return response
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by admin.
|
|
||||||
--- DateTime: 2025/10/30 08:09
|
|
||||||
---业务逻辑 对账户登录的参数进行数据的验证
|
|
||||||
local jsonschema = require("jsonschema")
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
|
||||||
local schema = {
|
|
||||||
{type = "object", properties = {
|
|
||||||
{name = "username", type = "string"},
|
|
||||||
{name = "password", type = "string"},
|
|
||||||
{name = "captcha", type = "string"},
|
|
||||||
{name = "checkKey", type = "string"},
|
|
||||||
}, required = {"username", "password"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
|
||||||
-- 验证数据是否符合schema
|
|
||||||
local validator = jsonschema.generate_validator(schema)
|
|
||||||
local result = validator(jsonData)
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by .
|
|
||||||
--- DateTime: 2025/10/30 08:18
|
|
||||||
--- 业务逻辑 对账户数据参数进行数据的验证
|
|
||||||
local jsonschema = require("jsonschema")
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
|
||||||
local schema = {
|
|
||||||
{type = "object", properties = {
|
|
||||||
{name = "name", type = "string"},
|
|
||||||
{name = "password", type = "string"},
|
|
||||||
{name = "real_name", type = "string"},
|
|
||||||
{name = "department", type = "string"},
|
|
||||||
{name = "office_phone", type = "string"},
|
|
||||||
{name = "telephone", type = "string"},
|
|
||||||
{name = "display_name", type = "string"},
|
|
||||||
}, required = {"name"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
|
||||||
-- 验证数据是否符合schema
|
|
||||||
local validator = jsonschema.generate_validator(schema)
|
|
||||||
local result = validator(jsonData)
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by .
|
|
||||||
--- DateTime: 2025/10/30 08:14
|
|
||||||
--- 业务逻辑 对应用数据参数进行数据的验证
|
|
||||||
local jsonschema = require("jsonschema")
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
|
||||||
local schema = {
|
|
||||||
{type = "object", properties = {
|
|
||||||
{name = "name", type = "string"},
|
|
||||||
{name = "display_name", type = "string"},
|
|
||||||
{name = "logo", type = "string"},
|
|
||||||
{name = "title", type = "string"},
|
|
||||||
{name = "name", type = "string"},
|
|
||||||
{name = "favicon", type = "string"},
|
|
||||||
{name = "description", type = "string"},
|
|
||||||
{name = "homepage_url", type = "string"},
|
|
||||||
{name = "redirect_uris", type = "string"},
|
|
||||||
}, required = {"name", "redirect_uris"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
|
||||||
-- 验证数据是否符合schema
|
|
||||||
local validator = jsonschema.generate_validator(schema)
|
|
||||||
local result = validator(jsonData)
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by .
|
|
||||||
--- DateTime: 2025/10/30 08:12
|
|
||||||
--- 业务逻辑 对组织架构数据进行参数数据的验证
|
|
||||||
local jsonschema = require("jsonschema")
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
|
||||||
local schema = {
|
|
||||||
{type = "object", properties = {
|
|
||||||
{name = "name", type = "string"},
|
|
||||||
{name = "seq", type = "string"},
|
|
||||||
{name = "description", type = "string"},
|
|
||||||
{name = "create_by", type = "string"},
|
|
||||||
{name = "update_by", type = "string"},
|
|
||||||
{name = "parent_id", type = "string"},
|
|
||||||
{name = "leader", type = "string"},
|
|
||||||
{name = "status", type = "string"},
|
|
||||||
}, required = {"name"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
|
||||||
-- 验证数据是否符合schema
|
|
||||||
local validator = jsonschema.generate_validator(schema)
|
|
||||||
local result = validator(jsonData)
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by .
|
|
||||||
--- DateTime: 2025/10/30 08:11
|
|
||||||
--- 业务逻辑 对权限参数进行数据的验证
|
|
||||||
local jsonschema = require("jsonschema")
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
|
||||||
local schema = {
|
|
||||||
{type = "object", properties = {
|
|
||||||
{name = "username", type = "string"},
|
|
||||||
{name = "phone", type = "string"},
|
|
||||||
{name = "email", type = "string"},
|
|
||||||
{name = "idcard", type = "string"},
|
|
||||||
{name = "name", type = "string"},
|
|
||||||
{name = "office_phone", type = "string"},
|
|
||||||
{name = "telephone", type = "string"},
|
|
||||||
{name = "display_name", type = "string"},
|
|
||||||
}, required = {"username", "phone", "email", "idcard"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
|
||||||
-- 验证数据是否符合schema
|
|
||||||
local validator = jsonschema.generate_validator(schema)
|
|
||||||
local result = validator(jsonData)
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by .
|
|
||||||
--- DateTime: 2025/10/30 08:13
|
|
||||||
--- 业务逻辑 对用户角色参数进行数据的验证
|
|
||||||
local jsonschema = require("jsonschema")
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
|
||||||
local schema = {
|
|
||||||
{type = "object", properties = {
|
|
||||||
{name = "role_name", type = "string"},
|
|
||||||
{name = "description", type = "string"},
|
|
||||||
{name = "create_by", type = "string"},
|
|
||||||
{name = "update_by", type = "string"},
|
|
||||||
}, required = {"role_name"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
|
||||||
-- 验证数据是否符合schema
|
|
||||||
local validator = jsonschema.generate_validator(schema)
|
|
||||||
local result = validator(jsonData)
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by .
|
|
||||||
--- DateTime: 2025/10/30 08:19
|
|
||||||
--- 业务逻辑 对用户参数进行数据的验证
|
|
||||||
local jsonschema = require("jsonschema")
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
|
||||||
local schema = {
|
|
||||||
{type = "object", properties = {
|
|
||||||
{name = "username", type = "string"},
|
|
||||||
{name = "phone", type = "string"},
|
|
||||||
{name = "email", type = "string"},
|
|
||||||
{name = "idcard", type = "string"},
|
|
||||||
{name = "name", type = "string"},
|
|
||||||
{name = "office_phone", type = "string"},
|
|
||||||
{name = "telephone", type = "string"},
|
|
||||||
{name = "display_name", type = "string"},
|
|
||||||
}, required = {"username", "phone", "email", "idcard"}}
|
|
||||||
}
|
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
|
||||||
-- 验证数据是否符合schema
|
|
||||||
local validator = jsonschema.generate_validator(schema)
|
|
||||||
local result = validator(jsonData)
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
Loading…
Reference in New Issue
Block a user