summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-04-24 20:31:58 +0000
committerTed Trask <ttrask01@yahoo.com>2008-04-24 20:31:58 +0000
commit2ac0d30c272dc9c36c81792f608e4f6ce231ba7e (patch)
treece325a3c7c5614f634ea25e28bdaadedeadd791e
parentf87baaa40bcc86b62759df6bf884ff53548f348c (diff)
downloadacf-core-2ac0d30c272dc9c36c81792f608e4f6ce231ba7e.tar.bz2
acf-core-2ac0d30c272dc9c36c81792f608e4f6ce231ba7e.tar.xz
Replaced all list_redir functions with redirect in mvc.lua, implemented a default_action string in each controller, removing the on_load functions
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1037 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--app/acf-util/logon-controller.lua5
-rwxr-xr-xapp/acf-util/password-controller.lua5
-rw-r--r--app/acf-util/roles-controller.lua2
-rw-r--r--app/acf_www-controller.lua2
-rw-r--r--app/welcome-controller.lua2
-rwxr-xr-xwww/cgi-bin/mvc.lua41
6 files changed, 30 insertions, 27 deletions
diff --git a/app/acf-util/logon-controller.lua b/app/acf-util/logon-controller.lua
index 61b4864..8dddb87 100644
--- a/app/acf-util/logon-controller.lua
+++ b/app/acf-util/logon-controller.lua
@@ -2,10 +2,7 @@
module (..., package.seeall)
-mvc = {}
-mvc.on_load = function(self, parent)
- self.conf.default_action = "status"
-end
+default_action = "status"
-- Logon a new user based upon id and password in clientdata
logon = function(self)
diff --git a/app/acf-util/password-controller.lua b/app/acf-util/password-controller.lua
index f891c58..fdcca8a 100755
--- a/app/acf-util/password-controller.lua
+++ b/app/acf-util/password-controller.lua
@@ -2,10 +2,7 @@ module(..., package.seeall)
local auth=require("authenticator-plaintext")
-mvc = {}
-mvc.on_load = function(self, parent)
- self.conf.default_action = "status"
-end
+default_action = "status"
local function admin_permission()
-- if (sessiondata.userinfo) and (sessiondata.userinfo.userid == "alpine") then
diff --git a/app/acf-util/roles-controller.lua b/app/acf-util/roles-controller.lua
index 771c44e..b868924 100644
--- a/app/acf-util/roles-controller.lua
+++ b/app/acf-util/roles-controller.lua
@@ -2,6 +2,8 @@
module (..., package.seeall)
+default_action = "read"
+
read = function(self)
return ( { userid = self.sessiondata.userinfo.userid, roles = self.sessiondata.userinfo.roles, permissions = self.sessiondata.permissions } )
end
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua
index 54cab87..9983293 100644
--- a/app/acf_www-controller.lua
+++ b/app/acf_www-controller.lua
@@ -11,7 +11,6 @@ module(..., package.seeall)
-- require statements shouldn't need to go to the disk lib
require "posix"
-
-- We use the parent exception handler in a last-case situation
local parent_exception_handler
@@ -73,7 +72,6 @@ mvc.on_load = function (self, parent)
self.conf.appuri = "https://" .. ENV.HTTP_HOST .. ENV.SCRIPT_NAME
self.conf.default_prefix = "/"
self.conf.default_controller = "welcome"
- self.conf.default_action = "read"
self.clientdata = FORM
self.conf.clientip = ENV.REMOTE_ADDR
diff --git a/app/welcome-controller.lua b/app/welcome-controller.lua
index 3ff5cc5..77735ec 100644
--- a/app/welcome-controller.lua
+++ b/app/welcome-controller.lua
@@ -1,6 +1,8 @@
-- A standin controller for testing
module (..., package.seeall)
+default_action = "read"
+
read = function (self )
return ( {self = self} )
end
diff --git a/www/cgi-bin/mvc.lua b/www/cgi-bin/mvc.lua
index c64fa08..3a4b530 100755
--- a/www/cgi-bin/mvc.lua
+++ b/www/cgi-bin/mvc.lua
@@ -120,11 +120,11 @@ dispatch = function (self, userprefix, userctlr, useraction)
-- Find the proper controller/action combo
local origconf = {controller = self.conf.controller, action = self.conf.action}
local action = ""
- self.conf.default_controller = self.conf.default_controller or ""
- self.conf.default_prefix = self.conf.default_prefix or ""
+ local default_prefix = self.conf.default_prefix or ""
+ local default_controller = self.conf.default_controller or ""
if "" == self.conf.controller then
- self.conf.prefix = self.conf.default_prefix
- self.conf.controller = self.conf.default_controller
+ self.conf.prefix = default_prefix
+ self.conf.controller = default_controller
self.conf.action = ""
end
while "" ~= self.conf.controller do
@@ -139,11 +139,9 @@ dispatch = function (self, userprefix, userctlr, useraction)
controller, worker_loaded = self:new(self.conf.prefix .. self.conf.controller)
end
if worker_loaded then
- controller.conf.default_action = controller.conf.default_action or ""
- action = controller.conf.action or ""
- if "" == action then
- action = controller.conf.default_action
- end
+ local default_action = rawget(controller.worker, "default_action") or ""
+ action = self.conf.action
+ if action == "" then action = default_action end
while "" ~= action do
local perm = true
if type(controller.worker.mvc.check_permission) == "function" then
@@ -156,11 +154,10 @@ dispatch = function (self, userprefix, userctlr, useraction)
if perm and (type(rawget(controller.worker, action)) == "function") then
-- We have a valid and permissible controller / action
self.conf.action = action
- controller.conf.action = action
break
end
- if action ~= controller.conf.default_action then
- action = controller.conf.default_action
+ if action ~= default_action then
+ action = default_action
else
action = ""
end
@@ -172,9 +169,9 @@ dispatch = function (self, userprefix, userctlr, useraction)
controller = nil
end
self.conf.action = ""
- if self.conf.controller ~= self.conf.default_controller then
- self.conf.prefix = self.conf.default_prefix
- self.conf.controller = self.conf.default_controller
+ if self.conf.controller ~= default_controller then
+ self.conf.prefix = default_prefix
+ self.conf.controller = default_controller
else
self.conf.controller = ""
end
@@ -188,8 +185,7 @@ dispatch = function (self, userprefix, userctlr, useraction)
-- If we have different controller / action, redirect
if self.conf.controller ~= origconf.controller or self.conf.action ~= origconf.action then
- self.conf.type = "redir"
- error(self.conf)
+ redirect(self, self.conf.action)
end
-- run the (first found) pre_exec code, starting at the controller
@@ -232,6 +228,17 @@ dispatch = function (self, userprefix, userctlr, useraction)
end
end
+-- Cause a redirect to specified (or default) action
+-- We use the self.conf table because it already has prefix,controller,etc
+-- The actual redirection is defined in the application error handler (acf-controller)
+redirect = function (self, action)
+ if nil == action then
+ action = rawget(self.worker, "default_action") or ""
+ end
+ self.conf.action = action
+ self.conf.type = "redir"
+ error(self.conf)
+end
-- Tries to see if name exists in the self.conf.appdir, and if so, it loads it.
-- otherwise, returns nil, but no error