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")