1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
module(..., package.seeall)
require("controllerfunctions")
default_action = "editme"
function status(self)
return self.model.get_users(self)
end
function editme(self)
-- 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)
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)
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, "Create", "Create New User", "Created user")
end
function deleteuser(self)
return self:redirect_to_referrer(self.model.delete_user(self, self.clientdata.userid))
end
|