diff --git a/src/api/api.lua b/src/api/api.lua index c4aa74d..8da5491 100644 --- a/src/api/api.lua +++ b/src/api/api.lua @@ -3,15 +3,17 @@ --- Created by admin. --- DateTime: 2025/9/24 15:29 --- +--解析url路由过滤库 local radix = require("resty.radixtree") +--数据表业务处理 local userApi = require("api.system.user") local accountApi = require("api.system.account") local roleApi = require("api.system.role") local permissionApi = require("api.system.permission") local applicationApi = require("api.system.application") local organizationApi = require("api.system.organization") - -local controllerApi = require("api.controller") +--业务接口控制 +local controllerApi = require("api.system.controller") --定义相关路由,前端接口url地址 local routes = { diff --git a/src/api/controller.lua b/src/api/controller.lua deleted file mode 100644 index 8bb3b6d..0000000 --- a/src/api/controller.lua +++ /dev/null @@ -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 \ No newline at end of file diff --git a/src/api/system/controller.lua b/src/api/system/controller.lua new file mode 100644 index 0000000..c78d302 --- /dev/null +++ b/src/api/system/controller.lua @@ -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 \ No newline at end of file diff --git a/src/service/system/account.lua b/src/service/system/account.lua index c5f9442..a6edcd6 100644 --- a/src/service/system/account.lua +++ b/src/service/system/account.lua @@ -43,7 +43,7 @@ function _M.addAccount(jsonData) end end --账户存在时返回账户已经存在 - if num <= 0 then + if num > 0 then return 0x01000C, nil end --键值为id产生uuid数据值,增加到json中 diff --git a/src/service/system/application.lua b/src/service/system/application.lua index 68a2fe9..b1c1242 100644 --- a/src/service/system/application.lua +++ b/src/service/system/application.lua @@ -55,7 +55,7 @@ function _M.addApplication(jsonData) end end --应用存在时返回应用已经存在 - if num <= 0 then + if num > 0 then return 0x01000C, nil end --键值为id产生uuid数据值,增加到json中 diff --git a/src/service/system/controller.lua b/src/service/system/controller.lua new file mode 100644 index 0000000..6ca7b4c --- /dev/null +++ b/src/service/system/controller.lua @@ -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 \ No newline at end of file diff --git a/src/service/system/organization.lua b/src/service/system/organization.lua index df0d5b3..e36f8c9 100644 --- a/src/service/system/organization.lua +++ b/src/service/system/organization.lua @@ -43,7 +43,7 @@ function _M.addOrganization(jsonData) end end --组织架构存在时返回组织架构已经存在 - if num <= 0 then + if num > 0 then return 0x01000C, nil end --键值为id产生uuid数据值,增加到json中 diff --git a/src/service/system/permission.lua b/src/service/system/permission.lua index d6551a3..e26d270 100644 --- a/src/service/system/permission.lua +++ b/src/service/system/permission.lua @@ -50,7 +50,7 @@ function _M.addPermission(jsonData) end end --权限存在时返回权限已经存在 - if num <= 0 then + if num > 0 then return 0x01000C, nil end --键值为id产生uuid数据值,增加到json中 diff --git a/src/service/system/role.lua b/src/service/system/role.lua index 24e9e88..280620f 100644 --- a/src/service/system/role.lua +++ b/src/service/system/role.lua @@ -43,7 +43,7 @@ function _M.addRole(jsonData) end end --角色存在时返回账号已经存在 - if num <= 0 then + if num > 0 then return 0x01000C, nil end --键值为id产生uuid数据值,增加到json中 diff --git a/src/service/system/user.lua b/src/service/system/user.lua index 4990ae3..a0bf6f3 100644 --- a/src/service/system/user.lua +++ b/src/service/system/user.lua @@ -46,7 +46,7 @@ function _M.addUser(jsonData) end end --用户存在时返回用户已经存在 - if num <= 0 then + if num > 0 then return 0x01000C,nil end