liquid_feedback_frontend

view app/main/registration_admin/_action/update_verification.lua @ 1814:8f431f4cc87f

Fixed syntax
author bsw
date Thu Dec 02 13:34:22 2021 +0100 (2021-12-02)
parents f9f3a657d348
children 6246f8249f9f
line source
1 local verification = Verification:by_id(param.get_id())
3 local function update_data()
4 local old_verification_data = verification.verification_data or {}
5 verification.verification_data = json.object()
7 for i, field in ipairs(config.self_registration.fields) do
8 local value = param.get(field.name)
9 if field.name == "fiscal_code" then
10 value = string.gsub(value, "[^A-Z0-9]", "")
11 elseif field.name == "mobile_phone" then
12 value = string.gsub(value, "[^0-9]", "")
13 elseif field.name == "unit" then
14 value = string.gsub(value, "[^0-9]", "")
15 if old_verification_data.unit and old_verification_data.unit ~= "" and old_verification_data.unit ~= value then
16 local old_unit_privilege = Privilege:by_pk(old_verification_data.unit, verification.requesting_member_id)
17 if old_unit_privilege then
18 old_unit_privilege:destroy()
19 end
20 end
21 if value ~= old_verification_data.unit and value ~= "" then
22 local unit_privilege = Privilege:new()
23 unit_privilege.member_id = verification.requesting_member_id
24 unit_privilege.unit_id = tonumber(value)
25 unit_privilege.voting_right = true
26 unit_privilege.initiative_right = true
27 unit_privilege:save()
28 end
29 elseif field.name == "sequential_number" then
30 value = old_verification_data.sequential_number
31 if not value then
32 local last_sequential_number = 0
33 db:query('LOCK TABLE "verification" IN SHARE ROW EXCLUSIVE MODE')
34 local record = Verification:new_selector()
35 :reset_fields()
36 :add_field("max((verification_data->>'sequential_number')::int8)", "max_sequential_number")
37 :optional_object_mode()
38 :exec()
39 if record and record.max_sequential_number then
40 last_sequential_number = record.max_sequential_number
41 end
42 value = last_sequential_number + 1
43 end
44 elseif field.type ~= "image" then
45 value = string.gsub(value, "^%s+", "")
46 value = string.gsub(value, "%s+$", "")
47 value = string.gsub(value, "%s+", " ")
48 end
49 verification.verification_data[field.name] = value
50 end
51 end
53 local function check_db_error(db_error)
54 if db_error then
55 if db_error:is_kind_of("IntegrityConstraintViolation.UniqueViolation") then
56 slot.select("error", function()
57 ui.tag{ content = _"Identification unique violation: This identification is already in use for another member." }
58 end )
59 return false
60 else
61 error(db_error)
62 end
63 end
64 end
66 if verification.verified_member_id then
68 local member = Member:by_id(verification.verified_member_id)
70 if param.get("cancel") then
71 db:query({ "SELECT delete_member(?)", member.id })
72 return
73 end
75 local identification = param.get("identification")
76 if identification and #identification == 0 then
77 identification = nil
78 end
79 member.identification = identification
81 member.notify_email = param.get("email")
83 check_db_error(member:try_save())
85 update_data()
87 verification:save()
89 if param.get("invite") then
90 member:send_invitation()
91 end
93 elseif param.get("drop") then
95 verification.denied = "now"
96 verification:save()
97 return
99 elseif param.get("accredit") then
101 local member = Member:by_id(verification.requesting_member_id)
103 local identification = param.get("identification")
104 if identification and #identification == 0 then
105 identification = nil
106 end
107 member.identification = identification
109 member.notify_email = param.get("email")
110 check_db_error(member:try_save())
112 if config.self_registration.manual_invitation then
113 local function secret_token()
114 local parts = {}
115 for i = 1, 5 do
116 parts[#parts+1] = multirand.string(5, "23456789bcdfghjkmnpqrstvwxyz")
117 end
118 return (table.concat(parts, "-"))
119 end
120 member.invite_code = secret_token()
121 member:save()
122 else
123 member:send_invitation()
124 end
126 for i, unit_id in ipairs(config.self_registration.grant_privileges_for_unit_ids) do
127 local privilege = Privilege:new()
128 privilege.member_id = member.id
129 privilege.unit_id = unit_id
130 privilege.initiative_right = true
131 privilege.voting_right = true
132 privilege:save()
133 end
135 update_data()
137 verification.verified_member_id = verification.requesting_member_id
138 verification.verifying_member_id = app.session.member_id
139 verification.verified = "now"
141 verification:save()
144 else
146 update_data()
147 verification:save()
149 end

Impressum / About Us