55 lines
1.6 KiB
Lua
55 lines
1.6 KiB
Lua
local fw = require("fastweb")
|
|
local utils = require("utils")
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
M.initialization = function(conn)
|
|
|
|
local result,err = M.__get_guest_role_id(conn)
|
|
if result == false then
|
|
return false,err
|
|
end
|
|
|
|
--生成字节码
|
|
local module_menu = require("fwutils.develop.function.menu")
|
|
local module_acl = require("fwutils.develop.function.role_permissions")
|
|
local module_template = require("fwutils.develop.function.template")
|
|
if not module_menu.make_bytecode(nil,conn) then
|
|
return false,"menu bytecode generation failed"
|
|
end
|
|
if not module_acl.make_bytecode(nil,conn) then
|
|
return false,"acl bytecode generation failed"
|
|
end
|
|
if not module_template.make_bytecode(conn) then
|
|
return false,"template bytecode generation failed"
|
|
end
|
|
return true
|
|
end
|
|
M.__get_guest_role_id = function(mysql_conn)
|
|
local config = require("fwutils.config")
|
|
local ppst = mysql_conn:setsql("SELECT * FROM fw_role WHERE guest = 1 AND server_id = ?")
|
|
ppst:set_str(1,config.server_id)
|
|
local result = ppst:query()
|
|
if result:row_count() ~= 1 then
|
|
return false,"role guest not found"
|
|
end
|
|
|
|
result:next()
|
|
local bc = {
|
|
GUEST_ROLE_ID = result:get("id"),
|
|
}
|
|
|
|
local code = "return " .. require("serpent").serialize(bc, {comment = false})
|
|
utils.save_file(fw.website_dir().."/"..(config.path.luabytecode:gsub("%.", "/")).."/fwcache.lua",code)
|
|
return true
|
|
end
|
|
M.guest_role_id = function()
|
|
local config = require("fwutils.config")
|
|
return require(config.path.luabytecode..".fwcache").GUEST_ROLE_ID
|
|
end
|
|
|
|
|
|
|
|
return M |