summaryrefslogtreecommitdiffstats
path: root/app/acf-util/logon-controller.lua
blob: 8d4f57e2e530b2c6f1f967d90a347c8b64de82b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- Logon / Logoff functions

module (..., package.seeall)

default_action = "status"

-- Logon a new user based upon id and password in clientdata
logon = function(self)
	local userid = cfe({ value=clientdata.userid or "", label="User ID" })
	local password = cfe({ label="Password" })
	local cmdresult = cfe({ type="form", value={userid=userid, password=password}, label="Logon" })
	if clientdata.userid and clientdata.password then
		local logon = self.model:logon(clientdata, conf.clientip, conf.sessiondir, sessiondata)
		-- If successful logon, redirect to welcome-page, otherwise try again
		if logon.value then
			self.conf.controller = ""
			redirect(self, "")
		else
			cmdresult.errtxt = "Logon Attempt Failed"
		end
	end
	return cmdresult
end

-- Log out current user and go to login screen
logout = function(self)
	local logout = self.model.logoff(conf.sessiondir, sessiondata)
	-- We have to redirect so a new session / menu is created
	redirect(self, "logon")
end

-- Report the login status
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} })
end