From b202af98292d6d7b5053e5a934b916153ce89af9 Mon Sep 17 00:00:00 2001 From: Ted Trask Date: Tue, 28 Sep 2010 07:15:36 +0000 Subject: Made major changes to authenticator and roles to improve efficiency. Changed authenticator.lua to request individual users, rather than always loading everyone. Modified get_userinfo and removed get_userinfo_roles and get_userinfo_skin to remove unnecessary cfe processing. This was especially bad when retrieving the cfe options for skins and roles. This does break the interface used by other modules like acf-tinydns. Validation and cfe processing were moved into password-model, where they belong. Added global variables to authenticator and roles libraries so they can reuse data that was already generated. Modified logon-controller to only check for zero users if logon fails. --- lib/roles.lua | 98 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 56 insertions(+), 42 deletions(-) (limited to 'lib/roles.lua') diff --git a/lib/roles.lua b/lib/roles.lua index a07d290..e5786ba 100644 --- a/lib/roles.lua +++ b/lib/roles.lua @@ -8,17 +8,22 @@ module (..., package.seeall) guest_role = "GUEST" +-- Global variables so we don't have to figure out all the roles multiple times +local defined_roles, default_roles, reverseroles, roles_candidates, role_table + -- returns a table of the *.roles files -- startdir should be the app dir local get_roles_candidates = function(self) - local list = {} - for p in string.gmatch(self.conf.appdir, "[^,]+") do - local l = fs.find_files_as_array(".*%.roles", p, true) or {} - for i,f in ipairs(l) do - list[#list+1] = f + if not roles_candidates then + roles_candidates = {} + for p in string.gmatch(self.conf.appdir, "[^,]+") do + local l = fs.find_files_as_array(".*%.roles", p, true) or {} + for i,f in ipairs(l) do + roles_candidates[#roles_candidates+1] = f + end end end - return list + return roles_candidates end -- Return a list of *controller.lua files @@ -90,52 +95,61 @@ get_controllers_view = function(self,controller_info) end list_default_roles = function(self) - local default_roles = {} - local reverseroles = {} + if not default_roles then + default_roles = {} + reverseroles = {} - -- find all of the default roles files and parse them - local rolesfiles = get_roles_candidates(self) + -- find all of the default roles files and parse them + local rolesfiles = get_roles_candidates(self) - for x,file in ipairs(rolesfiles) do - f = fs.read_file_as_array(file) or {} - local rolefile = string.match(file, "(/[^/]+/[^/]+)%.roles$") - for y,line in pairs(f) do - local role = string.match(line,"^[%w_]+") - if role then - if not reverseroles[rolefile.."/"..role] then - default_roles[#default_roles+1] = rolefile.."/"..role - reverseroles[default_roles[#default_roles]] = #default_roles - end - if not reverseroles[role] then - default_roles[#default_roles+1] = role - reverseroles[default_roles[#default_roles]] = #default_roles + for x,file in ipairs(rolesfiles) do + f = fs.read_file_as_array(file) or {} + local rolefile = string.match(file, "(/[^/]+/[^/]+)%.roles$") + for y,line in pairs(f) do + local role = string.match(line,"^[%w_]+") + if role then + if not reverseroles[rolefile.."/"..role] then + default_roles[#default_roles+1] = rolefile.."/"..role + reverseroles[default_roles[#default_roles]] = #default_roles + end + if not reverseroles[role] then + default_roles[#default_roles+1] = role + reverseroles[default_roles[#default_roles]] = #default_roles + end end end end - end - table.sort(default_roles, function(a,b) - if string.byte(a, 1) == 47 and string.byte(b,1) ~= 47 then return false - elseif string.byte(a, 1) ~= 47 and string.byte(b,1) == 47 then return true - else return a