liquid_feedback_frontend
diff app/main/registration/_action/register.lua @ 1843:b01d9920371b
merge
| author | jbe |
|---|---|
| date | Thu Feb 03 15:57:22 2022 +0100 (2022-02-03) |
| parents | 38a8b840bff7 |
| children |
line diff
1.1 --- a/app/main/registration/_action/register.lua Thu Feb 03 15:54:23 2022 +0100 1.2 +++ b/app/main/registration/_action/register.lua Thu Feb 03 15:57:22 2022 +0100 1.3 @@ -138,8 +138,46 @@ 1.4 end 1.5 verification.request_data[field.name] = string.format("%04i-%02i-%02i", year, month, day) 1.6 1.7 + elseif field.type == "multiselect" then 1.8 + local values = {} 1.9 + for i_options, option in ipairs(field.options) do 1.10 + if not option.id then 1.11 + option.id = option.name 1.12 + end 1.13 + local value = param.get("verification_data_" .. field.name .. "__" .. option.id) 1.14 + if value == "1" then 1.15 + if option.other then 1.16 + table.insert(values, param.get("verification_data_" .. field.name .. "_other")) 1.17 + else 1.18 + table.insert(values, option.id) 1.19 + end 1.20 + end 1.21 + end 1.22 + if not field.optional and #values < 1 then 1.23 + slot.put_into("self_registration__invalid_" .. field.name, "to_short") 1.24 + slot.select("error", function() 1.25 + ui.container{ content = _("Please enter: #{field_name}", { field_name = field.label or field.title }) } 1.26 + end) 1.27 + errors = errors + 1 1.28 + end 1.29 + verification.request_data[field.name] = table.concat(values, ", ") 1.30 else 1.31 local value = param.get("verification_data_" .. field.name) 1.32 + if field.type == "dropdown" then 1.33 + local other_option_id 1.34 + for i_options, option in ipairs(field.options) do 1.35 + if not option.id then 1.36 + option.id = option.name 1.37 + end 1.38 + if option.other then 1.39 + other_option_id = option.id 1.40 + end 1.41 + end 1.42 + if other_option_id and other_option_id == value then 1.43 + value = param.get("verification_data_" .. field.name .. "_other") 1.44 + end 1.45 + end 1.46 + 1.47 local optional = false 1.48 if field.optional then 1.49 optional = true 1.50 @@ -150,7 +188,7 @@ 1.51 if not optional and (not value or (#value < 1 and (not manual_verification or field.name ~= "mobile_phone"))) then 1.52 slot.put_into("self_registration__invalid_" .. field.name, "to_short") 1.53 slot.select("error", function() 1.54 - ui.container{ content = _("Please enter: #{field_name}", { field_name = field.label }) } 1.55 + ui.container{ content = _("Please enter: #{field_name}", { field_name = field.label or field.title }) } 1.56 end) 1.57 errors = errors + 1 1.58 end 1.59 @@ -244,17 +282,19 @@ 1.60 table.insert(manual_check_reasons, "User requested manual verification (during step 1)") 1.61 end 1.62 1.63 -if not config.self_registration.sms_id then 1.64 - table.insert(manual_check_reasons, "User requested manual verification (during step 1)") 1.65 +if config.self_registration.sms_id then 1.66 + local existing_verifications = Verification:new_selector() 1.67 + :add_where{ "request_data->>'mobile_phone' = ?", mobile_phone } 1.68 + :add_where("comment ilike '%SMS code%'") 1.69 + :exec() 1.70 + 1.71 + if #existing_verifications > 0 then 1.72 + table.insert(manual_check_reasons, "mobile phone number already used before") 1.73 + end 1.74 end 1.75 1.76 -local existing_verifications = Verification:new_selector() 1.77 - :add_where{ "request_data->>'mobile_phone' = ?", mobile_phone } 1.78 - :add_where("comment ilike '%SMS code%'") 1.79 - :exec() 1.80 - 1.81 -if #existing_verifications > 0 then 1.82 - table.insert(manual_check_reasons, "mobile phone number already used before") 1.83 +if config.self_registration.force_manual_check then 1.84 + table.insert(manual_check_reasons, "Manual check enforced by configuration") 1.85 end 1.86 1.87 if #manual_check_reasons > 0 then 1.88 @@ -263,13 +303,12 @@ 1.89 verification:save() 1.90 request.redirect{ external = encode.url { module = "registration", view = "register_manual_check_needed" } } 1.91 1.92 -else 1.93 +elseif config.self_registration.sms_id then 1.94 local pin = multirand.string(6, "0123456789") 1.95 verification.request_data.sms_code = pin 1.96 verification.request_data.sms_code_tries = 3 1.97 local sms_text = config.self_registration.sms_text 1.98 local sms_text = string.gsub(sms_text, "{PIN}", pin) 1.99 - print("SMS Code: " .. sms_text) 1.100 local phone_number 1.101 if config.self_registration.sms_strip_leading_zero then 1.102 phone_number = string.match(verification.request_data.mobile_phone, "0(.+)") 1.103 @@ -293,9 +332,7 @@ 1.104 1.105 local params_string = table.concat(params_list, "&") 1.106 local url = "http://gateway.any-sms.biz/send_sms.php?" .. params_string 1.107 - print("curl " .. url) 1.108 local output, err, status = extos.pfilter(nil, "curl", url) 1.109 - print(output) 1.110 verification.request_data.sms_code_sent_status = output 1.111 if not string.match(output, "^err:0") then 1.112 verification.comment = (verification.comment or "").. " /// Manual verification needed: sending SMS failed (" .. output .. ")" 1.113 @@ -306,6 +343,25 @@ 1.114 verification.comment = (verification.comment or "") .. " /// SMS code " .. pin .. " sent" 1.115 verification:save() 1.116 request.redirect{ external = encode.url { module = "registration", view = "register_enter_pin", id = verification.id } } 1.117 + 1.118 +else 1.119 + local success = execute.action{ 1.120 + module = "registration", action = "_verify", params = { 1.121 + verification = verification 1.122 + } 1.123 + } 1.124 + if success == "ok" then 1.125 + if verification.request_data.unit then 1.126 + local unit_privilege = Privilege:new() 1.127 + unit_privilege.member_id = verification.requesting_member_id 1.128 + unit_privilege.unit_id = tonumber(verification.request_data.unit) 1.129 + unit_privilege.voting_right = true 1.130 + unit_privilege.initiative_right = true 1.131 + unit_privilege:save() 1.132 + end 1.133 + request.redirect{ external = encode.url { module = "registration", view = "register_completed" } } 1.134 + end 1.135 + 1.136 end 1.137 1.138