diff options
author | Ted Trask <ttrask01@yahoo.com> | 2014-10-01 21:22:08 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2014-10-01 21:22:08 +0000 |
commit | 6c1b7edae605eb56e7b3d87f3d824b729e1dc797 (patch) | |
tree | 498da52806d15f50c422061152cbecec08afae41 /app/acf-util/logon-model.lua | |
parent | ca2c56d0457cb40517ca744e177e1d0060fdfc2c (diff) | |
download | acf-core-6c1b7edae605eb56e7b3d87f3d824b729e1dc797.tar.bz2 acf-core-6c1b7edae605eb56e7b3d87f3d824b729e1dc797.tar.xz |
Modify logon to move logic to the model, leaving redirect in the controller
Diffstat (limited to 'app/acf-util/logon-model.lua')
-rw-r--r-- | app/acf-util/logon-model.lua | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/app/acf-util/logon-model.lua b/app/acf-util/logon-model.lua index 279e988..0cfba7f 100644 --- a/app/acf-util/logon-model.lua +++ b/app/acf-util/logon-model.lua @@ -8,53 +8,73 @@ fs = require ("acf.fs") roles = require ("roles") authenticator = require ("authenticator") +-- Report the logon status +mymodule.status = function(self) + local result = cfe({ type="group", value={}, label="Logon Status" }) + result.value.username = cfe({ label="User Name" }) + result.value.sessionid = cfe({ value=self.sessiondata.id or "", label="Session ID" }) + if self.sessiondata.userinfo then + result.value.username.value = self.sessiondata.userinfo.username or "" + end + return result +end + -- Logoff the user by deleting session data -mymodule.logoff = function (sessiondir, sessiondata) +mymodule.logoff = function (self) -- Unlink / delete the current session - local result = session.unlink_session(sessiondir, sessiondata.id) + local result = session.unlink_session(self.conf.sessiondir, self.sessiondata.id) local success = (result ~= nil) -- Clear the current session data - for a,b in pairs(sessiondata) do - sessiondata[a] = nil + for a,b in pairs(self.sessiondata) do + self.sessiondata[a] = nil end return cfe({ type="boolean", value=success, label="Logoff Success" }) end +mymodule.get_logon = function(self, clientdata) + local cmdresult = cfe({ type="group", value={}, label="Logon" }) + cmdresult.value.userid = cfe({ value=self.clientdata.userid or "", label="User ID", seq=1 }) + cmdresult.value.password = cfe({ type="password", label="Password", seq=2 }) + cmdresult.value.redir = cfe({ type="hidden", value=self.clientdata.redir, label="" }) + return cmdresult +end + -- Log on new user if possible and set up userinfo in session -- if we fail, we leave the session alone (don't log off) -mymodule.logon = function (self, userid, password, ip_addr, sessiondir, sessiondata) +mymodule.logon = function (self, logon) + logon.errtxt = "Logon Attempt Failed" -- Check to see if we can log on this user id / ip addr - local countevent = session.count_events(sessiondir, userid, session.hash_ip_addr(ip_addr), self.conf.lockouttime, self.conf.lockouteventlimit) + local countevent = session.count_events(self.conf.sessiondir, logon.value.userid.value, session.hash_ip_addr(self.conf.clientip), self.conf.lockouttime, self.conf.lockouteventlimit) if countevent then - session.record_event(sessiondir, userid, session.hash_ip_addr(ip_addr)) + session.record_event(self.conf.sessiondir, logon.value.userid.value, session.hash_ip_addr(self.conf.clientip)) end - if false == countevent and userid and password then - if authenticator.authenticate (self, userid, password) then + if false == countevent then + if authenticator.authenticate (self, logon.value.userid.value, logon.value.password.value) then -- We have a successful logon, change sessiondata -- for some reason, can't call this function or it skips rest of logon - -- mymodule.logoff(sessiondir, sessiondata) + -- mymodule.logoff(self.conf.sessiondir, self.sessiondata) ---[[ so, do this instead - session.unlink_session(sessiondir, sessiondata.id) + session.unlink_session(self.conf.sessiondir, self.sessiondata.id) -- Clear the current session data - for a,b in pairs(sessiondata) do - if a ~= "id" then sessiondata[a] = nil end + for a,b in pairs(self.sessiondata) do + if a ~= "id" then self.sessiondata[a] = nil end end --]] - sessiondata.id = session.random_hash(512) - local t = authenticator.get_userinfo (self, userid) - sessiondata.userinfo = {} + self.sessiondata.id = session.random_hash(512) + local t = authenticator.get_userinfo (self, logon.value.userid.value) + self.sessiondata.userinfo = {} for name,value in pairs(t) do - sessiondata.userinfo[name] = value + self.sessiondata.userinfo[name] = value end - return cfe({ type="boolean", value=true, label="Logon Success" }) + logon.errtxt = nil else -- We have a bad logon, log the event - session.record_event(sessiondir, userid, session.hash_ip_addr(ip_addr)) + session.record_event(self.conf.sessiondir, logon.value.userid.value, session.hash_ip_addr(self.conf.clientip)) end end - return cfe({ type="boolean", value=false, label="Logon Success" }) + return logon end mymodule.list_users = function(self) |