summaryrefslogtreecommitdiffstats
path: root/app/acf-util/logon-model.lua
diff options
context:
space:
mode:
authorNatanael Copa <natanael.copa@gmail.com>2007-07-27 12:53:38 +0000
committerNatanael Copa <natanael.copa@gmail.com>2007-07-27 12:53:38 +0000
commitdc53423183a0c459284ebd139022b707f01af006 (patch)
tree8a67a2904ec991028bddd429d57eec114b05baab /app/acf-util/logon-model.lua
parent275c80281ba2e84b8d810bdb1c2b7f8c9a4333d9 (diff)
downloadacf-core-2.0_alpha1.tar.bz2
acf-core-2.0_alpha1.tar.xz
moved core files to new dir structurev2.0_alpha1
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@219 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'app/acf-util/logon-model.lua')
-rw-r--r--app/acf-util/logon-model.lua61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/acf-util/logon-model.lua b/app/acf-util/logon-model.lua
new file mode 100644
index 0000000..dbd8522
--- /dev/null
+++ b/app/acf-util/logon-model.lua
@@ -0,0 +1,61 @@
+-- Logon / Logoff model functions
+
+module (..., package.seeall)
+
+local sess = require ("session")
+
+local pvt = {}
+
+
+-- return a sessionid if username / password is valid, false
+-- /etc/acf/passwd should be lines of userid:passwd:user name:role1[,role2[,role3]]
+pvt.logon = function (self, id, passwd )
+ -- if we already have sessionid... then you are already logged in
+ if self.session.id then
+ return false
+ end
+
+ id = id or ""
+ passwd = passwd or ""
+
+ -- open our hokey password file,
+ local f = io.open(self.conf.confdir .. "/passwd" )
+ if f then
+ m = f:read("*all") .. "\n"
+ f:close()
+
+ for l in string.gmatch(m, "(%C*)\n") do
+ local userid, password, username, roles =
+ string.match(l, "([^:]*):([^:]*):([^:]*):(.*)")
+ if userid == id and password == passwd then
+ self.session.id = sess.random_hash(512)
+ self.session.name = username
+ self.session.roles = roles
+ break
+ end
+ end
+ end
+ if self.session.id then
+ local x = require("session")
+ x.save_session(self.conf.sessiondir, self.session.id, self.session)
+ x=nil
+ return self.session.id
+ else
+ return false
+ end
+end
+
+-- invalidate the session, or return false if the session wasn't valid
+pvt.logout = function (self, sessionid)
+
+ sess.invalidate_session ( self.conf.sessiondir, sessionid)
+ self.session = {}
+
+end
+
+-------------------------------------------------------------------------
+-- Public Methods
+-------------------------------------------------------------------------
+
+logon = pvt.logon
+logout = pvt.logout