diff options
author | Ted Trask <ttrask01@yahoo.com> | 2010-10-06 12:57:42 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2010-10-06 12:57:42 +0000 |
commit | 25c09923e08f664a0c791f27d521fb13f4d5d74c (patch) | |
tree | 6410b0964cdbbd2603b9598f8474b5a9333be520 | |
parent | b202af98292d6d7b5053e5a934b916153ce89af9 (diff) | |
download | acf-core-25c09923e08f664a0c791f27d521fb13f4d5d74c.tar.bz2 acf-core-25c09923e08f664a0c791f27d521fb13f4d5d74c.tar.xz |
Added home page (action) to user parameters and redirect there after login
Moved get_all_permissions function from acf-util/roles-model to lib/roles
-rw-r--r-- | app/acf-util/logon-controller.lua | 9 | ||||
-rw-r--r-- | app/acf-util/password-model.lua | 16 | ||||
-rw-r--r-- | app/acf-util/roles-model.lua | 33 | ||||
-rw-r--r-- | app/acf_www-controller.lua | 4 | ||||
-rw-r--r-- | lib/authenticator.lua | 6 | ||||
-rw-r--r-- | lib/roles.lua | 35 |
6 files changed, 65 insertions, 38 deletions
diff --git a/app/acf-util/logon-controller.lua b/app/acf-util/logon-controller.lua index 2a88528..7bbd522 100644 --- a/app/acf-util/logon-controller.lua +++ b/app/acf-util/logon-controller.lua @@ -24,7 +24,7 @@ end logon = function(self) local userid = cfe({ value=clientdata.userid or "", label="User ID" }) local password = cfe({ label="Password" }) - local redir = cfe({ value=clientdata.redir or "welcome/read", label="" }) + local redir = cfe({ value=clientdata.redir, label="" }) local cmdresult = cfe({ type="form", value={userid=userid, password=password, redir=redir}, label="Logon", option="Logon" }) if clientdata.Logon then local logonredirect = self.sessiondata.logonredirect @@ -38,6 +38,13 @@ logon = function(self) end cmdresult = self:redirect_to_referrer(cmdresult) if logon.value then + if redir.value == "" then + if self.sessiondata.userinfo and self.sessiondata.userinfo.home and self.sessiondata.userinfo.home ~= "" then + redir.value = self.sessiondata.userinfo.home + else + redir.value = "/acf-util/welcome/read" + end + end -- only copy the logonredirect if redirecting to that page if logonredirect and cmdresult.value.redir.value then local prefix, controller, action = self.parse_redir_string(cmdresult.value.redir.value) diff --git a/app/acf-util/password-model.lua b/app/acf-util/password-model.lua index b7e9ebe..e9e0cd6 100644 --- a/app/acf-util/password-model.lua +++ b/app/acf-util/password-model.lua @@ -3,7 +3,7 @@ module(..., package.seeall) require("authenticator") require("roles") -avail_roles, avail_skins = nil +avail_roles, avail_skins, avail_homes = nil local weak_password = function(password) -- If password is too short, return false @@ -19,7 +19,7 @@ end -- validate the settings (ignore password if it's nil) local validate_settings = function(settings) - -- Username, password, roles, and skin are allowed to not exist, just leave the same + -- Username, password, roles, skin, and home are allowed to not exist, just leave the same -- Set errtxt when entering invalid values if (#settings.value.userid.value == 0) then settings.value.userid.errtxt = "You need to enter a valid userid!" end if string.find(settings.value.userid.value, "[^%w_]") then settings.value.userid.errtxt = "Can only contain letters, numbers, and '_'" end @@ -36,6 +36,7 @@ local validate_settings = function(settings) end if settings.value.roles then modelfunctions.validatemulti(settings.value.roles) end if settings.value.skin then modelfunctions.validateselect(settings.value.skin) end + if settings.value.home then modelfunctions.validateselect(settings.value.home) end -- Return false if any errormessages are set for name,value in pairs(settings.value) do @@ -126,12 +127,23 @@ function read_user(self, user) end end + -- Call into ?? controller to get the list of home actions + if not avail_homes then + avail_homes = {""} + local tmp1, tmp2 = roles.get_all_permissions(self) + table.sort(tmp2) + for i,h in ipairs(tmp2) do + avail_homes[#avail_homes+1] = h + end + end + -- Passwords are set to empty string result.username = cfe({ value=userinfo.username or "", label="Real name" }) result.password = cfe({ value="", label="Password" }) result.password_confirm = cfe({ value="", label="Password (confirm)" }) result.roles = cfe({ type="multi", value=userinfo.roles or {}, label="Roles", option=avail_roles or {} }) result.skin = cfe({ type="select", value=userinfo.skin or "", label="Skin", option=avail_skins or {""} }) + result.home = cfe({ type="select", value=userinfo.home or "", label="Home", option=avail_homes or {""} }) return cfe({ type="group", value=result, label="User Config" }) end diff --git a/app/acf-util/roles-model.lua b/app/acf-util/roles-model.lua index e12d49a..cbd9f38 100644 --- a/app/acf-util/roles-model.lua +++ b/app/acf-util/roles-model.lua @@ -5,35 +5,6 @@ require("modelfunctions") require("authenticator") require("roles") -local get_all_permissions = function(self) - -- need to get a list of all the controllers - controllers = roles.get_controllers(self) - local table_perm = {} - local array_perm = {} - for a,b in pairs(controllers) do - if nil == table_perm[b.prefix] then - table_perm[b.prefix] = {} - end - if nil == table_perm[b.prefix][b.sname] then - table_perm[b.prefix][b.sname] = {} - end - local temp = roles.get_controllers_func(self,b) - for x,y in ipairs(temp) do - table_perm[b.prefix][b.sname][y] = {} - array_perm[#array_perm + 1] = b.prefix .. b.sname .. "/" .. y - end - temp = roles.get_controllers_view(self,b) - for x,y in ipairs(temp) do - if not table_perm[b.prefix][b.sname][y] then - table_perm[b.prefix][b.sname][y] = {} - array_perm[#array_perm + 1] = b.prefix .. b.sname .. "/" .. y - end - end - end - - return table_perm, array_perm -end - -- Return roles/permissions for specified user get_user_roles = function(self, userid) local userinfo = authenticator.get_userinfo(self, userid) or {} @@ -49,7 +20,7 @@ end -- Return list of all permissions get_perms_list = function(self) - return cfe({ type="table", value=get_all_permissions(self), label="All Permissions" }) + return cfe({ type="table", value=roles.get_all_permissions(self), label="All Permissions" }) end view_roles = function(self) @@ -73,7 +44,7 @@ getpermissions = function(self, role) role = "" end - local tmp, all_perms = get_all_permissions(self) + local tmp, all_perms = roles.get_all_permissions(self) table.sort(all_perms) local permissions_cfe = cfe({ type="multi", value=my_perms, option=all_perms, label="Role permissions", default=default_perms }) diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua index 25f4c09..8878a8b 100644 --- a/app/acf_www-controller.lua +++ b/app/acf_www-controller.lua @@ -408,6 +408,10 @@ dispatch = function (self, userprefix, userctlr, useraction) -- Find the proper controller/action combo local origconf = {} for name,value in pairs(self.conf) do origconf[name]=value end + if "" == self.conf.controller and self.sessiondata.userinfo and self.sessiondata.userinfo.home and self.sessiondata.userinfo.home ~= "" then + self.conf.prefix, self.conf.controller, self.conf.action = + parse_path_info(self.sessiondata.userinfo.home) + end if "" == self.conf.controller then self.conf.prefix = self.conf.default_prefix or "/" self.conf.controller = self.conf.default_controller or "" diff --git a/lib/authenticator.lua b/lib/authenticator.lua index 95eb3d7..724b854 100644 --- a/lib/authenticator.lua +++ b/lib/authenticator.lua @@ -37,6 +37,7 @@ local parse_entry = function(id, entry) a.username = fields[2] or "" a.roles = fields[3] or "" a.skin = fields[4] or "" + a.home = fields[5] or "" authstruct[id] = a end return a @@ -106,14 +107,15 @@ write_userinfo = function(self, userinfo) return false end id = get_id(self, userinfo.userid) or {} - -- Username, password, roles, skin are allowed to not exist, just leave the same + -- Username, password, roles, skin, home are allowed to not exist, just leave the same id.userid = userinfo.userid if userinfo.username then id.username = userinfo.username end if userinfo.password then id.password = md5.sumhexa(userinfo.password) end if userinfo.roles then id.roles = table.concat(userinfo.roles, ",") end if userinfo.skin then id.skin = userinfo.skin end + if userinfo.home then id.home = userinfo.home end - local success = auth.write_entry(self, usertable, "", id.userid, (id.password or "")..":"..(id.username or "")..":"..(id.roles or "")..":"..(id.skin or "")) + local success = auth.write_entry(self, usertable, "", id.userid, (id.password or "")..":"..(id.username or "")..":"..(id.roles or "")..":"..(id.skin or "")..":"..(id.home or "")) authstruct[userinfo.userid] = nil get_id(self, id.userid) diff --git a/lib/roles.lua b/lib/roles.lua index e5786ba..6c5b8a2 100644 --- a/lib/roles.lua +++ b/lib/roles.lua @@ -9,7 +9,7 @@ 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 +local defined_roles, default_roles, reverseroles, roles_candidates, role_table, table_perm, array_perm -- returns a table of the *.roles files -- startdir should be the app dir @@ -43,7 +43,7 @@ end -- Return information about all or specified controller files get_controllers = function(self,pre,controller) --we get all the controllers - local list = roles.list_controllers(self) + local list = list_controllers(self) --we need to grab the directory and name of file local temp = {} for k,v in pairs(list) do @@ -94,6 +94,37 @@ get_controllers_view = function(self,controller_info) return temp end +get_all_permissions = function(self) + if not table_perm or not array_perm then + -- need to get a list of all the controllers + controllers = get_controllers(self) + table_perm = {} + array_perm = {} + for a,b in pairs(controllers) do + if nil == table_perm[b.prefix] then + table_perm[b.prefix] = {} + end + if nil == table_perm[b.prefix][b.sname] then + table_perm[b.prefix][b.sname] = {} + end + local temp = get_controllers_func(self,b) + for x,y in ipairs(temp) do + table_perm[b.prefix][b.sname][y] = {} + array_perm[#array_perm + 1] = b.prefix .. b.sname .. "/" .. y + end + temp = get_controllers_view(self,b) + for x,y in ipairs(temp) do + if not table_perm[b.prefix][b.sname][y] then + table_perm[b.prefix][b.sname][y] = {} + array_perm[#array_perm + 1] = b.prefix .. b.sname .. "/" .. y + end + end + end + end + + return table_perm, array_perm +end + list_default_roles = function(self) if not default_roles then default_roles = {} |