Files
daydaytalk-fwutils/target/fwutils/request_config.lua
2026-01-08 21:58:41 +08:00

64 lines
1.7 KiB
Lua

local request = require("fastweb.request")
local token_module = require("fwutils.token")
local config = require("fwutils.config")
local cjson = require("cjson")
local utils = require("utils")
local fwutils_init = require("fwutils.init")
local M = {}
M.__filepath = nil
M.__method = nil
M.__url_param = nil
M.__action = nil
M.__user_data = nil
M.__role_id = nil
M.__ext = nil
M.init = function(website_config)
M.__filepath = request.filepath()
M.__method = request.method()
M.__url_param = request.url_param()
M.__action = nil
M.__user_data = nil
M.__role_id = nil
M.__ext = utils.ext(M.__filepath)
-- 修饰路径
if M.__filepath == "/" then
M.__filepath = website_config.default_filepath
end
-- 获取动作
if M.__url_param ~= nil then
M.__action = M.__url_param["action"]
end
-- 获取TOKEN
local token = string.match(request.header("Cookie"),"token=(%w+)")
if token ~= nil and token ~= "" then
local result,user_data = token_module.get(token)
-- print("TOKEN_DATA:",cjson.encode(user_data))
if result and user_data ~= nil and user_data["role_id"] ~= nil and user_data["role_id"] > 0 then
M.__user_data = user_data
M.__role_id = user_data["role_id"]
request.set("user_data",cjson.encode(user_data))
else
M.__role_id = fwutils_init.guest_role_id()
end
else
-- 访客
M.__role_id = fwutils_init.guest_role_id()
end
end
M.role_id = function()
return M.__role_id
end
M.user_data = function()
return M.__user_data
end
M.action = function()
return M.__action
end
M.filepath = function()
return M.__filepath
end
M.ext = function()
return M.__ext
end
return M