summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMika Havela <mika.havela@gmail.com>2008-02-19 16:23:01 +0000
committerMika Havela <mika.havela@gmail.com>2008-02-19 16:23:01 +0000
commit2c343a41e917bf00d1f7e03c27248887c9c56121 (patch)
tree8d33c82e2d7867e1fb9b5a6338524d3c0dd1b3c0
parentf67ad7952b1fc9516c78c10e55db6ee4c2051b53 (diff)
downloadacf-core-2c343a41e917bf00d1f7e03c27248887c9c56121.tar.bz2
acf-core-2c343a41e917bf00d1f7e03c27248887c9c56121.tar.xz
Saving work for today (password manager controller/view)
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@755 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rwxr-xr-xapp/acf-util/password-controller.lua219
-rwxr-xr-xapp/acf-util/password-edit-html.lsp72
-rwxr-xr-xapp/acf-util/password-html.lsp74
-rwxr-xr-xapp/acf-util/password-status-html.lsp14
4 files changed, 292 insertions, 87 deletions
diff --git a/app/acf-util/password-controller.lua b/app/acf-util/password-controller.lua
index c19d6b4..3cbc98a 100755
--- a/app/acf-util/password-controller.lua
+++ b/app/acf-util/password-controller.lua
@@ -1,5 +1,7 @@
module(..., package.seeall)
+auth=require("authenticator-plaintext")
+
local list_redir = function (self)
self.conf.action = "status"
self.conf.type = "redir"
@@ -13,28 +15,158 @@ mvc.on_load = function(self, parent)
end
end
+local function admin_permission()
+ if (sessiondata.userinfo) and (sessiondata.userinfo.userid == "alpine") then
+ return true
+ else
+ return false
+ end
+end
+
+local function config(self,userid)
+ local config = {}
+ local userinfo = {}
+ if (userid) then
+ userinfo=auth.get_userinfo(self,userid)
+ else
+ userinfo.userid = ""
+ userinfo.username = ""
+ userinfo.roles = {}
+
+ end
+ local avail_roles=auth.list_roles()
+
+ config.debug = userid
+
+ config.userid = cfe({
+ name="userid",
+ label="User id",
+ value=(userinfo.userid or ""),
+ })
+ config.orguserid = cfe({
+ name="orguserid",
+ value=(userinfo.userid or ""),
+ type="hidden",
+ })
+
+ config.username = cfe({
+ name="username",
+ label="User name",
+ value=userinfo.username,
+ })
+ config.roles = cfe({
+ name="roles",
+ label="Roles",
+ option=userinfo.roles,
+ type="select",
+ size=#avail_roles,
+ })
+ config.password = cfe({
+ name="password",
+ label="Password",
+ type="passwd",
+ disabled="yes",
+ })
+ config.password_confirm = cfe({
+ name="password_confirm",
+ label="Password (confirm)",
+ type="passwd",
+ disabled="yes",
+ })
+
+ config.availableroles = cfe({
+ name="availableroles",
+ label="Available roles",
+ type="select",
+ option=avail_roles,
+ })
+
+ return config
+end
+
function status(self)
- local status=self.model.getstatus(self)
+ local status = {}
+
+ -- Check for admin persmissions - else redirect to personal options
+ if not (admin_permission()) then
+ self.conf.action = "edit_me"
+ return edit_me(self)
+ end
+
+ -- Redirect when creating a new account
+ if (clientdata.cmdnew) then
+ self.conf.action = "administrator"
+ self.conf.type = "redir"
+
+ return administrator(self)
+ end
+
+ --List all users and their userinfo
+ status.users = {}
+ local userlist = auth.list_users(self)
+ for k,v in pairs(userlist) do
+ local userinfo = auth.get_userinfo(self,v)
+ status.users[k] = cfe({
+ name=v,
+ label=v,
+-- debug=userinfo,
+ value={ userid=cfe ({
+ name="userid",
+ label="User ID",
+ value=userinfo.userid,
+ }),
+ username=cfe ({
+ name="username",
+ label="User name",
+ value=userinfo.username,
+ }),
+ roles=cfe ({
+ name="roles",
+ label="Roles",
+ value=table.concat(userinfo.roles," / "),
+ option=userinfo.roles,
+ type="select",
+ }),
+ },
+
+ })
+ end
+
+ --Create a button for 'New user account'
status.cmdnew = cfe ({
name="cmdnew",
type="submit",
label="Create new account",
value="Create",
- disabled="yes",
+-- disabled="yes",
})
return { status=status }
end
-function edit(self)
- local config=self.model.getsettings(self.clientdata.userid)
- config.cmdsave = cfe ({
+function administrator(self)
+ local output = {}
+
+ -- Check for admin persmissions - else redirect to personal options
+ if not (admin_permission()) then
+ self.conf.action = "edit_me"
+ return edit_me(self)
+ end
+
+ -- Output userinfo
+ output = config(self,self.clientdata.userid)
+
+ --Clear password-field
+ output.password.value = ""
+
+ -- Add some buttons
+ output.cmdsave = cfe ({
name="cmdsave",
type="submit",
label="Save changes",
value="Save",
- disabled="yes",
+-- disabled="yes",
})
- config.cmddelete = cfe ({
+ output.cmddelete = cfe ({
name="cmddelete",
type="submit",
label="Delete this account",
@@ -42,6 +174,77 @@ function edit(self)
disabled="yes",
})
- return { config=config, clientdata=self.clientdata }
+ return {config=output}
end
+function edit_me(self)
+
+ --FIXME: Redirect to Welcome or logon if user is not logged on
+-- if not ( self.sessiondata.userinfo) then
+-- self.conf.action = ""
+-- self.conf.type = "redir"
+-- end
+
+ -- Output userinfo
+ local output = config(self,sessiondata.userinfo.userid)
+
+ --Hide roles/cmddelete for current the user
+ output.roles = nil
+ output.cmddelete = nil
+
+ --Disable userid
+ output.userid.disabled = "yes"
+
+ --Add save-button
+ output.cmdsave = cfe ({
+ name="cmdsave",
+ type="submit",
+ label="Save changes",
+ value="Save",
+ disabled="yes",
+ })
+
+ return {config=output}
+end
+
+function save(self)
+
+ --FIXME: Check if user is allowed to save settings
+
+ -- We start changing things based on input
+ local cmdresult = {}
+ cmdresult.debug = {}
+ if (clientdata.cmdsave) then
+ if (#clientdata.orguserid > 0) then
+ local variables="username userid"
+ cmdresult.debugs = self.clientdata.orguserid
+ for var in string.gmatch(variables, "%S+") do
+ if (self.clientdata[var]) then
+ cmdresult[var],cmdresult.debug[var] = auth.change_settings(
+ self,
+ self.clientdata.orguserid,
+ var, self.clientdata[var]
+ )
+ end
+ end
+ else
+ cmdresult["new"],cmdresult.debug["new"] = auth.new_settings(
+ self,
+ self.clientdata.userid,
+ self.clientdata.username,
+ self.clientdata.password,
+ self.clientdata.password_confirm )
+ end
+ end
+
+ cmdresult.clientdata = self.clientdata
+
+ return cmdresult
+--[[
+ --FIXME: Redirect somewhere when changed settings
+ self.conf.action = "status"
+ self.conf.type = "redir"
+
+ return status(self)
+--]]
+end
diff --git a/app/acf-util/password-edit-html.lsp b/app/acf-util/password-edit-html.lsp
deleted file mode 100755
index 8b295b5..0000000
--- a/app/acf-util/password-edit-html.lsp
+++ /dev/null
@@ -1,72 +0,0 @@
-<? local form = ... ?>
-<?
---[[ DEBUG INFORMATION
-io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
-io.write(html.cfe_unpack(form))
-io.write("</span>")
---]]
-?>
-<?
-function displayinfo(myform,tags,viewonly)
- io.write("\n<DL>")
- for k,v in pairs(tags) do
- if (myform[v]) and (myform[v]["value"]) then
- local val = myform[v]
- io.write("\n\t<DT")
- if (#val.errtxt > 0) then
- val.class = "error"
- io.write(" class='error'")
- end
- io.write(">" .. val.label .. "</DT>\n")
- if (viewonly) then
- io.write("\t\t<DD>" .. val.value .. "\n")
- else
- io.write("\t\t<DD>" .. html.form[val.type](val) .. "\n")
- end
- if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>\n") end
- io.write("\t\t</DD>\n")
- end
- end
- io.write("</DL>")
-end
-?>
-
-<H1>CONFIG</H1>
-<H2>Settings</H2>
-<?
-local myform = form.config
-local tags = { "userid", }
-displayinfo(myform,tags,"viewonly")
-local tags = { "descr", }
-displayinfo(myform,tags)
-?>
-
-<?
--- The following code is a bit special because I want to display checkboxes for available roles.
-local myform = form.config.roles
-io.write("\n<DL>")
-io.write("\n\t<DT")
-if (#myform.errtxt > 0) then
- myform.class = "error"
- io.write(" class='error'")
-end
-io.write(">" .. myform.label .. "</DT>")
-io.write("\n\t\t<DD>")
-for k,v in pairs(myform.option) do
- local checked = ""
- if (form.config.userid.roles[v]) then checked = "checked='yes'" end
- io.write("\n\t\t\t" ..v .. ":<input class='checkbox' type='checkbox' name='roles' value='' " .. checked .. "> ")
-end
-if (#myform.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(myform.errtxt, "\n", "<BR>") .. "</P>\n") end
-io.write("\n\t\t</DD>\n")
-io.write("</DL>")
-?>
-
-<H2>Actions</H2>
-<?
-local myform = form.config
-local tags = { "cmdsave", "cmddelete", }
-displayinfo(myform,tags)
-
-?>
-
diff --git a/app/acf-util/password-html.lsp b/app/acf-util/password-html.lsp
new file mode 100755
index 0000000..861b793
--- /dev/null
+++ b/app/acf-util/password-html.lsp
@@ -0,0 +1,74 @@
+<? local form = ... ?>
+<?
+--[[ DEBUG INFORMATION
+io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
+io.write(html.cfe_unpack(form))
+io.write("</span>")
+--]]
+?>
+<?
+function displayinfo(myform,tags,viewtype)
+ io.write("\n<DL>")
+ for k,v in pairs(tags) do
+ if (myform) and (myform[v]) and (myform[v]["value"]) then
+ local val = myform[v]
+ if (val.type) and not (val.type == "hidden") then
+ io.write("\n\t<DT")
+ if (#val.errtxt > 0) then
+ val.class = "error"
+ io.write(" class='error'")
+ end
+ io.write(">" .. val.label .. "</DT>")
+ io.write("\n\t\t<DD>")
+ if (viewtype == "viewonly") then
+ io.write(val.value)
+ elseif (viewtype == "roles") then
+ for k,v in pairs(form.config.availableroles.option) do
+ local checked = ""
+ for kk,vv in pairs(form.config.roles.option) do
+ if (v == vv) then
+ checked = "checked='yes'"
+ break
+ end
+ end
+ io.write("\n\t\t\t" ..v .. ":<input class='checkbox' type='checkbox' name='roles' value='' " .. checked .. " disabled> ")
+ end
+ else
+ io.write(html.form[val.type](val))
+ end
+ if (#val.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(val.errtxt, "\n", "<BR>") .. "</P>") end
+ io.write("\n\t\t</DD>")
+ else
+ io.write(html.form[val.type](val))
+ end
+ end
+ end
+ io.write("\n</DL>")
+end
+?>
+
+<H1>CONFIG</H1>
+<H2>Settings</H2>
+<form name="settings" action="save" method="POST">
+<?
+local myform = form.config
+displayinfo(myform,{ "userid","orguserid", "username" })
+displayinfo(myform,{ "roles" },"roles")
+displayinfo(myform,{ "password","password_confirm" })
+?>
+
+<H2>Actions</H2>
+<?
+local myform = form.config
+local tags = { "cmdsave", "cmddelete", }
+displayinfo(myform,tags)
+?>
+</form>
+
+<?
+---[[ DEBUG INFORMATION
+io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
+io.write(html.cfe_unpack(form))
+io.write("</span>")
+--]]
+?>
diff --git a/app/acf-util/password-status-html.lsp b/app/acf-util/password-status-html.lsp
index 45bed4f..35e2027 100755
--- a/app/acf-util/password-status-html.lsp
+++ b/app/acf-util/password-status-html.lsp
@@ -35,12 +35,13 @@ end
<H1>USER ACCOUNTS</H1>
<H2>Create new account</H2>
+<form name="createnew" action="" method="POST">
<?
local myform = form.status
local tags = { "cmdnew", }
displayinfo(myform,tags)
?>
-
+</form>
<H2>Existing account</H2>
<?
--function displayinfo(myform,tags,viewonly)
@@ -57,12 +58,11 @@ if (type(myform) == "table") then
end
io.write("><IMG SRC='/static/tango/16x16/apps/system-users.png' HEIGHT='16' WIDTH='16'> " .. myform.label .. "</DT>\n")
io.write("\t\t<DD>\n\t\t<TABLE>")
- io.write("\n\t\t\t<TR>\n\t\t\t\t<TD><B>Account name:</B></TD>\n\t\t\t\t<TD WIDTH='90%'>" .. myform.value .. "</TD>\n\t\t\t</TR>")
- io.write("\n\t\t\t<TR>\n\t\t\t\t<TD><B>Description:</B></TD>\n\t\t\t\t<TD>" .. (myform.descr or "") .. "</TD>\n\t\t\t</TR>")
- io.write("\n\t\t\t<TR>\n\t\t\t\t<TD><B>Roles:</B></TD>\n\t\t\t\t<TD>")
- io.write(tostring(myform.roles))
+ io.write("\n\t\t\t<TR>\n\t\t\t\t<TD><B>".. myform.value.userid.label .."</B></TD>\n\t\t\t\t<TD WIDTH='90%'>" .. myform.value.userid.value .. "</TD>\n\t\t\t</TR>")
+ io.write("\n\t\t\t<TR>\n\t\t\t\t<TD><B>".. myform.value.username.label .."</B></TD>\n\t\t\t\t<TD>" .. myform.value.username.value .. "</TD>\n\t\t\t</TR>")
+ io.write("\n\t\t\t<TR>\n\t\t\t\t<TD><B>".. myform.value.roles.label .."</B></TD>\n\t\t\t\t<TD>" .. myform.value.roles.value .. "</TD>\n\t\t\t</TR>")
io.write("</TD>\n\t\t\t</TR>")
- io.write("\n\t\t\t<TR>\n\t\t\t\t<TD><B>Options:</B></TD>\n\t\t\t\t<TD>[<A HREF='edit?userid=".. myform.value .. "'>Edit this account</A>]</TD>\n\t\t\t</TR>")
+ io.write("\n\t\t\t<TR>\n\t\t\t\t<TD><B>Option</B></TD>\n\t\t\t\t<TD>[<A HREF='administrator?userid=".. myform.value.userid.value .. "'>Edit this account</A>]</TD>\n\t\t\t</TR>")
io.write("\n\t\t</TABLE>\n")
if (#myform.errtxt > 0) then io.write("\t\t<P CLASS='error'>" .. string.gsub(myform.errtxt, "\n", "<BR>") .. "</P>\n") end
io.write("\t\t</DD>\n")
@@ -73,7 +73,7 @@ io.write("</DL>")
<?
---[[ DEBUG INFORMATION
+---[[ DEBUG INFORMATION
io.write("<H1>DEBUGGING</H1><span style='color:red'><H2>DEBUG INFO: CFE</H2>")
io.write(html.cfe_unpack(form))
io.write("</span>")