diff options
Diffstat (limited to 'app/acf-util/password-controller.lua')
-rwxr-xr-x | app/acf-util/password-controller.lua | 132 |
1 files changed, 47 insertions, 85 deletions
diff --git a/app/acf-util/password-controller.lua b/app/acf-util/password-controller.lua index 20f04ef..bea4480 100755 --- a/app/acf-util/password-controller.lua +++ b/app/acf-util/password-controller.lua @@ -8,97 +8,59 @@ function status(self) end function editme(self) - local output = self.model.read_user(self, self.sessiondata.userinfo.userid) - - if clientdata.Save then - -- just to make sure can't modify any other user from this action - self.clientdata.userid = self.sessiondata.userinfo.userid - - -- As a special case for update_user, settings that don't change are nil - self.clientdata.roles = nil - output.value.roles.value = nil - -- if password is blank, don't update it or require it - if not self.clientdata.password or self.clientdata.password == "" then - self.clientdata.password = nil - output.value.password.value = nil - end - if not self.clientdata.password_confirm or self.clientdata.password_confirm == "" then - self.clientdata.password_confirm = nil - output.value.password_confirm.value = nil - end - - controllerfunctions.handle_clientdata(output, clientdata) - - -- Update userinfo - output = self.model.update_user(self, output) - if not output.errtxt then - output.descr = "Saved user" - end - output = self:redirect_to_referrer(output) - else - output = self:redirect_to_referrer() or output - 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 + -- just to make sure can't modify any other user from this action + self.clientdata.userid = self.sessiondata.userinfo.userid + return controllerfunctions.handle_form(self, function() + local value = self.model.read_user(self, self.sessiondata.userinfo.userid) + -- We don't allow a user to modify his own roles or dnsfiles + value.value.roles = nil + value.value.dnsfiles = nil + return value + end, function(value) + -- If password and password_confirm are blank, don't set them + local pw, pwc + if value.value.password.value == "" and value.value.password_confirm.value == "" then + pw = value.value.password + pwc = value.value.password_confirm + value.value.password = nil + value.value.password_confirm = nil + end + value = self.model.update_user(self, value) + if pw then + value.value.password = pw + value.value.password_confirm = pwc + end + return value + end, self.clientdata, "Save", "Edit My Settings", "Saved user") end function edituser(self) - local output = self.model.read_user(self, self.clientdata.userid) - if self.clientdata.Save then - -- As a special case for update_user, settings that don't change are nil - -- if password is blank, don't update it or require it - if not self.clientdata.password or self.clientdata.password == "" then - self.clientdata.password = nil - output.value.password.value = nil - end - if not self.clientdata.password_confirm or self.clientdata.password_confirm == "" then - self.clientdata.password_confirm = nil - output.value.password_confirm.value = nil - end - - controllerfunctions.handle_clientdata(output, clientdata) - - -- Update userinfo - output = self.model.update_user(self, output) - if not output.errtxt then - redirect(self, "status") - end - output = self:redirect_to_referrer(output) - else - output = self:redirect_to_referrer() or output - end - - output.type = "form" - output.label = "Edit User Settings" - output.option = "Save" - return output + return controllerfunctions.handle_form(self, function() + return self.model.read_user(self, self.clientdata.userid) + end, function(value) + -- If password and password_confirm are blank, don't set them + local pw, pwc + if value.value.password.value == "" and value.value.password_confirm.value == "" then + pw = value.value.password + pwc = value.value.password_confirm + value.value.password = nil + value.value.password_confirm = nil + end + value = self.model.update_user(self, value) + if pw then + value.value.password = pw + value.value.password_confirm = pwc + end + return value + end, self.clientdata, "Save", "Edit User Settings", "Saved user") end function newuser(self) - local output = self.model.read_user(self) - if self.clientdata.Save then - controllerfunctions.handle_clientdata(output, clientdata) - - -- Update userinfo - output = self.model.create_user(self, output) - if not output.errtxt then - redirect(self, "status") - end - output = self:redirect_to_referrer(output) - else - output = self:redirect_to_referrer() or output - end - - output.type = "form" - output.label = "New User Settings" - output.option = "Save" - return output + return controllerfunctions.handle_form(self, function() + return self.model.read_user(self) + end, function(value) + return self.model.create_user(self, value) + end, self.clientdata, "Save", "New User Settings", "Saved user", "status") end function deleteuser(self) |