113 lines
3.4 KiB
Lua
113 lines
3.4 KiB
Lua
|
|
---
|
||
|
|
--- 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 schemaAuth = {
|
||
|
|
{type = "object", properties = {
|
||
|
|
{name = "username", type = "string"},
|
||
|
|
{name = "password", type = "string"},
|
||
|
|
{name = "captcha", type = "string"},
|
||
|
|
{name = "checkKey", type = "string"},
|
||
|
|
}, required = {"username", "password"}}
|
||
|
|
}
|
||
|
|
|
||
|
|
--获取授权码
|
||
|
|
function _M:validatorAuthorize(jsonData)
|
||
|
|
-- 验证数据是否符合schema
|
||
|
|
local validator = jsonschema.generate_validator(schemaAuth)
|
||
|
|
local result = validator(jsonData)
|
||
|
|
return result
|
||
|
|
end
|
||
|
|
|
||
|
|
local schemaToken = {
|
||
|
|
{type = "object", properties = {
|
||
|
|
{name = "username", type = "string"},
|
||
|
|
{name = "password", type = "string"},
|
||
|
|
{name = "captcha", type = "string"},
|
||
|
|
{name = "checkKey", type = "string"},
|
||
|
|
}, required = {"username", "password"}}
|
||
|
|
}
|
||
|
|
|
||
|
|
--根据授权码获取Access-Token
|
||
|
|
function _M:validatorToken(jsonData)
|
||
|
|
-- 验证数据是否符合schema
|
||
|
|
local validator = jsonschema.generate_validator(schemaToken)
|
||
|
|
local result = validator(jsonData)
|
||
|
|
return result
|
||
|
|
end
|
||
|
|
|
||
|
|
local schemaUserInfo = {
|
||
|
|
{type = "object", properties = {
|
||
|
|
{name = "username", type = "string"},
|
||
|
|
{name = "password", type = "string"},
|
||
|
|
{name = "captcha", type = "string"},
|
||
|
|
{name = "checkKey", type = "string"},
|
||
|
|
}, required = {"username", "password"}}
|
||
|
|
}
|
||
|
|
|
||
|
|
--根据Access-Token获取相应用户的账户信息
|
||
|
|
function _M:validatorUserinfo(jsonData)
|
||
|
|
-- 验证数据是否符合schema
|
||
|
|
local validator = jsonschema.generate_validator(schemaUserInfo)
|
||
|
|
local result = validator(jsonData)
|
||
|
|
return result
|
||
|
|
end
|
||
|
|
|
||
|
|
local schemaLogout = {
|
||
|
|
{type = "object", properties = {
|
||
|
|
{name = "username", type = "string"},
|
||
|
|
{name = "password", type = "string"},
|
||
|
|
{name = "captcha", type = "string"},
|
||
|
|
{name = "checkKey", type = "string"},
|
||
|
|
}, required = {"username", "password"}}
|
||
|
|
}
|
||
|
|
|
||
|
|
--回收Access-Token
|
||
|
|
function _M:validatorLogout(jsonData)
|
||
|
|
-- 验证数据是否符合schema
|
||
|
|
local validator = jsonschema.generate_validator(schemaLogout)
|
||
|
|
local result = validator(jsonData)
|
||
|
|
return result
|
||
|
|
end
|
||
|
|
|
||
|
|
local schemaRefresh = {
|
||
|
|
{type = "object", properties = {
|
||
|
|
{name = "username", type = "string"},
|
||
|
|
{name = "password", type = "string"},
|
||
|
|
{name = "captcha", type = "string"},
|
||
|
|
{name = "checkKey", type = "string"},
|
||
|
|
}, required = {"username", "password"}}
|
||
|
|
}
|
||
|
|
|
||
|
|
--根据Refresh-Token刷新Access-Token
|
||
|
|
function _M:validatorRefresh(jsonData)
|
||
|
|
-- 验证数据是否符合schema
|
||
|
|
local validator = jsonschema.generate_validator(schemaRefresh)
|
||
|
|
local result = validator(jsonData)
|
||
|
|
return result
|
||
|
|
end
|
||
|
|
|
||
|
|
local schemaChecklogin = {
|
||
|
|
{type = "object", properties = {
|
||
|
|
{name = "username", type = "string"},
|
||
|
|
{name = "password", type = "string"},
|
||
|
|
{name = "captcha", type = "string"},
|
||
|
|
{name = "checkKey", type = "string"},
|
||
|
|
}, required = {"username", "password"}}
|
||
|
|
}
|
||
|
|
|
||
|
|
--验证token是否有效
|
||
|
|
function _M:validatorChecklogin(jsonData)
|
||
|
|
-- 验证数据是否符合schema
|
||
|
|
local validator = jsonschema.generate_validator(schemaChecklogin)
|
||
|
|
local result = validator(jsonData)
|
||
|
|
return result
|
||
|
|
end
|
||
|
|
|
||
|
|
return _M
|