liquid_feedback_frontend
view app/main/index/_action/register.lua @ 111:bf885faf3452
add initiator support in delegation
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
if a delegation is issued from the initiative view, the initiators
from that one are added to the delegation target list. this makes it easier to delegate to the author without the need to add him to the contact list.
| author | Daniel Poelzleithner <poelzi@poelzi.org> |
|---|---|
| date | Mon Sep 20 20:32:04 2010 +0200 (2010-09-20) |
| parents | 3da86120cadd |
| children | 217653875fbb 9345ea6af3b2 |
line source
1 local code = param.get("code")
3 local invite_code = InviteCode:new_selector()
4 :add_where{ "code = ?", code }
5 :optional_object_mode()
6 :for_update()
7 :exec()
9 if not invite_code or invite_code.used then
10 slot.put_into("error", _"The code you've entered is invalid")
11 request.redirect{
12 mode = "forward",
13 module = "index",
14 view = "register"
15 }
16 return false
17 end
19 local notify_email = param.get("notify_email")
21 if invite_code and not notify_email then
22 request.redirect{
23 mode = "redirect",
24 module = "index",
25 view = "register",
26 params = { code = invite_code.code }
27 }
28 return false
29 end
31 if #notify_email < 5 then
32 slot.put_into("error", _"Email address too short!")
33 request.redirect{
34 mode = "redirect",
35 module = "index",
36 view = "register",
37 params = { code = invite_code.code }
38 }
39 return false
40 end
42 local name = param.get("name")
44 if notify_email and not name then
45 request.redirect{
46 mode = "redirect",
47 module = "index",
48 view = "register",
49 params = {
50 code = invite_code.code,
51 notify_email = notify_email
52 }
53 }
54 return false
55 end
57 name = util.trim(name)
59 if #name < 3 then
60 slot.put_into("error", _"This username is too short!")
61 request.redirect{
62 mode = "redirect",
63 module = "index",
64 view = "register",
65 params = {
66 code = invite_code.code,
67 notify_email = notify_email
68 }
69 }
70 return false
71 end
73 if Member:by_name(name) then
74 slot.put_into("error", _"This name is already taken, please choose another one!")
75 request.redirect{
76 mode = "redirect",
77 module = "index",
78 view = "register",
79 params = {
80 code = invite_code.code,
81 notify_email = notify_email
82 }
83 }
84 return false
85 end
87 local login = param.get("login")
89 if name and not login then
90 request.redirect{
91 mode = "redirect",
92 module = "index",
93 view = "register",
94 params = {
95 code = invite_code.code,
96 notify_email = notify_email,
97 name = name
98 }
99 }
100 return false
101 end
103 login = util.trim(login)
105 if #login < 3 then
106 slot.put_into("error", _"This login is too short!")
107 request.redirect{
108 mode = "redirect",
109 module = "index",
110 view = "register",
111 params = {
112 code = invite_code.code,
113 notify_email = notify_email,
114 name = name
115 }
116 }
117 return false
118 end
120 if Member:by_login(login) then
121 slot.put_into("error", _"This login is already taken, please choose another one!")
122 request.redirect{
123 mode = "redirect",
124 module = "index",
125 view = "register",
126 params = {
127 code = invite_code.code,
128 notify_email = notify_email,
129 name = name
130 }
131 }
132 return false
133 end
135 if login and param.get("step") ~= "5" then
136 request.redirect{
137 mode = "redirect",
138 module = "index",
139 view = "register",
140 params = {
141 code = invite_code.code,
142 notify_email = notify_email,
143 name = name,
144 login = login
145 }
146 }
147 return false
148 end
150 for i, checkbox in ipairs(config.use_terms_checkboxes) do
151 local accepted = param.get("use_terms_checkbox_" .. checkbox.name, atom.boolean)
152 if not accepted then
153 slot.put_into("error", checkbox.not_accepted_error)
154 return false
155 end
156 end
158 local password1 = param.get("password1")
159 local password2 = param.get("password2")
161 if login and not password1 then
162 request.redirect{
163 mode = "redirect",
164 module = "index",
165 view = "register",
166 params = {
167 code = invite_code.code,
168 notify_email = notify_email,
169 name = name,
170 login = login
171 }
172 }
173 --]]
174 return false
175 end
177 if password1 ~= password2 then
178 slot.put_into("error", _"Passwords don't match!")
179 return false
180 end
182 if #password1 < 8 then
183 slot.put_into("error", _"Passwords must consist of at least 8 characters!")
184 return false
185 end
187 local member = Member:new()
189 member.login = login
190 member.name = name
192 local success = member:set_notify_email(notify_email)
193 if not success then
194 slot.put_into("error", _"Can't send confirmation email")
195 return
196 end
198 member:set_password(password1)
199 member:save()
201 local now = db:query("SELECT now() AS now", "object").now
203 for i, checkbox in ipairs(config.use_terms_checkboxes) do
204 local accepted = param.get("use_terms_checkbox_" .. checkbox.name, atom.boolean)
205 member:set_setting("use_terms_checkbox_" .. checkbox.name, "accepted at " .. tostring(now))
206 end
208 invite_code.member_id = member.id
209 invite_code.used = "now"
210 invite_code:save()
212 slot.put_into("notice", _"You've successfully registered and you can login now with your login and password!")
214 request.redirect{
215 mode = "redirect",
216 module = "index",
217 view = "login",
218 }
