用户登录业务逻辑,接收前端用户名从数据表中获取数据,然后取出密码进行md5加密,再与前端传的密码进行比对,相等则进入系统
This commit is contained in:
parent
ece64e90f3
commit
0508599f34
|
|
@ -9,17 +9,22 @@ local _M = {}
|
||||||
|
|
||||||
--认证用户返回用户数据信息
|
--认证用户返回用户数据信息
|
||||||
local function authenticate(name, passwd)
|
local function authenticate(name, passwd)
|
||||||
--验证用户名是否为空
|
--验证用户名或者密码是否为空
|
||||||
if name == "" then
|
if name == "" or passwd == "" then
|
||||||
return 0x010003, nil
|
return 0x010003, nil
|
||||||
end
|
end
|
||||||
--验证密码是否为空
|
|
||||||
if passwd == "" then
|
|
||||||
return 0x010002, nil
|
|
||||||
end
|
|
||||||
return userDao:adjustUser(name, passwd)
|
return userDao:adjustUser(name, passwd)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--根据用户名称获取用户信息
|
||||||
|
local function getUserByUsername(username)
|
||||||
|
--验证用户名否为空
|
||||||
|
if username == "" then
|
||||||
|
return 0x010003, nil
|
||||||
|
end
|
||||||
|
return userDao:getUserByUsername(username)
|
||||||
|
end
|
||||||
|
|
||||||
--用户登录业务逻辑处理
|
--用户登录业务逻辑处理
|
||||||
function _M.login(jsonData)
|
function _M.login(jsonData)
|
||||||
--解析json中的键和数据值
|
--解析json中的键和数据值
|
||||||
|
|
@ -28,7 +33,7 @@ function _M.login(jsonData)
|
||||||
local captcha = jsonData["captcha"]
|
local captcha = jsonData["captcha"]
|
||||||
local checkKey = jsonData["checkKey"]
|
local checkKey = jsonData["checkKey"]
|
||||||
--验证用户名是否为空
|
--验证用户名是否为空
|
||||||
local code, res = authenticate(name, passwd)
|
local code, res = userDao:getUserByUsername(name) --authenticate(name, passwd)
|
||||||
if code ~= 0 then
|
if code ~= 0 then
|
||||||
return 0x000001,res
|
return 0x000001,res
|
||||||
end
|
end
|
||||||
|
|
@ -36,10 +41,15 @@ function _M.login(jsonData)
|
||||||
if res ~= nil then
|
if res ~= nil then
|
||||||
num = table.getn(res)
|
num = table.getn(res)
|
||||||
end
|
end
|
||||||
--用户存在时返回用户已经存在
|
--用户不存在时返回
|
||||||
if num <= 0 then
|
if num <= 0 then
|
||||||
return 0x01000C,nil
|
return 0x01000C,nil
|
||||||
end
|
end
|
||||||
|
--进行密码验证 获取数据库的密码
|
||||||
|
local pwdMd5 = ngx.md5(res[1].password)
|
||||||
|
if pwdMd5 ~= passwd then
|
||||||
|
return 0x000001,res --密码错误
|
||||||
|
end
|
||||||
local userid = res[1].id
|
local userid = res[1].id
|
||||||
--获取用户id查询角色信息
|
--获取用户id查询角色信息
|
||||||
local err, rest = userDao:userRole(userid)
|
local err, rest = userDao:userRole(userid)
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,15 @@ local function isExistUser(id)
|
||||||
return true
|
return true
|
||||||
end
|
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)
|
function _M.getSystemUsers(pageNum, pageSize)
|
||||||
return userModel:paginate(pageNum, pageSize)
|
return userModel:paginate(pageNum, pageSize)
|
||||||
|
|
@ -58,7 +67,7 @@ function _M.addSystemUser(jsonData)
|
||||||
local email = jsonData['email']
|
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
|
if code ~= 0 then
|
||||||
return 0x000001,res
|
return 0x000001,res
|
||||||
end
|
end
|
||||||
|
|
@ -73,9 +82,9 @@ function _M.addSystemUser(jsonData)
|
||||||
|
|
||||||
--键值为id产生uuid数据值,增加到json中
|
--键值为id产生uuid数据值,增加到json中
|
||||||
jsonData.id = helpers.getUuid()
|
jsonData.id = helpers.getUuid()
|
||||||
--用户密码暂时使用md5进行加密
|
--用户密码暂时使用md5进行加密 使用明文暂时注释掉加密
|
||||||
local pwd = jsonData['password']
|
--local pwd = jsonData['password']
|
||||||
jsonData.password = ngx.md5(pwd)
|
--jsonData.password = ngx.md5(pwd)
|
||||||
-- 创建一个用户
|
-- 创建一个用户
|
||||||
return userModel:create(jsonData)
|
return userModel:create(jsonData)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user