137 lines
3.7 KiB
Lua
137 lines
3.7 KiB
Lua
---
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
--- Created by admin.
|
|
--- DateTime: 2025/10/28 11:09
|
|
---
|
|
local helpers = require("share.helpers")
|
|
local resp = require("util.response")
|
|
local user = require("model.user")
|
|
|
|
local _M = {}
|
|
|
|
local dao = require("service.system.auth")
|
|
|
|
--用户登录业务逻辑处理
|
|
function _M.login()
|
|
--获取请求头并进行校验
|
|
if validator.checkReqHeader() == false then
|
|
local result = resp:json(0x000001)
|
|
resp:send(result)
|
|
return
|
|
end
|
|
--读取请求体的数据
|
|
ngx.req.read_body()
|
|
--获取请求数据
|
|
local body_data = ngx.req.get_body_data()
|
|
--判断请求体数据是否为空
|
|
if body_data == nil then
|
|
local result = resp:json(0x000001)
|
|
resp:send(result)
|
|
return
|
|
end
|
|
--ngx.say(body_data)
|
|
local code, ret = dao.login(body_data)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
--用户登出业务逻辑处理
|
|
function _M.logout()
|
|
--获取请求头并进行校验
|
|
if validator.checkReqHeader() == false then
|
|
local result = resp:json(0x000001)
|
|
resp:send(result)
|
|
return
|
|
end
|
|
--读取请求体的数据
|
|
ngx.req.read_body()
|
|
--获取请求数据
|
|
local body_data = ngx.req.get_body_data()
|
|
--判断请求体数据是否为空
|
|
if body_data == nil then
|
|
local result = resp:json(0x000001)
|
|
resp:send(result)
|
|
return
|
|
end
|
|
--ngx.say(body_data)
|
|
local code, ret = dao.logout(body_data)
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
--认证用户返回用户数据信息
|
|
local function authenticate(name, passwd)
|
|
--验证用户名是否为空
|
|
if name == "" then
|
|
return 0x010003, nil
|
|
end
|
|
--验证密码是否为空
|
|
if passwd == "" then
|
|
return 0x010002, nil
|
|
end
|
|
--根据用户进行验证用户是否存在
|
|
local code, res = user:where("name", "=", name):where("password", "=", passwd):get()
|
|
if code == 0 and res ~= nil then
|
|
return code, res
|
|
end
|
|
--根据手机号进行验证用户是否存在
|
|
code, res = user:where("phone", "=", name):where("password", "=", passwd):get()
|
|
if code == 0 and res ~= nil then
|
|
return code, res
|
|
end
|
|
--根据邮箱进行验证用户是否存在
|
|
code, res = user:where("email", "=", name):where("password", "=", passwd):get()
|
|
if code == 0 and res ~= nil then
|
|
return code, res
|
|
end
|
|
--查询不到用户信息
|
|
return 0x010003, nil
|
|
end
|
|
|
|
--用户登录业务逻辑处理
|
|
function _M.login(jsonData)
|
|
--验证数据的正确性,错误时返回
|
|
local success, result = validator.checkJson(jsonData)
|
|
if success == false then
|
|
return 0x000001,result
|
|
end
|
|
--解析json中的键和数据值
|
|
local name = ""
|
|
local passwd = ""
|
|
local captcha = ""
|
|
local checkKey = ""
|
|
for key, value in pairs(result) do
|
|
if key == "username" then name = value end
|
|
if key == "password" then passwd = value end
|
|
if key == "captcha" then captcha = value end
|
|
if key == "checkKey" then checkKey = value end
|
|
end
|
|
--验证用户名是否为空
|
|
local code, res = authenticate(name, passwd)
|
|
if code ~= 0 then
|
|
return 0x000001,res
|
|
end
|
|
local num = 0
|
|
for _, row in ipairs(res) do
|
|
for key, value in pairs(row) do
|
|
num = num + 1
|
|
end
|
|
end
|
|
--用户存在时返回用户已经存在
|
|
if num <= 0 then
|
|
return 0x01000C,nil
|
|
end
|
|
--对用户进行认证返回相关的数据
|
|
local result = resp:json(code, res)
|
|
resp:send(result)
|
|
end
|
|
|
|
--用户登出业务逻辑处理
|
|
function _M.logout(jsonData)
|
|
local code = 0
|
|
local ret = "{}"
|
|
local result = resp:json(code, ret)
|
|
resp:send(result)
|
|
end
|
|
|
|
return _M |