diff options
author | Ted Trask <ttrask01@yahoo.com> | 2008-04-30 20:37:09 +0000 |
---|---|---|
committer | Ted Trask <ttrask01@yahoo.com> | 2008-04-30 20:37:09 +0000 |
commit | 21b0abee37316cd578a984c3de0ec878a8b41f72 (patch) | |
tree | 0600824b78cb7d1a1acf98fc929216874b5c83a9 /app/acf-util/password-model.lua | |
parent | 378e53f20a0f11c36afffbaef78f47a5303df9ce (diff) | |
download | acf-core-21b0abee37316cd578a984c3de0ec878a8b41f72.tar.bz2 acf-core-21b0abee37316cd578a984c3de0ec878a8b41f72.tar.xz |
Forgot the password model file
git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@1053 ab2d0c66-481e-0410-8bed-d214d4d58bed
Diffstat (limited to 'app/acf-util/password-model.lua')
-rwxr-xr-x | app/acf-util/password-model.lua | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/app/acf-util/password-model.lua b/app/acf-util/password-model.lua new file mode 100755 index 0000000..553abca --- /dev/null +++ b/app/acf-util/password-model.lua @@ -0,0 +1,105 @@ +module(..., package.seeall) + +local auth=require("authenticator-plaintext") + +function update_user(self, clientdata, newuser) + 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 + local userinfo + if ( errtxt == nil ) and clientdata.userid and (#clientdata.userid > 0) then + userinfo = auth.get_userinfo(self,clientdata.userid) + end + userinfo = userinfo or {} + + -- Get list of available roles + local avail_roles=auth.list_roles() + + config.userid = cfe({ + label="User id", + value=(userinfo.userid or clientdata.userid or ""), + errtxt = errormessage.userid + }) + config.username = cfe({ + label="Real name", + value=(userinfo.username or clientdata.username or ""), + errtxt = errormessage.username + }) + config.roles = cfe({ + label="Roles", + value=(userinfo.roles or clientdata.roles or {}), + type="multi", + option=avail_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" }) +end + +function get_users(self) + --List all users and their userinfo + local users = {} + local userlist = auth.list_users(self) + for x,user in pairs(userlist) do + local userinfo = auth.get_userinfo(self,user) + users[user] = cfe({ + type="group", + label=user, + value={ userid=cfe ({ + label="User ID", + value=userinfo.userid, + }), + username=cfe ({ + label="Real name", + value=userinfo.username, + }), + roles=cfe ({ + label="Roles", + value=userinfo.roles, + option=auth.list_roles(), + type="multi", + }), + }, + + }) + end + + return cfe({ type="group", value=users, label="User Configs" }) +end + +function delete_user(self, userid) + auth.delete_user(self, userid) +end |