summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTed Trask <ttrask01@yahoo.com>2008-05-15 20:15:32 +0000
committerTed Trask <ttrask01@yahoo.com>2008-05-15 20:15:32 +0000
commit846a69204d0d2e54638f8e08a3052b2316827cab (patch)
treef1e567623b6be1e62f91ba1cfe9383308790bcc9
parentc1c2252c53ffcb14b98443f8ee2c6da40551f160 (diff)
downloadacf-core-846a69204d0d2e54638f8e08a3052b2316827cab.tar.bz2
acf-core-846a69204d0d2e54638f8e08a3052b2316827cab.tar.xz
For cfe.type='form', use cfe.option as the command to save the form data i.e. can be used as button name. Modified pages that use 'form' to also use 'option'.
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1122 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--app/acf-util/logon-controller.lua4
-rw-r--r--app/acf-util/logon-html.lsp2
-rwxr-xr-xapp/acf-util/password-controller.lua69
-rwxr-xr-xapp/acf-util/password-html.lsp2
-rwxr-xr-xapp/acf-util/password-model.lua95
-rw-r--r--app/acf-util/roles-controller.lua46
-rw-r--r--app/acf-util/roles-editrole-html.lsp3
-rw-r--r--app/acf-util/roles-model.lua56
-rw-r--r--lib/viewfunctions.lua6
9 files changed, 169 insertions, 114 deletions
diff --git a/app/acf-util/logon-controller.lua b/app/acf-util/logon-controller.lua
index 2a55c7a..b83da37 100644
--- a/app/acf-util/logon-controller.lua
+++ b/app/acf-util/logon-controller.lua
@@ -8,8 +8,8 @@ default_action = "status"
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 cmdresult = cfe({ type="form", value={userid=userid, password=password}, label="Logon", option="Logon" })
+ if clientdata.Logon 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
diff --git a/app/acf-util/logon-html.lsp b/app/acf-util/logon-html.lsp
index c4d4bd3..22deb4d 100644
--- a/app/acf-util/logon-html.lsp
+++ b/app/acf-util/logon-html.lsp
@@ -6,8 +6,6 @@
<h1><?= form.label ?></h1>
<?
- form.action = "logon"
- form.submit = "Logon"
form.value.password.type = "password"
local order = { "userid", "password" }
displayform(form, order)
diff --git a/app/acf-util/password-controller.lua b/app/acf-util/password-controller.lua
index 809e766..4493e4a 100755
--- a/app/acf-util/password-controller.lua
+++ b/app/acf-util/password-controller.lua
@@ -7,50 +7,75 @@ function status(self)
end
function editme(self)
- -- just to make sure can't modify any other user from this action
- self.clientdata.userid = sessiondata.userinfo.userid
- self.clientdata.roles = nil
- -- if password is blank, don't update it or require it
- if self.clientdata.password == "" then self.clientdata.password = nil end
- if self.clientdata.password_confirm == "" then self.clientdata.password_confirm = nil end
+ local output
+ if clientdata.Save then
+ -- just to make sure can't modify any other user from this action
+ self.clientdata.userid = self.sessiondata.userinfo.userid
+ self.clientdata.roles = nil
+ -- if password is blank, don't update it or require it
+ if self.clientdata.password == "" then self.clientdata.password = nil end
+ if self.clientdata.password_confirm == "" then self.clientdata.password_confirm = nil end
- -- Update userinfo
- local output = self.model.update_user(self, self.clientdata, false)
+ -- Update userinfo
+ output = self.model.update_user(self, self.clientdata)
+
+ if not output.errtxt then
+ output.descr = "Saved user"
+ end
+ else
+ output = self.model.read_user(self, self.sessiondata.userinfo.userid)
+ end
-- Don't allow changing of roles for yourself
output.value.roles = nil
+ output.type = "form"
output.label = "Edit My Settings"
+ output.option = "Save"
return output
end
function edituser(self)
- -- if password is blank, don't update it or require it
- if self.clientdata.password == "" then self.clientdata.password = nil end
- if self.clientdata.password_confirm == "" then self.clientdata.password_confirm = nil end
+ local output
+ if self.clientdata.Save then
+ -- if password is blank, don't update it or require it
+ if self.clientdata.password == "" then self.clientdata.password = nil end
+ if self.clientdata.password_confirm == "" then self.clientdata.password_confirm = nil end
- -- Update userinfo
- local output = self.model.update_user(self, self.clientdata, false)
+ -- Update userinfo
+ output = self.model.update_user(self, self.clientdata)
- -- result
- if output.descr and output.errtxt == nil then
- redirect(self, "status")
+ -- result
+ if not output.errtxt then
+ redirect(self, "status")
+ end
+ else
+ output = self.model.read_user(self, self.clientdata.userid)
end
+ output.type = "form"
output.label = "Edit User Settings"
+ output.option = "Save"
return output
end
function newuser(self)
- -- Update userinfo
- local output = self.model.update_user(self, self.clientdata, true)
-
- -- result
- if output.descr and output.errtxt == nil then
- redirect(self, "status")
+ local output
+ if self.clientdata.Save then
+ -- Update userinfo
+ output = self.model.create_user(self, self.clientdata)
+
+ -- result
+ if not output.errtxt then
+ redirect(self, "status")
+ end
+ else
+ output = self.model.read_user(self)
end
+ output.type = "form"
output.label = "New User Settings"
+ output.option = "Save"
return output
end
diff --git a/app/acf-util/password-html.lsp b/app/acf-util/password-html.lsp
index 8b6d563..5f081c3 100755
--- a/app/acf-util/password-html.lsp
+++ b/app/acf-util/password-html.lsp
@@ -11,8 +11,6 @@ io.write("</span>")
<H1><?= form.label ?></H1>
<?
- form.action = ""
- form.submit = "Save"
if form.value.password and form.value.password_confirm then
form.value.password.type = "password"
form.value.password_confirm.type = "password"
diff --git a/app/acf-util/password-model.lua b/app/acf-util/password-model.lua
index e3d58f1..12e29b0 100755
--- a/app/acf-util/password-model.lua
+++ b/app/acf-util/password-model.lua
@@ -2,68 +2,89 @@ module(..., package.seeall)
local auth=require("authenticator-plaintext")
-function update_user(self, clientdata, newuser)
+function create_user(self, clientdata)
+ return update_user(self, clientdata, true)
+end
+
+function read_user(self, user)
local config = {}
local errtxt
- local descr
- local errormessage = {}
- -- Try to write new or update existing data
- -- if clientdata.username exists, then pretty sure trying to write
- if newuser == true then
- if clientdata.username then
- result, errormessage = auth.new_settings(self, clientdata.userid, clientdata.username, clientdata.password, clientdata.password_confirm, clientdata.roles)
- if result == true then
- descr = "Created new user"
- else
- errtxt = "Failed to create new user"
- end
- end
- else
- result, errormessage = auth.change_settings(self, clientdata.userid, clientdata.username, clientdata.password, clientdata.password_confirm, clientdata.roles)
- if result == true and clientdata.username then
- descr = "Saved changes"
- elseif result == false and clientdata.username then
- errtxt = "Failed to save changes"
- elseif result == false then
- errtxt = "Bad user id"
- end
- end
-
- -- Now, read the updated / existing data
+ -- Read the user data
local userinfo
- if ( errtxt == nil ) and clientdata.userid and (#clientdata.userid > 0) then
- userinfo = auth.get_userinfo(self,clientdata.userid)
+ if user and (#user > 0) then
+ userinfo = auth.get_userinfo(self,user)
+ if not userinfo then
+ errtxt = "User does not exist"
+ end
end
userinfo = userinfo or {}
config.userid = cfe({
label="User id",
- value=(userinfo.userid or clientdata.userid or ""),
- errtxt = errormessage.userid
+ value=(userinfo.userid or user or ""),
+ errtxt = errtxt
})
config.username = cfe({
label="Real name",
- value=(userinfo.username or clientdata.username or ""),
- errtxt = errormessage.username
+ value=(userinfo.username or ""),
})
config.roles = cfe({
label="Roles",
- value=(userinfo.roles or clientdata.roles or {}),
+ value=(userinfo.roles or {}),
type="multi",
option=auth.list_roles(),
- errtxt = errormessage.roles
})
config.password = cfe({
label="Password",
- errtxt = errormessage.password
})
config.password_confirm = cfe({
label="Password (confirm)",
- errtxt = errormessage.password_confirm
})
- return cfe({ type="form", value=config, errtxt = errtxt, descr = descr, label="User Config" })
+ return cfe({ type="group", value=config, errtxt = errtxt, label="User Config" })
+end
+
+function update_user(self, clientdata, newuser)
+ local config
+ local result
+ local errtxt
+ local errormessage = {}
+
+ -- Try to write new or update existing data
+ if newuser == true then
+ result, errormessage = auth.new_settings(self, clientdata.userid, clientdata.username, clientdata.password, clientdata.password_confirm, clientdata.roles)
+ if result == false then
+ errtxt = "Failed to create new user"
+ end
+ else
+ result, errormessage = auth.change_settings(self, clientdata.userid, clientdata.username, clientdata.password, clientdata.password_confirm, clientdata.roles)
+ if result == false then
+ errtxt = "Failed to save changes"
+ end
+ end
+
+ if result == true then
+ config = read_user(self, clientdata.userid)
+ else
+ -- get a blank table
+ config = read_user(self)
+
+ -- now, copy in the user info and errors
+ config.value.userid.value = clientdata.userid or ""
+ config.value.userid.errtxt = errormessage.userid
+ config.value.username.value = clientdata.username or config.value.username.value
+ config.value.username.errtxt = errormessage.username
+ config.value.roles.value = clientdata.roles or config.value.roles.value
+ config.value.roles.errtxt = errormessage.roles
+ --config.value.password.value = clientdata.password or config.value.password.value
+ config.value.password.errtxt = errormessage.password
+ --config.value.password_confirm.value = clientdata.password_confirm or config.value.password_confirm.value
+ config.value.password_confirm.errtxt = errormessage.password_confirm
+ config.errtxt = errtxt
+ end
+
+ return config
end
function get_users(self)
diff --git a/app/acf-util/roles-controller.lua b/app/acf-util/roles-controller.lua
index aa3e6bd..4c27e9d 100644
--- a/app/acf-util/roles-controller.lua
+++ b/app/acf-util/roles-controller.lua
@@ -50,32 +50,42 @@ viewroles = function(self)
end
newrole = function(self)
- local form = self.model.setpermissions(self, self.clientdata.role, self.clientdata.permissions, true)
+ local form
+ if self.clientdata.Save then
+ form = self.model.setpermissions(self, self.clientdata.role, self.clientdata.permissions, true)
+ if form.value.role.errtxt then
+ form.errtxt = "Failed to create role"
+ else
+ local cmdresult = cfe({ value="New role created", label="New role result" })
+ self.sessiondata.cmdresult = cmdresult
+ redirect(self, "viewroles")
+ end
+ else
+ form = self.model.getpermissions(self)
+ end
form.type = "form"
form.label = "Edit new role"
- if form.value.role.errtxt then
- form.errtxt = "Failed to create role"
- elseif self.clientdata.permissions then
- -- If we have permissions, we tried to set
- local cmdresult = cfe({ value="New role created" })
- self.sessiondata.cmdresult = cmdresult
- redirect(self, "viewroles")
- end
+ form.option = "Save"
return form
end
editrole = function(self)
- local form = self.model.setpermissions(self, self.clientdata.role, self.clientdata.permissions, false)
+ local form
+ if self.clientdata.Save then
+ form = self.model.setpermissions(self, self.clientdata.role, self.clientdata.permissions, false)
+ if form.value.role.errtxt then
+ form.errtxt = "Failed to save role"
+ else
+ local cmdresult = cfe({ value="Role saved", label="Edit role result" })
+ self.sessiondata.cmdresult = cmdresult
+ redirect(self, "viewroles")
+ end
+ else
+ form = self.model.getpermissions(self, self.clientdata.role)
+ end
form.type = "form"
form.label = "Edit role"
- if form.value.role.errtxt then
- form.errtxt = "Failed to save role"
- elseif self.clientdata.permissions then
- -- If we have permissions, we tried to set
- local cmdresult = cfe({ value="Role saved" })
- self.sessiondata.cmdresult = cmdresult
- redirect(self, "viewroles")
- end
+ form.option = "Save"
return form
end
diff --git a/app/acf-util/roles-editrole-html.lsp b/app/acf-util/roles-editrole-html.lsp
index 2094b54..a1bfc7a 100644
--- a/app/acf-util/roles-editrole-html.lsp
+++ b/app/acf-util/roles-editrole-html.lsp
@@ -1,15 +1,12 @@
<? local form, viewtable, pageinfo = ... ?>
<? --[[
io.write(html.cfe_unpack(form))
- io.write(html.cfe_unpack(FORM))
--]] ?>
<? ---[[ ?>
<H1><?= form.label ?></H1>
<?
require("viewfunctions")
- form.action = ""
- form.submit = "Save"
-- If editing existing role, disable role
if pageinfo.action ~= "newrole" then
form.value.role.contenteditable = false
diff --git a/app/acf-util/roles-model.lua b/app/acf-util/roles-model.lua
index 4fe3cbf..d02f390 100644
--- a/app/acf-util/roles-model.lua
+++ b/app/acf-util/roles-model.lua
@@ -48,43 +48,49 @@ view_roles = function()
return cfe({ type="group", value={defined_roles=defined_roles_cfe, default_roles=default_roles_cfe} })
end
-setpermissions = function(self, role, permissions, newrole)
- local errtxt
+getpermissions = function(self, role)
local my_perms = {}
- if permissions then
- -- we're changing permissions
- local result = true
- if newrole then
- -- make sure not overwriting role
- for x,ro in ipairs(roles.list_roles()) do
- if role==ro then
- result = false
- errtxt = "Role already exists"
- break
- end
- end
- end
- if result==true then
- result, errtxt = roles.set_role_perm(role, nil, permissions)
- end
- my_perms = self.clientdata.permissions
+
+ if role then
+ tmp, my_perms = roles.get_role_perm(self.conf.appdir, role)
+ my_perms = my_perms or {}
else
- if role then
- tmp, my_perms = roles.get_role_perm(self.conf.appdir, role)
- else
- role = ""
- end
+ role = ""
end
local tmp, all_perms = get_all_permissions(self)
table.sort(all_perms)
local permissions_cfe = cfe({ type="multi", value=my_perms, option=all_perms, label="Role permissions" })
- local role_cfe = cfe({ value=role, label="Role", errtxt=errtxt })
+ local role_cfe = cfe({ value=role, label="Role" })
return cfe({ type="table", value={role=role_cfe, permissions=permissions_cfe} })
end
+setpermissions = function(self, role, permissions, newrole)
+ local my_perms = getpermissions(self, role)
+ my_perms.value.permissions.value = permissions
+
+ -- Validate entries and create error strings
+ local result = true
+ if newrole then
+ -- make sure not overwriting role
+ for x,ro in ipairs(roles.list_roles()) do
+ if role==ro then
+ result = false
+ my_perms.value.role.errtxt = "Role already exists"
+ break
+ end
+ end
+ end
+ -- Try to set the value
+ if result==true then
+ result, my_perms.value.role.errtxt = roles.set_role_perm(role, nil, permissions)
+ end
+
+ return my_perms
+end
+
delete_role = function(role)
local result, cmdresult = roles.delete_role(role)
return cfe({ value=cmdresult })
diff --git a/lib/viewfunctions.lua b/lib/viewfunctions.lua
index bb6e6ec..801e7e4 100644
--- a/lib/viewfunctions.lua
+++ b/lib/viewfunctions.lua
@@ -108,7 +108,7 @@ function displayformitem(myitem, name, viewtype)
--myitem.type = "select"
--myitem.multiple = "true"
local tempname = myitem.name
- local tempval = myitem.value
+ local tempval = myitem.value or {}
local reverseval = {}
for x,val in ipairs(tempval) do
reverseval[val] = x
@@ -137,7 +137,7 @@ function displayform(myform, order)
if not myform then return end
if myform.descr then io.write("<P CLASS='descr'>" .. string.gsub(myform.descr, "\n", "<BR>") .. "</P>\n") end
if myform.errtxt then io.write("<P CLASS='error'>" .. string.gsub(myform.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write('<form action="' .. myform.action .. '" method="POST">\n')
+ io.write('<form action="' .. (myform.action or "") .. '" method="POST">\n')
io.write('<DL>\n')
local reverseorder= {}
if order then
@@ -155,7 +155,7 @@ function displayform(myform, order)
displayformitem(item)
end
end
- io.write('<DT><input class="submit" type="submit" name="save" value="' .. myform.submit .. '"></DT>\n')
+ io.write('<DT><input class="submit" type="submit" name="' .. myform.option .. '" value="' .. (myform.submit or myform.option) .. '"></DT>\n')
io.write('</DL>\n')
io.write('</FORM>')
end