From c9845b75521b3ce6872ac12510713faa894809d7 Mon Sep 17 00:00:00 2001 From: wanglei <34475144@qq.com> Date: Tue, 4 Nov 2025 21:57:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=B8=E5=85=B3=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E6=93=8D=E4=BD=9C=E6=95=B0=E6=8D=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C=E5=92=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E6=9A=82=E6=97=B6=E8=BF=9B?= =?UTF-8?q?=E8=A1=8Cmd5=E5=8A=A0=E5=AF=86=EF=BC=8C=E7=84=B6=E5=90=8E?= =?UTF-8?q?=E5=AD=98=E5=85=A5=E5=88=B0=E6=95=B0=E6=8D=AE=E8=A1=A8=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/nginx.conf | 8 ++++---- src/api/system/account.lua | 2 +- src/api/system/application.lua | 2 +- src/api/system/department.lua | 2 +- src/api/system/menu.lua | 2 +- src/api/system/permission.lua | 2 +- src/api/system/postion.lua | 2 +- src/api/system/role.lua | 2 +- src/dao/auth.lua | 7 ++++--- src/dao/user.lua | 4 +++- src/init.lua | 6 +++++- 11 files changed, 23 insertions(+), 16 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 1b9a0a6..e3c042f 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -24,10 +24,10 @@ http { # The verification depth in the server certificates chain. #lua_ssl_verify_depth 3; - # 在 Nginx 启动时执行的 Lua 代码块 + #在Nginx启动时执行的Lua代码块 lua_shared_dict dict_a 1m; init_by_lua_block { - -- 定义一个全局变量 + -- 定义一个全局变量 ngx.log(ngx.INFO, "Initializing global variable") global_var = "Hello, Nginx with Lua!" @@ -35,8 +35,8 @@ http { local shared_dict = ngx.shared.dict_a shared_dict:set("key", "value") } - - #下面代码不能与上面的代码进行共用,否则报错nginx: [emerg] "init_by_lua_file" directive is duplicate + #init_by_lua_block 与 init_by_lua_file 只能初始化其中的一个,不能同时启用 + #否则报错nginx: [emerg] "init_by_lua_file" directive is duplicate #init_by_lua_file '/home/frankly/work/AuthPlatform/src/init.lua'; server { diff --git a/src/api/system/account.lua b/src/api/system/account.lua index e4dad4b..4673cb1 100644 --- a/src/api/system/account.lua +++ b/src/api/system/account.lua @@ -11,7 +11,7 @@ local systemAccount = require("service.system.account") --定义相关路由,前端接口url地址 local routes = { - --用户相关路由接口 + --账户相关路由接口 { paths = { "/api/system/accounts" }, methods = { "GET" }, diff --git a/src/api/system/application.lua b/src/api/system/application.lua index a8dcf6e..f9c3bff 100644 --- a/src/api/system/application.lua +++ b/src/api/system/application.lua @@ -11,7 +11,7 @@ local systemApplication = require("service.system.application") --定义相关路由,前端接口url地址 local routes = { - --用户相关路由接口 + --应用相关路由接口 { paths = { "/api/system/applications" }, methods = { "GET" }, diff --git a/src/api/system/department.lua b/src/api/system/department.lua index 4eba869..edbd17e 100644 --- a/src/api/system/department.lua +++ b/src/api/system/department.lua @@ -11,7 +11,7 @@ local systemDepartment = require("service.system.department") --定义相关路由,前端接口url地址 local routes = { - --用户相关路由接口 + --组织(部门)相关路由接口 { paths = { "/api/system/departments" }, methods = { "GET" }, diff --git a/src/api/system/menu.lua b/src/api/system/menu.lua index 8774a3c..2b3ff67 100644 --- a/src/api/system/menu.lua +++ b/src/api/system/menu.lua @@ -11,7 +11,7 @@ local systemMenu = require("service.system.menu") --定义相关路由,前端接口url地址 local routes = { - --用户相关路由接口 + --菜单相关路由接口 { paths = { "/api/system/menus" }, methods = { "GET" }, diff --git a/src/api/system/permission.lua b/src/api/system/permission.lua index e2e7810..bfd0f00 100644 --- a/src/api/system/permission.lua +++ b/src/api/system/permission.lua @@ -11,7 +11,7 @@ local systemPermission = require("service.system.permission") --定义相关路由,前端接口url地址 local routes = { - --用户相关路由接口 + --权限相关路由接口 { paths = { "/api/system/permissions" }, methods = { "GET" }, diff --git a/src/api/system/postion.lua b/src/api/system/postion.lua index 700e244..7caad16 100644 --- a/src/api/system/postion.lua +++ b/src/api/system/postion.lua @@ -11,7 +11,7 @@ local systemPosition = require("service.system.position") --定义相关路由,前端接口url地址 local routes = { - --用户相关路由接口 + --岗位相关路由接口 { paths = { "/api/system/positions" }, methods = { "GET" }, diff --git a/src/api/system/role.lua b/src/api/system/role.lua index 957654a..ea115ec 100644 --- a/src/api/system/role.lua +++ b/src/api/system/role.lua @@ -11,7 +11,7 @@ local systemRole = require("service.system.role") --定义相关路由,前端接口url地址 local routes = { - --用户相关路由接口 + --角色相关路由接口 { paths = { "/api/system/roles" }, methods = { "GET" }, diff --git a/src/dao/auth.lua b/src/dao/auth.lua index 8c1da3f..bc83446 100644 --- a/src/dao/auth.lua +++ b/src/dao/auth.lua @@ -20,18 +20,19 @@ local function authenticate(name, passwd) if passwd == "" then return 0x010002, nil end + local pwdMd5 = ngx.encode_md5(passwd) --根据用户进行验证用户是否存在 - local code, res = userModel:where("username", "=", name):where("password", "=", passwd):get() + local code, res = userModel:where("username", "=", name):where("password", "=", pwdMd5):get() if code == 0 and res ~= nil then return code, res end --根据手机号进行验证用户是否存在 - code, res = userModel:where("phone", "=", name):where("password", "=", passwd):get() + code, res = userModel:where("phone", "=", name):where("password", "=", pwdMd5):get() if code == 0 and res ~= nil then return code, res end --根据邮箱进行验证用户是否存在 - code, res = userModel:where("email", "=", name):where("password", "=", passwd):get() + code, res = userModel:where("email", "=", name):where("password", "=", pwdMd5):get() if code == 0 and res ~= nil then return code, res end diff --git a/src/dao/user.lua b/src/dao/user.lua index 069b0d3..020bc7b 100644 --- a/src/dao/user.lua +++ b/src/dao/user.lua @@ -15,7 +15,6 @@ local _M = {} local user = { ["ID"] = "", ["type"] = 0, - } --判断用户是否存在 @@ -72,6 +71,9 @@ function _M.addSystemUser(jsonData) --键值为id产生uuid数据值,增加到json中 jsonData.id = helpers.getUuid() + --用户密码暂时使用md5进行加密 + local pwd = jsonData['password'] + jsonData.password = ngx.encode_md5(pwd) -- 创建一个用户 return userModel:create(jsonData) end diff --git a/src/init.lua b/src/init.lua index 556aeb4..190a261 100644 --- a/src/init.lua +++ b/src/init.lua @@ -3,9 +3,13 @@ --- Created by frankly. --- DateTime: 2025/11/3 18:44 --- +--[[ +在"ngx_lua"模块的"init_by_lua_file"命令中执行; +只在启动nginx时初始化一次。 +--]] print("init application...") - +--初始化,获取系统默认的用户权限,为实现RBAC框架做权限数据准备 cjson = require "cjson" local dict_a = ngx.shared.dict_a local v = dict_a:get("abc")