summaryrefslogtreecommitdiffstats
path: root/app/acf-util
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2013-10-17 18:59:27 +0000
committerTed Trask <ttrask01@yahoo.com>2013-10-17 18:59:27 +0000
commitc0e0377e384c8167172ee06d8c11ef2f782522c7 (patch)
treebb89301e467ff61d93a39642354bcfe382571529 /app/acf-util
parentfcaab1b363fcd5ff2dccce8f98cacabc5635ba5f (diff)
downloadacf-core-c0e0377e384c8167172ee06d8c11ef2f782522c7.tar.bz2
acf-core-c0e0377e384c8167172ee06d8c11ef2f782522c7.tar.xz
Remove all calls to 'module' in preparation for move to Lua 5.2
Use mymodule parameter for module definition. This was also helpfule in revealing places where the code relied on the global environment.
Diffstat (limited to 'app/acf-util')
-rw-r--r--app/acf-util/logon-controller.lua26
-rw-r--r--app/acf-util/logon-model.lua12
-rw-r--r--app/acf-util/password-controller.lua16
-rw-r--r--app/acf-util/password-model.lua20
-rw-r--r--app/acf-util/roles-controller.lua23
-rw-r--r--app/acf-util/roles-model.lua24
-rw-r--r--app/acf-util/skins-controller.lua9
-rw-r--r--app/acf-util/skins-model.lua10
-rw-r--r--app/acf-util/welcome-controller.lua8
9 files changed, 81 insertions, 67 deletions
diff --git a/app/acf-util/logon-controller.lua b/app/acf-util/logon-controller.lua
index 4fa3d20..bd26e10 100644
--- a/app/acf-util/logon-controller.lua
+++ b/app/acf-util/logon-controller.lua
@@ -1,8 +1,8 @@
-- Logon / Logoff functions
-module (..., package.seeall)
+local mymodule = {}
-default_action = "status"
+mymodule.default_action = "status"
-- Logon a new user based upon id and password in clientdata
local check_users = function(self)
@@ -21,14 +21,14 @@ local check_users = function(self)
end
-- Logon a new user based upon id and password in clientdata
-logon = function(self)
- local userid = cfe({ value=clientdata.userid or "", label="User ID", seq=1 })
+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=clientdata.redir, label="" })
+ 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 clientdata.submit then
+ if self.clientdata.submit then
local logonredirect = self.sessiondata.logonredirect
- local logon = self.model:logon(clientdata.userid, clientdata.password, conf.clientip, conf.sessiondir, sessiondata)
+ 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"
@@ -54,7 +54,7 @@ logon = function(self)
self.sessiondata.logonredirect = logonredirect
end
end
- redirect(self, cmdresult.value.redir.value)
+ self:redirect(cmdresult.value.redir.value)
end
else
if check_users(self) then return end
@@ -64,15 +64,15 @@ logon = function(self)
end
-- Log off current user and go to logon screen
-logoff = function(self)
- local logoff = self.model.logoff(conf.sessiondir, sessiondata)
+mymodule.logoff = function(self)
+ local logoff = self.model.logoff(self.conf.sessiondir, self.sessiondata)
-- We have to redirect so a new session / menu is created
- redirect(self, "logon")
+ self:redirect("logon")
return logoff
end
-- Report the logon status
-status = function(self)
+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
@@ -80,3 +80,5 @@ status = function(self)
end
return cfe({ type="group", value={username=name, sessionid=sessionid}, label="Logon Status" })
end
+
+return mymodule
diff --git a/app/acf-util/logon-model.lua b/app/acf-util/logon-model.lua
index fd67ec2..279e988 100644
--- a/app/acf-util/logon-model.lua
+++ b/app/acf-util/logon-model.lua
@@ -1,6 +1,6 @@
-- Logon / Logoff model functions
-module (..., package.seeall)
+local mymodule = {}
session = require ("session")
html = require ("acf.html")
@@ -9,7 +9,7 @@ roles = require ("roles")
authenticator = require ("authenticator")
-- Logoff the user by deleting session data
-logoff = function (sessiondir, sessiondata)
+mymodule.logoff = function (sessiondir, sessiondata)
-- Unlink / delete the current session
local result = session.unlink_session(sessiondir, sessiondata.id)
local success = (result ~= nil)
@@ -23,7 +23,7 @@ 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)
-logon = function (self, userid, password, ip_addr, sessiondir, sessiondata)
+mymodule.logon = function (self, userid, password, ip_addr, sessiondir, sessiondata)
-- 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)
if countevent then
@@ -34,7 +34,7 @@ logon = function (self, userid, password, ip_addr, sessiondir, sessiondata)
if authenticator.authenticate (self, userid, password) then
-- We have a successful logon, change sessiondata
-- for some reason, can't call this function or it skips rest of logon
- -- logoff(sessiondir, sessiondata)
+ -- mymodule.logoff(sessiondir, sessiondata)
---[[ so, do this instead
session.unlink_session(sessiondir, sessiondata.id)
-- Clear the current session data
@@ -57,6 +57,8 @@ logon = function (self, userid, password, ip_addr, sessiondir, sessiondata)
return cfe({ type="boolean", value=false, label="Logon Success" })
end
-list_users = function(self)
+mymodule.list_users = function(self)
return cfe({ type="list", value=authenticator.list_users(self), label="Users" })
end
+
+return mymodule
diff --git a/app/acf-util/password-controller.lua b/app/acf-util/password-controller.lua
index 40ba61b..0715b50 100644
--- a/app/acf-util/password-controller.lua
+++ b/app/acf-util/password-controller.lua
@@ -1,13 +1,13 @@
-module(..., package.seeall)
+local mymodule = {}
roles = require("roles")
-default_action = "editme"
+mymodule.default_action = "editme"
-function status(self)
+function mymodule.status(self)
return self.model.get_users(self)
end
-function editme(self)
+function mymodule.editme(self)
-- just to make sure can't modify any other user from this action
self.clientdata.userid = self.sessiondata.userinfo.userid
return self.handle_form(self, function()
@@ -42,7 +42,7 @@ function editme(self)
end, self.clientdata, "Save", "Edit My Settings", "Saved user")
end
-function edituser(self)
+function mymodule.edituser(self)
return self.handle_form(self, function()
return self.model.read_user(self, self.clientdata.userid)
end, function(self, value)
@@ -63,10 +63,12 @@ function edituser(self)
end, self.clientdata, "Save", "Edit User Settings", "Saved user")
end
-function newuser(self)
+function mymodule.newuser(self)
return self.handle_form(self, function() return self.model.read_user(self) end, self.model.create_user, self.clientdata, "Create", "Create New User", "Created user")
end
-function deleteuser(self)
+function mymodule.deleteuser(self)
return self.handle_form(self, self.model.get_delete_user, self.model.delete_user, self.clientdata, "Delete", "Delete User", "Deleted user")
end
+
+return mymodule
diff --git a/app/acf-util/password-model.lua b/app/acf-util/password-model.lua
index a329c19..3a61983 100644
--- a/app/acf-util/password-model.lua
+++ b/app/acf-util/password-model.lua
@@ -1,4 +1,4 @@
-module(..., package.seeall)
+local mymodule = {}
authenticator = require("authenticator")
roles = require("roles")
@@ -48,11 +48,11 @@ local validate_settings = function(settings)
return true, settings
end
-function create_user(self, settings)
- return update_user(self, settings, true)
+function mymodule.create_user(self, settings)
+ return mymodule.update_user(self, settings, true)
end
-function update_user(self, settings, create)
+function mymodule.update_user(self, settings, create)
local success, settings = validate_settings(settings)
if success then
@@ -86,7 +86,7 @@ function update_user(self, settings, create)
end
-function read_user(self, user)
+function mymodule.read_user(self, user)
local result = {}
result.userid = cfe({ value=user, label="User id", seq=1 })
if user and user ~= "" then
@@ -151,28 +151,30 @@ function read_user(self, user)
return cfe({ type="group", value=result, label="User Config" })
end
-function get_users(self)
+function mymodule.get_users(self)
--List all users and their userinfo
local users = {}
local userlist = authenticator.list_users(self)
table.sort(userlist)
for x,user in pairs(userlist) do
- users[#users+1] = read_user(self, user)
+ users[#users+1] = mymodule.read_user(self, user)
end
return cfe({ type="group", value=users, label="User Configs" })
end
-function get_delete_user(self, clientdata)
+function mymodule.get_delete_user(self, clientdata)
local userid = cfe({ label="User id", value=clientdata.userid or "" })
return cfe({ type="group", value={userid=userid}, label="Delete User" })
end
-function delete_user(self, deleteuser)
+function mymodule.delete_user(self, deleteuser)
deleteuser.errtxt = "Failed to delete user"
if authenticator.delete_user(self, deleteuser.value.userid.value) then
deleteuser.errtxt = nil
end
return deleteuser
end
+
+return mymodule
diff --git a/app/acf-util/roles-controller.lua b/app/acf-util/roles-controller.lua
index c02d693..30cf768 100644
--- a/app/acf-util/roles-controller.lua
+++ b/app/acf-util/roles-controller.lua
@@ -1,11 +1,10 @@
-- Roles/Group functions
-module (..., package.seeall)
+local mymodule = {}
-
-default_action = "read"
+mymodule.default_action = "read"
-- Return your own roles/permissions
-read = function(self)
+mymodule.read = function(self)
userid = cfe({ value=self.sessiondata.userinfo.userid, label="User Id" })
roles = cfe({ type="list", value=self.sessiondata.userinfo.roles, label="Roles" })
permissions = cfe({ type="table", value = self.sessiondata.permissions, label="Permissions" })
@@ -13,7 +12,7 @@ read = function(self)
end
-- Return roles/permissions for specified user
-viewuserroles = function(self)
+mymodule.viewuserroles = function(self)
if not (self.clientdata.userid) then
redirect(self)
end
@@ -24,7 +23,7 @@ viewuserroles = function(self)
end
-- Return permissions for specified role
-viewroleperms = function(self)
+mymodule.viewroleperms = function(self)
if not (self.clientdata.role) then
redirect(self, "getlist")
end
@@ -34,22 +33,24 @@ viewroleperms = function(self)
end
-- Return list of all permissions
-getpermslist = function(self)
+mymodule.getpermslist = function(self)
return cfe({ type="group", value={permissions=self.model.get_perms_list(self)} })
end
-viewroles = function(self)
+mymodule.viewroles = function(self)
return self.model.view_roles(self)
end
-newrole = function(self)
+mymodule.newrole = function(self)
return self.handle_form(self, self.model.getpermissions, self.model.setnewpermissions, self.clientdata, "Create", "Create New Role", "New Role Created")
end
-editrole = function(self)
+mymodule.editrole = function(self)
return self.handle_form(self, self.model.getpermissions, self.model.setpermissions, self.clientdata, "Save", "Edit Role", "Role Saved")
end
-deleterole = function(self)
+mymodule.deleterole = function(self)
return self.handle_form(self, self.model.get_delete_role, self.model.delete_role, self.clientdata, "Delete", "Delete Role", "Role Deleted")
end
+
+return mymodule
diff --git a/app/acf-util/roles-model.lua b/app/acf-util/roles-model.lua
index 4d5d1d3..51c10b1 100644
--- a/app/acf-util/roles-model.lua
+++ b/app/acf-util/roles-model.lua
@@ -1,12 +1,12 @@
-- Roles/Group functions
-module (..., package.seeall)
+local mymodule = {}
modelfunctions = require("modelfunctions")
authenticator = require("authenticator")
roles = require("roles")
-- Return roles/permissions for specified user
-get_user_roles = function(self, userid)
+mymodule.get_user_roles = function(self, userid)
local userinfo = authenticator.get_userinfo(self, userid) or {}
rls = cfe({ type="list", value=userinfo.roles or {}, label="Roles" })
permissions = cfe({ type="table", value=roles.get_roles_perm(self, rls.value), label="Permissions" })
@@ -14,16 +14,16 @@ get_user_roles = function(self, userid)
end
-- Return permissions for specified role
-get_role_perms = function(self, role)
+mymodule.get_role_perms = function(self, role)
return cfe({ type="table", value=roles.get_role_perm(self, role), label="Permissions" })
end
-- Return list of all permissions
-get_perms_list = function(self)
+mymodule.get_perms_list = function(self)
return cfe({ type="table", value=roles.get_all_permissions(self), label="All Permissions" })
end
-view_roles = function(self)
+mymodule.view_roles = function(self)
local defined_roles, default_roles = roles.list_roles(self)
local defined_roles_cfe=cfe({ type="list", value=defined_roles, label="Locally-defined roles" })
local default_roles_cfe=cfe({ type="list", value=default_roles, label="System-defined roles" })
@@ -31,7 +31,7 @@ view_roles = function(self)
return cfe({ type="group", value={defined_roles=defined_roles_cfe, default_roles=default_roles_cfe} })
end
-getpermissions = function(self, clientdata)
+mymodule.getpermissions = function(self, clientdata)
local role_cfe = cfe({ value=clientdata.role or "", label="Role", seq=1 })
local tmp, all_perms = roles.get_all_permissions(self)
@@ -68,11 +68,11 @@ getpermissions = function(self, clientdata)
return cfe({ type="table", value={role=role_cfe, permissions=permissions_cfe} })
end
-setnewpermissions = function(self, permissions, action)
- return setpermissions(self, permissions, action, true)
+mymodule.setnewpermissions = function(self, permissions, action)
+ return mymodule.setpermissions(self, permissions, action, true)
end
-setpermissions = function(self, permissions, action, newrole)
+mymodule.setpermissions = function(self, permissions, action, newrole)
-- Validate entries and create error strings
local result = true
if newrole then
@@ -98,13 +98,13 @@ setpermissions = function(self, permissions, action, newrole)
return permissions
end
-get_delete_role = function(self, clientdata)
+mymodule.get_delete_role = function(self, clientdata)
local defined_roles, default_roles = roles.list_roles(self)
local role = cfe({ type="select", value = clientdata.role or "", label="Role", option=defined_roles })
return cfe({ type="group", value={role=role}, label="Delete Role" })
end
-delete_role = function(self, role)
+mymodule.delete_role = function(self, role)
local result, cmdresult = roles.delete_role(self, role.value.role.value)
if not result then
role.value.role.errtxt = cmdresult
@@ -121,3 +121,5 @@ delete_role = function(self, role)
end
return role
end
+
+return mymodule
diff --git a/app/acf-util/skins-controller.lua b/app/acf-util/skins-controller.lua
index c3d08a0..e6f8fc3 100644
--- a/app/acf-util/skins-controller.lua
+++ b/app/acf-util/skins-controller.lua
@@ -1,14 +1,15 @@
-module (..., package.seeall)
+local mymodule = {}
-- Public methods
-default_action = "read"
+mymodule.default_action = "read"
-read = function (self )
+mymodule.read = function (self )
return self.model.get(self)
end
-update = function (self )
+mymodule.update = function (self )
return self.handle_form(self, self.model.get_update, self.model.update, self.clientdata, "Update", "Update Skin", "Skin updated")
end
+return mymodule
diff --git a/app/acf-util/skins-model.lua b/app/acf-util/skins-model.lua
index e646af9..9016e62 100644
--- a/app/acf-util/skins-model.lua
+++ b/app/acf-util/skins-model.lua
@@ -1,4 +1,4 @@
-module (..., package.seeall)
+local mymodule = {}
modelfunctions = require("modelfunctions")
fs = require("acf.fs")
@@ -31,11 +31,11 @@ local function list_skins(self)
end
-get = function (self)
+mymodule.get = function (self)
return cfe({ type="list", value=list_skins(self), label="Skins" })
end
-get_update = function (self)
+mymodule.get_update = function (self)
local skin = cfe({ type="select", value="", label="Skin", option=list_skins(self) })
if self and self.conf and self.conf.skin then
skin.value = self.conf.skin
@@ -43,7 +43,7 @@ get_update = function (self)
return cfe({ type="group", value={skin=skin}, label="Update Skin" })
end
-update = function (self, newskin)
+mymodule.update = function (self, newskin)
local success = modelfunctions.validateselect(newskin.value.skin)
if success then
set_skins(self, newskin.value.skin.value)
@@ -53,3 +53,5 @@ update = function (self, newskin)
end
return newskin
end
+
+return mymodule
diff --git a/app/acf-util/welcome-controller.lua b/app/acf-util/welcome-controller.lua
index 77735ec..b35266c 100644
--- a/app/acf-util/welcome-controller.lua
+++ b/app/acf-util/welcome-controller.lua
@@ -1,10 +1,10 @@
-- A standin controller for testing
-module (..., package.seeall)
+local mymodule = {}
-default_action = "read"
+mymodule.default_action = "read"
-read = function (self )
+mymodule.read = function (self )
return ( {self = self} )
end
-
+return mymodule