liquid_feedback_frontend
annotate app/main/registration/_action/register_pin.lua @ 1309:32cc544d5a5b
Cumulative patch for upcoming frontend version 4
author | bsw/jbe |
---|---|
date | Sun Jul 15 14:07:29 2018 +0200 (2018-07-15) |
parents | |
children | 899fdfb23465 |
rev | line source |
---|---|
bsw/jbe@1309 | 1 local id = param.get_id() |
bsw/jbe@1309 | 2 local verification = Verification:by_id(id) |
bsw/jbe@1309 | 3 |
bsw/jbe@1309 | 4 if not verification then |
bsw/jbe@1309 | 5 return false |
bsw/jbe@1309 | 6 end |
bsw/jbe@1309 | 7 |
bsw/jbe@1309 | 8 local pin = param.get("pin") |
bsw/jbe@1309 | 9 |
bsw/jbe@1309 | 10 if param.get("manual_verification") then |
bsw/jbe@1309 | 11 verification.comment = (verification.comment or "") .. " /// User requested manual verification (during step 2)" |
bsw/jbe@1309 | 12 verification:save() |
bsw/jbe@1309 | 13 request.redirect{ external = encode.url { module = "registration", view = "register_manual_check_needed" } } |
bsw/jbe@1309 | 14 return false |
bsw/jbe@1309 | 15 elseif verification.request_data.sms_code ~= pin then |
bsw/jbe@1309 | 16 verification.request_data.sms_code_tries = verification.request_data.sms_code_tries - 1 |
bsw/jbe@1309 | 17 verification.comment = (verification.comment or "") .. " /// User entered wrong PIN " .. pin |
bsw/jbe@1309 | 18 if verification.request_data.sms_code_tries > 0 then |
bsw/jbe@1309 | 19 verification:save() |
bsw/jbe@1309 | 20 request.redirect{ external = encode.url { module = "registration", view = "register_enter_pin", id = verification.id, params = { invalid_pin = true } } } |
bsw/jbe@1309 | 21 return false |
bsw/jbe@1309 | 22 else |
bsw/jbe@1309 | 23 verification.comment = (verification.comment or "") .. " /// Manual verification needed: user entered invalid PIN three times" |
bsw/jbe@1309 | 24 verification:save() |
bsw/jbe@1309 | 25 request.redirect{ external = encode.url { module = "registration", view = "register_manual_check_needed" } } |
bsw/jbe@1309 | 26 return false |
bsw/jbe@1309 | 27 end |
bsw/jbe@1309 | 28 end |
bsw/jbe@1309 | 29 |
bsw/jbe@1309 | 30 verification.comment = (verification.comment or "").. " /// User entered correct PIN code" |
bsw/jbe@1309 | 31 |
bsw/jbe@1309 | 32 verification.verified = "now" |
bsw/jbe@1309 | 33 verification.verification_data = verification.request_data |
bsw/jbe@1309 | 34 |
bsw/jbe@1309 | 35 local identification = config.self_registration.identification_func(verification.request_data) |
bsw/jbe@1309 | 36 |
bsw/jbe@1309 | 37 local members_with_same_identification = Member:new_selector() |
bsw/jbe@1309 | 38 :add_where{ "identification = ?", identification } |
bsw/jbe@1309 | 39 :exec() |
bsw/jbe@1309 | 40 |
bsw/jbe@1309 | 41 if #members_with_same_identification > 0 then |
bsw/jbe@1309 | 42 verification.comment = (verification.comment or "").. " /// Manual verification needed: user with same name already exists" |
bsw/jbe@1309 | 43 verification:save() |
bsw/jbe@1309 | 44 request.redirect{ external = encode.url { module = "registration", view = "register_manual_check_needed" } } |
bsw/jbe@1309 | 45 return false |
bsw/jbe@1309 | 46 end |
bsw/jbe@1309 | 47 |
bsw/jbe@1309 | 48 local member = Member:by_id(verification.requesting_member_id) |
bsw/jbe@1309 | 49 |
bsw/jbe@1309 | 50 member.identification = identification |
bsw/jbe@1309 | 51 member.notify_email = verification.request_data.email |
bsw/jbe@1309 | 52 |
bsw/jbe@1309 | 53 member:send_invitation() |
bsw/jbe@1309 | 54 |
bsw/jbe@1309 | 55 for i, unit_id in ipairs(config.self_registration.grant_privileges_for_unit_ids) do |
bsw/jbe@1309 | 56 local privilege = Privilege:new() |
bsw/jbe@1309 | 57 privilege.member_id = member.id |
bsw/jbe@1309 | 58 privilege.unit_id = unit_id |
bsw/jbe@1309 | 59 privilege.initiative_right = true |
bsw/jbe@1309 | 60 privilege.voting_right = true |
bsw/jbe@1309 | 61 privilege:save() |
bsw/jbe@1309 | 62 end |
bsw/jbe@1309 | 63 |
bsw/jbe@1309 | 64 verification.verified_member_id = member.id |
bsw/jbe@1309 | 65 |
bsw/jbe@1309 | 66 verification.comment = (verification.comment or "").. " /// Account created" |
bsw/jbe@1309 | 67 |
bsw/jbe@1309 | 68 verification:save() |
bsw/jbe@1309 | 69 |
bsw/jbe@1309 | 70 |
bsw/jbe@1309 | 71 request.redirect{ external = encode.url { module = "registration", view = "register_completed" } } |