AuthPlatform/src/dao/system/login.lua

80 lines
2.0 KiB
Lua

---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by frankly.
--- DateTime: 2025/10/29 23:36
---
local userDao = require("dao.system.user")
local _M = {}
--认证用户返回用户数据信息
local function authenticate(name, passwd)
--验证用户名或者密码是否为空
if name == "" or passwd == "" then
return 0x010003, nil
end
return userDao:adjustUser(name, passwd)
end
--根据用户名称获取用户信息
local function getUserByUsername(username)
--验证用户名否为空
if username == "" then
return 0x010003, nil
end
return userDao:getUserByUsername(username)
end
--用户登录业务逻辑处理
function _M.login(jsonData)
--解析json中的键和数据值
local name = jsonData["username"]
local passwd = jsonData["password"]
local captcha = jsonData["captcha"]
local checkKey = jsonData["checkKey"]
--验证用户名是否为空
local code, res = userDao:getUserByUsername(name) --authenticate(name, passwd)
if code ~= 0 then
return 0x000001,res
end
local num = 0
if res ~= nil then
num = table.getn(res)
end
--用户不存在时返回
if num <= 0 then
return 0x01000C,nil
end
--进行密码验证 获取数据库的密码
local pwdMd5 = ngx.md5(res[1].password)
if pwdMd5 ~= passwd then
return 0x000001,res --密码错误
end
local userid = res[1].id
--获取用户id查询角色信息
local err, rest = userDao:userRole(userid)
if rest == nil then
return 0x01000C,nil
end
res[1].role_id = rest[1].role_id
res[1].role_name = rest[1].role_name
return 0, res
end
--用户登出业务逻辑处理
function _M.logout(jsonData)
local code = 0
local ret = "{}"
return code, ret
end
--用户注册业务逻辑处理
function _M.signup(jsonData)
return userDao:addSystemUser(jsonData)
end
function _M.getUser(userid)
return userDao:getSystemUser(userid)
end
return _M