From 0508599f34945627e2fd475a4b7d4acd118ab940 Mon Sep 17 00:00:00 2001 From: wanglei <34475144@qq.com> Date: Wed, 12 Nov 2025 15:27:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E9=80=BB=E8=BE=91=EF=BC=8C=E6=8E=A5=E6=94=B6=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E7=94=A8=E6=88=B7=E5=90=8D=E4=BB=8E=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=A1=A8=E4=B8=AD=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE=EF=BC=8C?= =?UTF-8?q?=E7=84=B6=E5=90=8E=E5=8F=96=E5=87=BA=E5=AF=86=E7=A0=81=E8=BF=9B?= =?UTF-8?q?=E8=A1=8Cmd5=E5=8A=A0=E5=AF=86=EF=BC=8C=E5=86=8D=E4=B8=8E?= =?UTF-8?q?=E5=89=8D=E7=AB=AF=E4=BC=A0=E7=9A=84=E5=AF=86=E7=A0=81=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E6=AF=94=E5=AF=B9=EF=BC=8C=E7=9B=B8=E7=AD=89=E5=88=99?= =?UTF-8?q?=E8=BF=9B=E5=85=A5=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/dao/system/login.lua | 26 ++++++++++++++++++-------- src/dao/system/user.lua | 17 +++++++++++++---- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/dao/system/login.lua b/src/dao/system/login.lua index 6c63b13..885f1e8 100644 --- a/src/dao/system/login.lua +++ b/src/dao/system/login.lua @@ -9,17 +9,22 @@ local _M = {} --认证用户返回用户数据信息 local function authenticate(name, passwd) - --验证用户名是否为空 - if name == "" then + --验证用户名或者密码是否为空 + if name == "" or passwd == "" then return 0x010003, nil end - --验证密码是否为空 - if passwd == "" then - return 0x010002, 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中的键和数据值 @@ -28,7 +33,7 @@ function _M.login(jsonData) local captcha = jsonData["captcha"] local checkKey = jsonData["checkKey"] --验证用户名是否为空 - local code, res = authenticate(name, passwd) + local code, res = userDao:getUserByUsername(name) --authenticate(name, passwd) if code ~= 0 then return 0x000001,res end @@ -36,10 +41,15 @@ function _M.login(jsonData) 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) diff --git a/src/dao/system/user.lua b/src/dao/system/user.lua index 7977ec6..b6feb28 100644 --- a/src/dao/system/user.lua +++ b/src/dao/system/user.lua @@ -37,6 +37,15 @@ local function isExistUser(id) return true end +--通过用户名验证用户是否存在 +function _M:getUserByUsername(username) + local code, res = userModel:where("username", "=", username):orwhere("phone", "=", username):orwhere("email", "=", username):get() + if code ~= 0 then + return 0x000001,res + end + return code, res +end + -- 查询数据表中的所有用户信息 function _M.getSystemUsers(pageNum, pageSize) return userModel:paginate(pageNum, pageSize) @@ -58,7 +67,7 @@ function _M.addSystemUser(jsonData) local email = jsonData['email'] --根据用户、手机号、邮箱进行验证用户是否存在 - local code, res = userModel:where("username", "=", userName):orwhere("phone", "=", phone):orwhere("email", "=", email):get() + local code, res = self.getUserByUsername(userName) if code ~= 0 then return 0x000001,res end @@ -73,9 +82,9 @@ function _M.addSystemUser(jsonData) --键值为id产生uuid数据值,增加到json中 jsonData.id = helpers.getUuid() - --用户密码暂时使用md5进行加密 - local pwd = jsonData['password'] - jsonData.password = ngx.md5(pwd) + --用户密码暂时使用md5进行加密 使用明文暂时注释掉加密 + --local pwd = jsonData['password'] + --jsonData.password = ngx.md5(pwd) -- 创建一个用户 return userModel:create(jsonData) end