修改用户登录并进行验证返回用户信息和token数据,修改jsonschema验证方法使用错误问题
This commit is contained in:
parent
899496bd0d
commit
4f4ab0d2bb
|
|
@ -29,9 +29,9 @@ http {
|
||||||
log_not_found off;
|
log_not_found off;
|
||||||
access_log off;
|
access_log off;
|
||||||
}
|
}
|
||||||
|
#登录认证配置
|
||||||
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';
|
||||||
|
|
@ -39,13 +39,17 @@ 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 '/home/frankly/work/AuthPlatform/src/test/testPostgres.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testPostgres.lua';
|
||||||
}
|
}
|
||||||
|
|
||||||
location /cjson {
|
location /cjson {
|
||||||
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/test.lua';
|
content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/test.lua';
|
||||||
}
|
}
|
||||||
|
#jwt验证进行测试
|
||||||
|
location /api/test {
|
||||||
|
access_by_lua_file /usr/local/openresty/lualib/resty/jwt-auth.lua;
|
||||||
|
proxy_pass http://192.168.147.1:3000;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,7 +3,10 @@
|
||||||
--- 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 = {}
|
||||||
|
|
||||||
|
|
@ -18,17 +21,17 @@ local function authenticate(name, passwd)
|
||||||
return 0x010002, nil
|
return 0x010002, nil
|
||||||
end
|
end
|
||||||
--根据用户进行验证用户是否存在
|
--根据用户进行验证用户是否存在
|
||||||
local code, res = userDao:where("name", "=", name):where("password", "=", passwd):get()
|
local code, res = userModel:where("username", "=", 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 = userDao:where("phone", "=", name):where("password", "=", passwd):get()
|
code, res = userModel: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 = userDao:where("email", "=", name):where("password", "=", passwd):get()
|
code, res = userModel: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
|
||||||
|
|
@ -39,7 +42,7 @@ end
|
||||||
--用户登录业务逻辑处理
|
--用户登录业务逻辑处理
|
||||||
function _M.login(jsonData)
|
function _M.login(jsonData)
|
||||||
--解析json中的键和数据值
|
--解析json中的键和数据值
|
||||||
local name = jsonData["name"]
|
local name = jsonData["username"]
|
||||||
local passwd = jsonData["password"]
|
local passwd = jsonData["password"]
|
||||||
local captcha = jsonData["captcha"]
|
local captcha = jsonData["captcha"]
|
||||||
local checkKey = jsonData["checkKey"]
|
local checkKey = jsonData["checkKey"]
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@ local resp = require("util.response")
|
||||||
local authDao = require("dao.auth")
|
local authDao = require("dao.auth")
|
||||||
local jwt = require("resty.jwt")
|
local jwt = require("resty.jwt")
|
||||||
local conf = require("config")
|
local conf = require("config")
|
||||||
local validatorJson = require("validator.system.auth")
|
local validatorJson = require("validator.auth.auth")
|
||||||
|
local cjson = require("cjson.safe")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -15,8 +16,9 @@ local _M = {}
|
||||||
local obj = {
|
local obj = {
|
||||||
header = {typ="JWT", alg="HS256"},
|
header = {typ="JWT", alg="HS256"},
|
||||||
payload = { -- 自定义数据
|
payload = { -- 自定义数据
|
||||||
username = "",
|
userid = "", -- 用户id
|
||||||
role = "",
|
username = "", -- 用户名
|
||||||
|
role = "", -- 角色
|
||||||
--iss = "your_issuer", -- 签发者
|
--iss = "your_issuer", -- 签发者
|
||||||
--sub = "1234567890", -- 主题
|
--sub = "1234567890", -- 主题
|
||||||
exp = os.time() + 3600, -- 过期时间(例如:当前时间+1小时)
|
exp = os.time() + 3600, -- 过期时间(例如:当前时间+1小时)
|
||||||
|
|
@ -31,15 +33,15 @@ function _M.login()
|
||||||
--获取请求数据
|
--获取请求数据
|
||||||
local body_data = ngx.req.get_body_data()
|
local body_data = ngx.req.get_body_data()
|
||||||
-- 验证数据是否符合json
|
-- 验证数据是否符合json
|
||||||
local ok = validatorJson.validatorJson(body_data)
|
local retJson = validatorJson.validatorJson(body_data)
|
||||||
--验证失败则返回
|
--验证失败则返回
|
||||||
if not ok then
|
if not retJson 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(body_data)
|
local code, ret = authDao.login(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)
|
||||||
|
|
@ -47,11 +49,15 @@ function _M.login()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--获取的登陆的用户信息,返回tocken
|
--获取的登陆的用户信息,返回tocken
|
||||||
obj.payload.username = body_data["name"]
|
obj.payload.userid = ret["id"]
|
||||||
|
obj.payload.username = ret["name"]
|
||||||
obj.payload.role = ""
|
obj.payload.role = ""
|
||||||
local jwt_token = jwt:sign(conf.secret_key, obj)
|
local jwt_token = jwt:sign(conf.secret_key, obj)
|
||||||
ngx.say(jwt_token)
|
--ngx.say(jwt_token)
|
||||||
local result = resp:json(code, ret)
|
local data = {}
|
||||||
|
data["token"] = jwt_token
|
||||||
|
data["userInfo"] = ret
|
||||||
|
local result = resp:json(code, data)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -70,7 +76,7 @@ function _M.logout()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = authDao.logout(body_data)
|
local code, ret = authDao.logout(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
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 validatorJson = require("validator.system.account")
|
||||||
|
local cjson = require("cjson.safe")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -41,7 +42,7 @@ function _M.addSystemAccount()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = accountDao.addSystemAccount(body_data)
|
local code, ret = accountDao.addSystemAccount(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -67,7 +68,7 @@ function _M.updateSystemAccount(m)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = accountDao.updateSystemAccount(m.id, body_data)
|
local code, ret = accountDao.updateSystemAccount(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
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 validatorJson = require("validator.system.application")
|
||||||
|
local cjson = require("cjson.safe")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -55,7 +56,7 @@ function _M.addSystemApplication()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = applicationDao.addApplication(body_data)
|
local code, ret = applicationDao.addApplication(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -81,7 +82,7 @@ function _M.updateSystemApplication(m)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = applicationDao.updateSystemApplication(m.id, body_data)
|
local code, ret = applicationDao.updateSystemApplication(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
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 validatorJson = require("validator.system.department")
|
||||||
|
local cjson = require("cjson.safe")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -41,7 +42,7 @@ function _M.addSystemDepartment()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = departmentDao.addSystemDepartment(body_data)
|
local code, ret = departmentDao.addSystemDepartment(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -67,7 +68,7 @@ function _M.updateSystemDepartment(m)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = departmentDao.updateSystemDepartment(m.id, body_data)
|
local code, ret = departmentDao.updateSystemDepartment(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
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 validatorJson = require("validator.system.permission")
|
||||||
|
local cjson = require("cjson.safe")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -48,7 +49,7 @@ function _M.addSystemPermission()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = permissionDao.addPermission(body_data)
|
local code, ret = permissionDao.addPermission(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -74,7 +75,7 @@ function _M.updateSystemPermission(m)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = permissionDao.updatePermission(m.id, body_data)
|
local code, ret = permissionDao.updatePermission(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
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 validatorJson = require("validator.system.role")
|
||||||
|
local cjson = require("cjson.safe")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -42,7 +43,7 @@ function _M.addSystemRole()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = roleDao.addSystemRole(body_data)
|
local code, ret = roleDao.addSystemRole(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -68,7 +69,7 @@ function _M.updateSystemRole(m)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local code, ret = roleDao.updateSystemRole(m.id, body_data)
|
local code, ret = roleDao.updateSystemRole(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
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 validatorJson = require("validator.system.user")
|
||||||
|
local cjson = require("cjson.safe")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -42,7 +43,7 @@ function _M.addSystemUser()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--ngx.say(body_data)
|
--ngx.say(body_data)
|
||||||
local code, ret = userDao.addSystemUser(body_data)
|
local code, ret = userDao.addSystemUser(cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
@ -69,7 +70,7 @@ function _M.updateSystemUser(m)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
--将数据更新到数据表中
|
--将数据更新到数据表中
|
||||||
local code, ret = userDao.updateSystemUser(m.id, body_data)
|
local code, ret = userDao.updateSystemUser(m.id, cjson.decode(body_data))
|
||||||
local result = resp:json(code, ret)
|
local result = resp:json(code, ret)
|
||||||
resp:send(result)
|
resp:send(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,17 @@ local pageSize = args["pagesize"] or 10
|
||||||
ngx.say("pageNum:", pageNum, " pageSize:", pageSize)
|
ngx.say("pageNum:", pageNum, " pageSize:", pageSize)
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
|
||||||
|
local jwttoken = require("validator.auth.auth")
|
||||||
|
--获取请求头中的令牌数据
|
||||||
|
local auth_header = ngx.var.http_Authorization
|
||||||
|
--调用令牌校验
|
||||||
|
local result = jwttoken.check(auth_header)
|
||||||
|
-- 输出结果
|
||||||
|
ngx.say(cjson.encode(result))
|
||||||
|
ngx.exit(result.code)
|
||||||
|
|
||||||
|
--[[
|
||||||
local jsonschema = require("jsonschema")
|
local jsonschema = require("jsonschema")
|
||||||
|
|
||||||
-- 定义一个JSON Schema
|
-- 定义一个JSON Schema
|
||||||
|
|
@ -67,6 +78,7 @@ if not ok then
|
||||||
else
|
else
|
||||||
print("Validation succeeded!")
|
print("Validation succeeded!")
|
||||||
end
|
end
|
||||||
|
--]]
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
local jwt = require("resty.jwt")
|
local jwt = require("resty.jwt")
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
--- DateTime: 2025/10/30 08:09
|
--- DateTime: 2025/10/30 08:09
|
||||||
---业务逻辑 对账户登录的参数进行数据的验证
|
---业务逻辑 对账户登录的参数进行数据的验证
|
||||||
local jsonschema = require("jsonschema")
|
local jsonschema = require("jsonschema")
|
||||||
|
local jwt = require("resty.jwt")
|
||||||
|
local conf = require("config")
|
||||||
|
|
||||||
local _M = {}
|
local _M = {}
|
||||||
|
|
||||||
|
|
@ -19,8 +21,42 @@ local schema = {
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
function _M.validatorJson(jsonData)
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok, err = jsonschema:generate_validator(jsonData, schema)
|
local validator = jsonschema.generate_validator(schema)
|
||||||
return ok
|
local result = validator(jsonData)
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
--令牌校验
|
||||||
|
function _M.check(auth_header)
|
||||||
|
--定义响应数据
|
||||||
|
local response = {}
|
||||||
|
--如果请求头中没有令牌,则直接返回401
|
||||||
|
if auth_header == nil 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, token)
|
||||||
|
--如果校验结果中的verified==false,则表示令牌无效
|
||||||
|
if jwt_obj.verified == false then
|
||||||
|
response["code"] = 401
|
||||||
|
response["message"] = "令牌无效"
|
||||||
|
return response
|
||||||
|
end
|
||||||
|
--全部校验完成后,说明令牌有效,返回令牌数据
|
||||||
|
response["code"] = 200
|
||||||
|
response["message"] = "令牌校验通过"
|
||||||
|
response["body"] = jwt_obj
|
||||||
|
return response
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
@ -22,8 +22,9 @@ local schema = {
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
function _M.validatorJson(jsonData)
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok, err = jsonschema:generate_validator(jsonData, schema)
|
local validator = jsonschema.generate_validator(schema)
|
||||||
return ok
|
local result = validator(jsonData)
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,9 @@ local schema = {
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
function _M.validatorJson(jsonData)
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok, err = jsonschema:generate_validator(jsonData, schema)
|
local validator = jsonschema.generate_validator(schema)
|
||||||
return ok
|
local result = validator(jsonData)
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,9 @@ local schema = {
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
function _M.validatorJson(jsonData)
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok, err = jsonschema:generate_validator(jsonData, schema)
|
local validator = jsonschema.generate_validator(schema)
|
||||||
return ok
|
local result = validator(jsonData)
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,9 @@ local schema = {
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
function _M.validatorJson(jsonData)
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok, err = jsonschema:generate_validator(jsonData, schema)
|
local validator = jsonschema.generate_validator(schema)
|
||||||
return ok
|
local result = validator(jsonData)
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,9 @@ local schema = {
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
function _M.validatorJson(jsonData)
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok, err = jsonschema:generate_validator(jsonData, schema)
|
local validator = jsonschema.generate_validator(schema)
|
||||||
return ok
|
local result = validator(jsonData)
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,9 @@ local schema = {
|
||||||
|
|
||||||
function _M.validatorJson(jsonData)
|
function _M.validatorJson(jsonData)
|
||||||
-- 验证数据是否符合schema
|
-- 验证数据是否符合schema
|
||||||
local ok, err = jsonschema:generate_validator(jsonData, schema)
|
local validator = jsonschema.generate_validator(schema)
|
||||||
return ok
|
local result = validator(jsonData)
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user