2025-11-10 19:34:43 +08:00
|
|
|
---
|
|
|
|
|
--- 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 = {
|
2025-11-11 19:00:22 +08:00
|
|
|
{name = "responseType", type = "string", default = "code"},
|
|
|
|
|
{name = "clientId", type = "string", minLength = 10},
|
|
|
|
|
{name = "redirectUri", type = "string", minLength = 8},
|
|
|
|
|
{name = "state", type = "string"},
|
|
|
|
|
{name = "scope", type = "string"},
|
|
|
|
|
}, required = {"responseType", "clientId", "redirectUri"}}
|
2025-11-10 19:34:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
--获取授权码
|
|
|
|
|
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
|
|
|
|
|
|
2025-11-11 21:35:21 +08:00
|
|
|
local schemaLogin = {
|
2025-11-12 09:36:00 +08:00
|
|
|
type = "object",
|
|
|
|
|
properties = {
|
|
|
|
|
username = { type = "string" },
|
|
|
|
|
password = { type = "string" },
|
|
|
|
|
},
|
|
|
|
|
required = {"username", "password"}
|
2025-11-11 21:35:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
--回收Access-Token
|
|
|
|
|
function _M:validatorLogin(jsonData)
|
|
|
|
|
-- 验证数据是否符合schema
|
|
|
|
|
local validator = jsonschema.generate_validator(schemaLogin)
|
|
|
|
|
local result = validator(jsonData)
|
|
|
|
|
return result
|
|
|
|
|
end
|
|
|
|
|
|
2025-11-10 19:34:43 +08:00
|
|
|
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
|