增加用户登录接口业务逻辑处理,根据用户名、手机号、邮箱和密码进行验证用户是否存在并返回用户信息数据;修改增加数据到数据表时验证错误问题
This commit is contained in:
parent
b0f3421082
commit
4b9c6ee202
|
|
@ -3,15 +3,17 @@
|
||||||
--- Created by admin.
|
--- Created by admin.
|
||||||
--- DateTime: 2025/9/24 15:29
|
--- DateTime: 2025/9/24 15:29
|
||||||
---
|
---
|
||||||
|
--解析url路由过滤库
|
||||||
local radix = require("resty.radixtree")
|
local radix = require("resty.radixtree")
|
||||||
|
--数据表业务处理
|
||||||
local userApi = require("api.system.user")
|
local userApi = require("api.system.user")
|
||||||
local accountApi = require("api.system.account")
|
local accountApi = require("api.system.account")
|
||||||
local roleApi = require("api.system.role")
|
local roleApi = require("api.system.role")
|
||||||
local permissionApi = require("api.system.permission")
|
local permissionApi = require("api.system.permission")
|
||||||
local applicationApi = require("api.system.application")
|
local applicationApi = require("api.system.application")
|
||||||
local organizationApi = require("api.system.organization")
|
local organizationApi = require("api.system.organization")
|
||||||
|
--业务接口控制
|
||||||
local controllerApi = require("api.controller")
|
local controllerApi = require("api.system.controller")
|
||||||
|
|
||||||
--定义相关路由,前端接口url地址
|
--定义相关路由,前端接口url地址
|
||||||
local routes = {
|
local routes = {
|
||||||
|
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
---
|
|
||||||
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
||||||
--- Created by admin.
|
|
||||||
--- DateTime: 2025/10/28 11:09
|
|
||||||
---
|
|
||||||
local validator = require("util.validator")
|
|
||||||
local helpers = require("util.helpers")
|
|
||||||
local resp = require("util.response")
|
|
||||||
|
|
||||||
local _M = {}
|
|
||||||
|
|
||||||
--用户登录业务逻辑处理
|
|
||||||
function _M.login(id)
|
|
||||||
local code = 0
|
|
||||||
local ret = "{}"
|
|
||||||
local result = resp:json(code, ret)
|
|
||||||
resp:send(result)
|
|
||||||
end
|
|
||||||
|
|
||||||
--用户登出业务逻辑处理
|
|
||||||
function _M.logout(id)
|
|
||||||
local code = 0
|
|
||||||
local ret = "{}"
|
|
||||||
local result = resp:json(code, ret)
|
|
||||||
resp:send(result)
|
|
||||||
end
|
|
||||||
|
|
||||||
return _M
|
|
||||||
61
src/api/system/controller.lua
Normal file
61
src/api/system/controller.lua
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
---
|
||||||
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||||
|
--- Created by admin.
|
||||||
|
--- DateTime: 2025/10/28 11:09
|
||||||
|
---
|
||||||
|
local validator = require("util.validator")
|
||||||
|
local helpers = require("util.helpers")
|
||||||
|
local resp = require("util.response")
|
||||||
|
local dao = require("service.system.controller")
|
||||||
|
|
||||||
|
local _M = {}
|
||||||
|
|
||||||
|
--用户登录业务逻辑处理
|
||||||
|
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
|
||||||
|
|
||||||
|
return _M
|
||||||
|
|
@ -43,7 +43,7 @@ function _M.addAccount(jsonData)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--账户存在时返回账户已经存在
|
--账户存在时返回账户已经存在
|
||||||
if num <= 0 then
|
if num > 0 then
|
||||||
return 0x01000C, nil
|
return 0x01000C, nil
|
||||||
end
|
end
|
||||||
--键值为id产生uuid数据值,增加到json中
|
--键值为id产生uuid数据值,增加到json中
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ function _M.addApplication(jsonData)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--应用存在时返回应用已经存在
|
--应用存在时返回应用已经存在
|
||||||
if num <= 0 then
|
if num > 0 then
|
||||||
return 0x01000C, nil
|
return 0x01000C, nil
|
||||||
end
|
end
|
||||||
--键值为id产生uuid数据值,增加到json中
|
--键值为id产生uuid数据值,增加到json中
|
||||||
|
|
|
||||||
85
src/service/system/controller.lua
Normal file
85
src/service/system/controller.lua
Normal file
|
|
@ -0,0 +1,85 @@
|
||||||
|
---
|
||||||
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
||||||
|
--- Created by admin.
|
||||||
|
--- DateTime: 2025/10/28 11:09
|
||||||
|
---
|
||||||
|
local validator = require("util.validator")
|
||||||
|
local helpers = require("util.helpers")
|
||||||
|
local resp = require("util.response")
|
||||||
|
local user = require("model.user")
|
||||||
|
|
||||||
|
local _M = {}
|
||||||
|
|
||||||
|
--认证用户返回用户数据信息
|
||||||
|
local function authenticate(username, password)
|
||||||
|
--验证用户名是否为空
|
||||||
|
if username == nil or username == "" then
|
||||||
|
return 0x010003, nil
|
||||||
|
end
|
||||||
|
--验证密码是否为空
|
||||||
|
if password == nil or password == "" then
|
||||||
|
return 0x010002, nil
|
||||||
|
end
|
||||||
|
--根据用户进行验证用户是否存在
|
||||||
|
local code, res = user:where("name", "=", username).where("password", "=", password):get()
|
||||||
|
if code == 0 and res ~= nil then
|
||||||
|
return code, res
|
||||||
|
end
|
||||||
|
--根据手机号进行验证用户是否存在
|
||||||
|
code, res = user:where("phone", "=", username).where("password", "=", password):get()
|
||||||
|
if code == 0 and res ~= nil then
|
||||||
|
return code, res
|
||||||
|
end
|
||||||
|
--根据邮箱进行验证用户是否存在
|
||||||
|
code, res = user:where("email", "=", username).where("password", "=", password):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, passwd, captcha, 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
|
||||||
|
|
@ -43,7 +43,7 @@ function _M.addOrganization(jsonData)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--组织架构存在时返回组织架构已经存在
|
--组织架构存在时返回组织架构已经存在
|
||||||
if num <= 0 then
|
if num > 0 then
|
||||||
return 0x01000C, nil
|
return 0x01000C, nil
|
||||||
end
|
end
|
||||||
--键值为id产生uuid数据值,增加到json中
|
--键值为id产生uuid数据值,增加到json中
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ function _M.addPermission(jsonData)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--权限存在时返回权限已经存在
|
--权限存在时返回权限已经存在
|
||||||
if num <= 0 then
|
if num > 0 then
|
||||||
return 0x01000C, nil
|
return 0x01000C, nil
|
||||||
end
|
end
|
||||||
--键值为id产生uuid数据值,增加到json中
|
--键值为id产生uuid数据值,增加到json中
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ function _M.addRole(jsonData)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--角色存在时返回账号已经存在
|
--角色存在时返回账号已经存在
|
||||||
if num <= 0 then
|
if num > 0 then
|
||||||
return 0x01000C, nil
|
return 0x01000C, nil
|
||||||
end
|
end
|
||||||
--键值为id产生uuid数据值,增加到json中
|
--键值为id产生uuid数据值,增加到json中
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ function _M.addUser(jsonData)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
--用户存在时返回用户已经存在
|
--用户存在时返回用户已经存在
|
||||||
if num <= 0 then
|
if num > 0 then
|
||||||
return 0x01000C,nil
|
return 0x01000C,nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user