summaryrefslogtreecommitdiffstats
path: root/app/acf-util/logon-controller.lua
diff options
context:
space:
mode:
Diffstat (limited to 'app/acf-util/logon-controller.lua')
-rw-r--r--app/acf-util/logon-controller.lua61
1 files changed, 26 insertions, 35 deletions
diff --git a/app/acf-util/logon-controller.lua b/app/acf-util/logon-controller.lua
index bd26e10..cc4b6f2 100644
--- a/app/acf-util/logon-controller.lua
+++ b/app/acf-util/logon-controller.lua
@@ -4,7 +4,7 @@ local mymodule = {}
mymodule.default_action = "status"
--- Logon a new user based upon id and password in clientdata
+-- If there are no users defined, default to creating new ADMIN user
local check_users = function(self)
-- If there are no users defined, add privileges and dispatch password/newuser
local users = self.model:list_users()
@@ -13,6 +13,7 @@ local check_users = function(self)
self.sessiondata.permissions[self.conf.prefix].password.newuser = {"temp"}
self:dispatch(self.conf.prefix, "password", "newuser")
self.sessiondata.permissions[self.conf.prefix].password = nil
+ -- suppress the view, because the dispatch above has already handled the output
self.conf.suppress_view = true
return true
end
@@ -22,50 +23,45 @@ end
-- Logon a new user based upon id and password in clientdata
mymodule.logon = function(self)
- local userid = cfe({ value=self.clientdata.userid or "", label="User ID", seq=1 })
- local password = cfe({ type="password", label="Password", seq=2 })
- local redir = cfe({ type="hidden", value=self.clientdata.redir, label="" })
- local cmdresult = cfe({ type="form", value={userid=userid, password=password, redir=redir}, label="Logon", option="Logon" })
- if self.clientdata.submit then
+ -- First, handle special case when no users are defined
+ if check_users(self) then return end
+
+ return self.handle_form(self, self.model.get_logon, function(self, cmdresult, submit)
+ -- We will handle the redirect here
+ -- The session will be cleared on a successful logon, so grab the logonredirect now
local logonredirect = self.sessiondata.logonredirect
- local logon = self.model:logon(self.clientdata.userid, self.clientdata.password, self.conf.clientip, self.conf.sessiondir, self.sessiondata)
- -- If successful logon, redirect to home or welcome page, otherwise try again
- if logon.value then
- cmdresult.descr = "Logon Successful"
- else
- if check_users(self) then return end
- cmdresult.errtxt = "Logon Attempt Failed"
- end
- cmdresult = self:redirect_to_referrer(cmdresult)
- if logon.value then
- if redir.value == "" then
+ cmdresult = self.model.logon(self, cmdresult)
+ -- If successful logon, redirect to home or welcome page
+ if not cmdresult.errtxt then
+ local redir = self.clientdata.redir
+ if not redir or redir == "" then
if self.sessiondata.userinfo and self.sessiondata.userinfo.home and self.sessiondata.userinfo.home ~= "" then
- redir.value = self.sessiondata.userinfo.home
+ redir = self.sessiondata.userinfo.home
elseif self.conf.home and self.conf.home ~= "" then
- redir.value = self.conf.home
+ redir = self.conf.home
else
- redir.value = "/acf-util/welcome/read"
+ redir = "/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)
+ if logonredirect and redir then
+ local prefix, controller, action = self.parse_redir_string(redir)
if logonredirect.action == action and logonredirect.controller == controller and logonredirect.prefix == prefix then
self.sessiondata.logonredirect = logonredirect
end
end
- self:redirect(cmdresult.value.redir.value)
+ -- we always want a redirect will occur, but nothing is expecting a command result
+ -- so do the redirect here instead of in handle_form and don't pass any data
+ self:redirect(redir)
end
- else
- if check_users(self) then return end
- cmdresult = self:redirect_to_referrer() or cmdresult
- end
- return cmdresult
+ return cmdresult
+ end, self.clientdata, "Logon", "Logon", "Logon Successful")
end
-- Log off current user and go to logon screen
mymodule.logoff = function(self)
- local logoff = self.model.logoff(self.conf.sessiondir, self.sessiondata)
+ -- This is an unusual action in that it does not require "submit" to take an action
+ local logoff = self.model.logoff(self)
-- We have to redirect so a new session / menu is created
self:redirect("logon")
return logoff
@@ -73,12 +69,7 @@ end
-- Report the logon status
mymodule.status = function(self)
- local name = cfe({ label="User Name" })
- local sessionid = cfe({ value=self.sessiondata.id or "", label="Session ID" })
- if self.sessiondata.userinfo then
- name.value = self.sessiondata.userinfo.username or ""
- end
- return cfe({ type="group", value={username=name, sessionid=sessionid}, label="Logon Status" })
+ return self.model.status(self)
end
return mymodule