| rev |
line source |
|
bsw/jbe@1309
|
1 local function check_italian_mobile_phone_number(value)
|
|
bsw/jbe@1309
|
2
|
|
bsw/jbe@1309
|
3 if not value then
|
|
bsw/jbe@1309
|
4 return false
|
|
bsw/jbe@1309
|
5 end
|
|
bsw/jbe@1309
|
6
|
|
bsw/jbe@1309
|
7 value = string.gsub(value, "[^0-9]*", "")
|
|
bsw/jbe@1309
|
8
|
|
bsw/jbe@1309
|
9 if #(value) < 9 or #(value) > 10 then
|
|
bsw/jbe@1309
|
10 return false
|
|
bsw/jbe@1309
|
11 end
|
|
bsw/jbe@1309
|
12
|
|
bsw/jbe@1309
|
13 local mobile_phone_prefixes = {
|
|
bsw/jbe@1309
|
14 { min = 320, max = 329, comment = "Wind Tre" },
|
|
bsw/jbe@1309
|
15 { min = 330, max = 339, comment = "Telecom Italia (TIM)" },
|
|
bsw/jbe@1309
|
16 { min = 340, max = 349, comment = "Vodafone Omnitel" },
|
|
bsw/jbe@1309
|
17 { min = 350, max = 359, comment = "" },
|
|
bsw/jbe@1309
|
18 { min = 360, max = 369, comment = "Telecom Italia (TIM)" },
|
|
bsw/jbe@1309
|
19 { min = 370, max = 379, comment = "" },
|
|
bsw/jbe@1309
|
20 { min = 380, max = 389, comment = "Wind Tre" },
|
|
bsw/jbe@1309
|
21 { min = 390, max = 393, comment = "Wind Tre" },
|
|
bsw/jbe@1309
|
22 { min = 394, max = 399, comment = "Wind Tre" }
|
|
bsw/jbe@1309
|
23 }
|
|
bsw/jbe@1309
|
24
|
|
bsw/jbe@1309
|
25 local value_prefix = tonumber(string.match(value, "^(...)"))
|
|
bsw/jbe@1309
|
26
|
|
bsw/jbe@1309
|
27 local valid_prefix = false
|
|
bsw/jbe@1309
|
28
|
|
bsw/jbe@1309
|
29 for i, prefix in ipairs(mobile_phone_prefixes) do
|
|
bsw/jbe@1309
|
30 trace.debug(value_prefix, prefix.min)
|
|
bsw/jbe@1309
|
31 if value_prefix >= prefix.min and value_prefix <= prefix.max then
|
|
bsw/jbe@1309
|
32 valid_prefix = true
|
|
bsw/jbe@1309
|
33 end
|
|
bsw/jbe@1309
|
34 end
|
|
bsw/jbe@1309
|
35
|
|
bsw/jbe@1309
|
36 if valid_prefix then
|
|
bsw/jbe@1309
|
37 return true
|
|
bsw/jbe@1309
|
38 else
|
|
bsw/jbe@1309
|
39 return false
|
|
bsw/jbe@1309
|
40 end
|
|
bsw/jbe@1309
|
41 end
|
|
bsw/jbe@1309
|
42
|
|
bsw/jbe@1309
|
43 local function check_uk_mobile_phone_number(value)
|
|
bsw/jbe@1309
|
44
|
|
bsw/jbe@1309
|
45 if not value then
|
|
bsw/jbe@1309
|
46 return false
|
|
bsw/jbe@1309
|
47 end
|
|
bsw/jbe@1309
|
48
|
|
bsw/jbe@1309
|
49 value = string.gsub(value, "[^0-9]*", "")
|
|
bsw/jbe@1309
|
50
|
|
bsw/jbe@1309
|
51 if #(value) < 11 or #(value) > 11 then
|
|
bsw/jbe@1309
|
52 return false
|
|
bsw/jbe@1309
|
53 end
|
|
bsw/jbe@1309
|
54
|
|
bsw/jbe@1309
|
55 local mobile_phone_prefixes = {
|
|
bsw/jbe@1309
|
56 { min = 071, max = 079, comment = "UK phone" },
|
|
bsw/jbe@1309
|
57 }
|
|
bsw/jbe@1309
|
58
|
|
bsw/jbe@1309
|
59 local value_prefix = tonumber(string.match(value, "^(...)"))
|
|
bsw/jbe@1309
|
60
|
|
bsw/jbe@1309
|
61 local valid_prefix = false
|
|
bsw/jbe@1309
|
62
|
|
bsw/jbe@1309
|
63 for i, prefix in ipairs(mobile_phone_prefixes) do
|
|
bsw/jbe@1309
|
64 trace.debug(value_prefix, prefix.min)
|
|
bsw/jbe@1309
|
65 if value_prefix >= prefix.min and value_prefix <= prefix.max then
|
|
bsw/jbe@1309
|
66 valid_prefix = true
|
|
bsw/jbe@1309
|
67 end
|
|
bsw/jbe@1309
|
68 end
|
|
bsw/jbe@1309
|
69
|
|
bsw/jbe@1309
|
70 if valid_prefix then
|
|
bsw/jbe@1309
|
71 return true
|
|
bsw/jbe@1309
|
72 else
|
|
bsw/jbe@1309
|
73 return false
|
|
bsw/jbe@1309
|
74 end
|
|
bsw/jbe@1309
|
75 end
|
|
bsw/jbe@1309
|
76
|
|
bsw/jbe@1309
|
77 local errors = 0
|
|
bsw/jbe@1309
|
78
|
|
bsw/jbe@1309
|
79 local manual_verification
|
|
bsw/jbe@1309
|
80
|
|
bsw/jbe@1309
|
81 if config.self_registration.allow_bypass_checks and param.get("manual_verification") then
|
|
bsw/jbe@1309
|
82 manual_verification = true
|
|
bsw/jbe@1309
|
83 end
|
|
bsw/jbe@1309
|
84
|
|
bsw/jbe@1309
|
85 for i, checkbox in ipairs(config.use_terms_checkboxes) do
|
|
bsw/jbe@1309
|
86 local accepted = param.get("use_terms_checkbox_" .. checkbox.name, atom.boolean)
|
|
bsw/jbe@1309
|
87 if not accepted then
|
|
bsw/jbe@1309
|
88 slot.put_into("error", checkbox.not_accepted_error)
|
|
bsw/jbe@1309
|
89 errors = errors + 1
|
|
bsw/jbe@1309
|
90 end
|
|
bsw/jbe@1309
|
91 end
|
|
bsw/jbe@1309
|
92
|
|
bsw/jbe@1309
|
93 local email = param.get("email")
|
|
bsw/jbe@1309
|
94
|
|
bsw/jbe@1309
|
95 local members = Member:new_selector()
|
|
bsw/jbe@1309
|
96 :add_where{ "notify_email = ? OR notify_email_unconfirmed = ?", email }
|
|
bsw/jbe@1309
|
97 :exec()
|
|
bsw/jbe@1309
|
98
|
|
bsw/jbe@1309
|
99 if #members > 0 then
|
|
bsw/jbe@1309
|
100 slot.select("error", function()
|
|
bsw/jbe@1309
|
101 slot.put_into("registration_register_email_invalid", "already_used")
|
|
bsw/jbe@1309
|
102 ui.tag{ content = _"This email address already been used. Please check your inbox for an invitation or contact us." }
|
|
bsw/jbe@1309
|
103 end)
|
|
bsw/jbe@1309
|
104 errors = errors + 1
|
|
bsw/jbe@1309
|
105 end
|
|
bsw/jbe@1309
|
106
|
|
bsw/jbe@1309
|
107 local verification = Verification:new()
|
|
bsw/jbe@1309
|
108 verification.requested = "now"
|
|
bsw/jbe@1309
|
109 verification.request_origin = json.object{
|
|
bsw/jbe@1309
|
110 ip = request.get_header("X-Forwarded-For"),
|
|
bsw/jbe@1309
|
111 hostname = request.get_header("X-Forwarded-Host")
|
|
bsw/jbe@1309
|
112 }
|
|
bsw/jbe@1309
|
113 verification.request_data = json.object()
|
|
bsw/jbe@1309
|
114
|
|
bsw/jbe@1309
|
115 for i, field in ipairs(config.self_registration.fields) do
|
|
bsw@1359
|
116 if not field.internal then
|
|
bsw@1359
|
117 if field.name == "date_of_birth" then
|
|
bsw@1359
|
118 local day = tonumber(param.get("verification_data_" .. field.name .. "_day"))
|
|
bsw@1359
|
119 local month = tonumber(param.get("verification_data_" .. field.name .. "_month"))
|
|
bsw@1359
|
120 local year = tonumber(param.get("verification_data_" .. field.name .. "_year"))
|
|
bsw@1359
|
121 local date = atom.date:new{ year = year, month = month, day = day }
|
|
bsw@1359
|
122 if date.invalid then
|
|
bsw@1359
|
123 slot.select("error", function()
|
|
bsw@1359
|
124 ui.container{ content = _"Please check date of birth" }
|
|
bsw@1359
|
125 slot.put_into("self_registration__invalid_" .. field.name, "invalid")
|
|
bsw@1359
|
126 end)
|
|
bsw@1359
|
127 errors = errors + 1
|
|
bsw@1359
|
128 end
|
|
bsw@1359
|
129 local today = atom.date:get_current()
|
|
bsw@1359
|
130 local date_16y_ago = atom.date:new{ year = today.year - 16, month = today.month, day = today.day }
|
|
bsw@1359
|
131 if date_16y_ago.invalid and today.month == 2 and today.day == 29 then
|
|
bsw@1359
|
132 date_16y_ago = atom.date:new{ year = today.year - 16, month = 2, day = 28 }
|
|
bsw@1359
|
133 end
|
|
bsw@1359
|
134 if date > date_16y_ago then
|
|
bsw@1359
|
135 request.redirect{ external = encode.url { module = "registration", view = "register_rejected_age" } }
|
|
bsw@1359
|
136 return
|
|
bsw@1334
|
137 end
|
|
bsw@1359
|
138 verification.request_data[field.name] = string.format("%04i-%02i-%02i", year, month, day)
|
|
bsw@1359
|
139
|
|
bsw/jbe@1309
|
140 else
|
|
bsw@1359
|
141 local value = param.get("verification_data_" .. field.name)
|
|
bsw@1376
|
142 local optional = false
|
|
bsw@1376
|
143 if field.optional then
|
|
bsw@1376
|
144 optional = true
|
|
bsw@1376
|
145 end
|
|
bsw@1376
|
146 if field.optional_checkbox and param.get("verification_data_" .. field.name .. "_optout", atom.boolean) then
|
|
bsw@1376
|
147 optional = true
|
|
bsw@1376
|
148 end
|
|
bsw@1376
|
149 if not optional and (not value or (#value < 1 and (not manual_verification or field.name ~= "mobile_phone"))) then
|
|
bsw@1359
|
150 slot.put_into("self_registration__invalid_" .. field.name, "to_short")
|
|
bsw@1359
|
151 slot.select("error", function()
|
|
bsw@1359
|
152 ui.container{ content = _("Please enter: #{field_name}", { field_name = field.label }) }
|
|
bsw@1359
|
153 end)
|
|
bsw@1359
|
154 errors = errors + 1
|
|
bsw@1359
|
155 end
|
|
bsw@1359
|
156 if field.name == "fiscal_code" then
|
|
bsw@1359
|
157 value = string.upper(value)
|
|
bsw@1359
|
158 value = string.gsub(value, "[^A-Z0-9]", "")
|
|
bsw@1359
|
159 elseif field.name == "mobile_phone" then
|
|
bsw@1359
|
160 value = string.gsub(value, "[^0-9]", "")
|
|
bsw@1359
|
161 elseif field.type == "image" then
|
|
bsw@1359
|
162 if field.save_func then
|
|
bsw@1359
|
163 value = field.save_func(value)
|
|
bsw@1359
|
164 end
|
|
bsw@1359
|
165 else
|
|
bsw@1359
|
166 value = string.gsub(value, "^%s+", "")
|
|
bsw@1359
|
167 value = string.gsub(value, "%s+$", "")
|
|
bsw@1359
|
168 value = string.gsub(value, "%s+", " ")
|
|
bsw@1359
|
169 end
|
|
bsw@1359
|
170 verification.request_data[field.name] = value
|
|
bsw/jbe@1309
|
171 end
|
|
bsw/jbe@1309
|
172 end
|
|
bsw/jbe@1309
|
173
|
|
bsw@1359
|
174 local mobile_phone = verification.request_data.mobile_phone
|
|
bsw@1359
|
175
|
|
bsw@1359
|
176 if not manual_verification then
|
|
bsw@1359
|
177 if config.self_registration.check_for_italien_mobile_phone then
|
|
bsw@1359
|
178 if not check_italian_mobile_phone_number(mobile_phone) then
|
|
bsw@1359
|
179 slot.select("error", function()
|
|
bsw@1359
|
180 ui.container{ content = _"Please check the mobile phone number (invalid format)" }
|
|
bsw@1359
|
181 end)
|
|
bsw@1359
|
182 errors = errors + 1
|
|
bsw@1359
|
183 end
|
|
bsw@1359
|
184 end
|
|
bsw@1359
|
185
|
|
bsw@1359
|
186 if config.self_registration.check_for_uk_mobile_phone then
|
|
bsw@1359
|
187 if not check_uk_mobile_phone_number(mobile_phone) then
|
|
bsw@1359
|
188 slot.select("error", function()
|
|
bsw@1359
|
189 ui.container{ content = _"Please check the mobile phone number (invalid format)" }
|
|
bsw@1359
|
190 end)
|
|
bsw@1359
|
191 errors = errors + 1
|
|
bsw@1359
|
192 end
|
|
bsw/jbe@1309
|
193 end
|
|
bsw/jbe@1309
|
194 end
|
|
bsw/jbe@1309
|
195 end
|
|
bsw/jbe@1309
|
196
|
|
bsw/jbe@1309
|
197 if config.self_registration.check_for_italian_fiscal_code then
|
|
bsw/jbe@1309
|
198 local check_fiscal_code = execute.chunk{ module = "registration", chunk = "_check_fiscal_code" }
|
|
bsw/jbe@1309
|
199
|
|
bsw/jbe@1309
|
200 local fiscal_code_valid, fiscal_code_error = check_fiscal_code(
|
|
bsw/jbe@1309
|
201 verification.request_data.fiscal_code,
|
|
bsw/jbe@1309
|
202 {
|
|
bsw/jbe@1309
|
203 first_name = verification.request_data.first_name,
|
|
bsw/jbe@1309
|
204 last_name = verification.request_data.name,
|
|
bsw/jbe@1309
|
205 year = tonumber(string.match(verification.request_data.date_of_birth, "^(....)-..-..$")),
|
|
bsw/jbe@1309
|
206 month = tonumber(string.match(verification.request_data.date_of_birth, "^....-(..)-..$")),
|
|
bsw/jbe@1309
|
207 day = tonumber(string.match(verification.request_data.date_of_birth, "^....-..-(..)$")),
|
|
bsw/jbe@1309
|
208 }
|
|
bsw/jbe@1309
|
209 )
|
|
bsw/jbe@1309
|
210
|
|
bsw/jbe@1309
|
211 if fiscal_code_valid then
|
|
bsw/jbe@1309
|
212 verification.comment = (verification.comment or "").. " /// Fiscal code matched"
|
|
bsw/jbe@1309
|
213 else
|
|
bsw/jbe@1309
|
214 slot.select("error", function()
|
|
bsw/jbe@1309
|
215 ui.container{ content = _"Please check the fiscal code (invalid format or does not match name, first name and/or date of birth)" }
|
|
bsw/jbe@1309
|
216 end)
|
|
bsw/jbe@1309
|
217 errors = errors + 1
|
|
bsw/jbe@1309
|
218 --table.insert(manual_check_reasons, "fiscal code does not match (" .. fiscal_code_error .. ")")
|
|
bsw/jbe@1309
|
219 end
|
|
bsw/jbe@1309
|
220 end
|
|
bsw/jbe@1309
|
221
|
|
bsw/jbe@1309
|
222 if errors > 0 then
|
|
bsw/jbe@1309
|
223 return false
|
|
bsw/jbe@1309
|
224 end
|
|
bsw/jbe@1309
|
225
|
|
bsw/jbe@1309
|
226 local member = Member:new()
|
|
bsw/jbe@1309
|
227 member.notify_email = email
|
|
bsw/jbe@1309
|
228 member:save()
|
|
bsw/jbe@1309
|
229
|
|
bsw/jbe@1309
|
230 for i, checkbox in ipairs(config.use_terms_checkboxes) do
|
|
bsw/jbe@1309
|
231 local accepted = param.get("use_terms_checkbox_" .. checkbox.name, atom.boolean)
|
|
bsw/jbe@1309
|
232 local member_useterms = MemberUseterms:new()
|
|
bsw/jbe@1309
|
233 member_useterms.member_id = member.id
|
|
bsw/jbe@1309
|
234 member_useterms.contract_identifier = checkbox.name
|
|
bsw/jbe@1309
|
235 member_useterms:save()
|
|
bsw/jbe@1309
|
236 end
|
|
bsw/jbe@1309
|
237
|
|
bsw/jbe@1309
|
238 verification.requesting_member_id = member.id
|
|
bsw/jbe@1309
|
239
|
|
bsw/jbe@1309
|
240 local manual_check_reasons = {}
|
|
bsw/jbe@1309
|
241
|
|
bsw/jbe@1309
|
242 if manual_verification then
|
|
bsw/jbe@1309
|
243 table.insert(manual_check_reasons, "User requested manual verification (during step 1)")
|
|
bsw/jbe@1309
|
244 end
|
|
bsw/jbe@1309
|
245
|
|
bsw@1316
|
246 if not config.self_registration.sms_id then
|
|
bsw@1316
|
247 table.insert(manual_check_reasons, "User requested manual verification (during step 1)")
|
|
bsw@1316
|
248 end
|
|
bsw@1316
|
249
|
|
bsw/jbe@1309
|
250 local existing_verifications = Verification:new_selector()
|
|
bsw/jbe@1309
|
251 :add_where{ "request_data->>'mobile_phone' = ?", mobile_phone }
|
|
bsw/jbe@1309
|
252 :add_where("comment ilike '%SMS code%'")
|
|
bsw/jbe@1309
|
253 :exec()
|
|
bsw/jbe@1309
|
254
|
|
bsw/jbe@1309
|
255 if #existing_verifications > 0 then
|
|
bsw/jbe@1309
|
256 table.insert(manual_check_reasons, "mobile phone number already used before")
|
|
bsw/jbe@1309
|
257 end
|
|
bsw/jbe@1309
|
258
|
|
bsw/jbe@1309
|
259 if #manual_check_reasons > 0 then
|
|
bsw/jbe@1309
|
260 local reasons = table.concat(manual_check_reasons, ", ")
|
|
bsw/jbe@1309
|
261 verification.comment = (verification.comment or "").. " /// Manual verification needed: " .. reasons
|
|
bsw/jbe@1309
|
262 verification:save()
|
|
bsw/jbe@1309
|
263 request.redirect{ external = encode.url { module = "registration", view = "register_manual_check_needed" } }
|
|
bsw/jbe@1309
|
264
|
|
bsw/jbe@1309
|
265 else
|
|
bsw/jbe@1309
|
266 local pin = multirand.string(6, "0123456789")
|
|
bsw/jbe@1309
|
267 verification.request_data.sms_code = pin
|
|
bsw/jbe@1309
|
268 verification.request_data.sms_code_tries = 3
|
|
bsw/jbe@1309
|
269 local sms_text = config.self_registration.sms_text
|
|
bsw/jbe@1309
|
270 local sms_text = string.gsub(sms_text, "{PIN}", pin)
|
|
bsw/jbe@1309
|
271 print("SMS Code: " .. sms_text)
|
|
bsw/jbe@1309
|
272 local phone_number
|
|
bsw/jbe@1309
|
273 if config.self_registration.sms_strip_leading_zero then
|
|
bsw/jbe@1309
|
274 phone_number = string.match(verification.request_data.mobile_phone, "0(.+)")
|
|
bsw/jbe@1309
|
275 else
|
|
bsw/jbe@1309
|
276 phone_number = verification.request_data.mobile_phone
|
|
bsw/jbe@1309
|
277 end
|
|
bsw/jbe@1309
|
278 phone_number = config.self_registration.sms_prefix .. phone_number
|
|
bsw/jbe@1309
|
279 local params = {
|
|
bsw/jbe@1309
|
280 id = config.self_registration.sms_id,
|
|
bsw/jbe@1309
|
281 pass = config.self_registration.sms_pass,
|
|
bsw/jbe@1309
|
282 gateway = config.self_registration.sms_gateway,
|
|
bsw/jbe@1309
|
283 absender = config.self_registration.sms_from,
|
|
bsw/jbe@1309
|
284 text = sms_text,
|
|
bsw/jbe@1309
|
285 nummer = phone_number,
|
|
bsw/jbe@1309
|
286 test = config.self_registration.test and "1" or nil
|
|
bsw/jbe@1309
|
287 }
|
|
bsw/jbe@1309
|
288 local params_list = {}
|
|
bsw/jbe@1309
|
289 for k, v in pairs(params) do
|
|
bsw/jbe@1309
|
290 table.insert(params_list, encode.url_part(k) .. "=" .. encode.url_part(v))
|
|
bsw/jbe@1309
|
291 end
|
|
bsw/jbe@1309
|
292
|
|
bsw/jbe@1309
|
293 local params_string = table.concat(params_list, "&")
|
|
bsw/jbe@1309
|
294 local url = "http://gateway.any-sms.biz/send_sms.php?" .. params_string
|
|
bsw/jbe@1309
|
295 print("curl " .. url)
|
|
bsw/jbe@1309
|
296 local output, err, status = extos.pfilter(nil, "curl", url)
|
|
bsw/jbe@1309
|
297 print(output)
|
|
bsw/jbe@1309
|
298 verification.request_data.sms_code_sent_status = output
|
|
bsw/jbe@1309
|
299 if not string.match(output, "^err:0") then
|
|
bsw/jbe@1309
|
300 verification.comment = (verification.comment or "").. " /// Manual verification needed: sending SMS failed (" .. output .. ")"
|
|
bsw/jbe@1309
|
301 verification:save()
|
|
bsw/jbe@1309
|
302 request.redirect{ external = encode.url { module = "registration", view = "register_manual_check_needed" } }
|
|
bsw/jbe@1309
|
303 return
|
|
bsw/jbe@1309
|
304 end
|
|
bsw/jbe@1309
|
305 verification.comment = (verification.comment or "") .. " /// SMS code " .. pin .. " sent"
|
|
bsw/jbe@1309
|
306 verification:save()
|
|
bsw/jbe@1309
|
307 request.redirect{ external = encode.url { module = "registration", view = "register_enter_pin", id = verification.id } }
|
|
bsw/jbe@1309
|
308 end
|
|
bsw/jbe@1309
|
309
|
|
bsw/jbe@1309
|
310
|
|
bsw/jbe@1309
|
311
|