liquid_feedback_frontend
changeset 1359:7532831a7618
Allow internal registration fields
author | bsw |
---|---|
date | Mon Aug 06 13:56:43 2018 +0200 (2018-08-06) |
parents | 06675c87f45f |
children | 7fbe8b516c2b |
files | app/main/registration/_action/register.lua app/main/registration/_register_form.lua app/main/registration_admin/_action/update_verification.lua app/main/registration_admin/verification.lua |
line diff
1.1 --- a/app/main/registration/_action/register.lua Mon Aug 06 13:42:37 2018 +0200 1.2 +++ b/app/main/registration/_action/register.lua Mon Aug 06 13:56:43 2018 +0200 1.3 @@ -113,76 +113,76 @@ 1.4 verification.request_data = json.object() 1.5 1.6 for i, field in ipairs(config.self_registration.fields) do 1.7 - if field.name == "date_of_birth" then 1.8 - local day = tonumber(param.get("verification_data_" .. field.name .. "_day")) 1.9 - local month = tonumber(param.get("verification_data_" .. field.name .. "_month")) 1.10 - local year = tonumber(param.get("verification_data_" .. field.name .. "_year")) 1.11 - local date = atom.date:new{ year = year, month = month, day = day } 1.12 - if date.invalid then 1.13 - slot.select("error", function() 1.14 - ui.container{ content = _"Please check date of birth" } 1.15 - slot.put_into("self_registration__invalid_" .. field.name, "invalid") 1.16 - end) 1.17 - errors = errors + 1 1.18 - end 1.19 - local today = atom.date:get_current() 1.20 - local date_16y_ago = atom.date:new{ year = today.year - 16, month = today.month, day = today.day } 1.21 - if date_16y_ago.invalid and today.month == 2 and today.day == 29 then 1.22 - date_16y_ago = atom.date:new{ year = today.year - 16, month = 2, day = 28 } 1.23 - end 1.24 - if date > date_16y_ago then 1.25 - request.redirect{ external = encode.url { module = "registration", view = "register_rejected_age" } } 1.26 - return 1.27 - end 1.28 - verification.request_data[field.name] = string.format("%04i-%02i-%02i", year, month, day) 1.29 - 1.30 - else 1.31 - local value = param.get("verification_data_" .. field.name) 1.32 - if not field.optional and (not value or (#value < 1 and (not manual_verification or field.name ~= "mobile_phone"))) then 1.33 - slot.put_into("self_registration__invalid_" .. field.name, "to_short") 1.34 - slot.select("error", function() 1.35 - ui.container{ content = _("Please enter: #{field_name}", { field_name = field.label }) } 1.36 - end) 1.37 - errors = errors + 1 1.38 - end 1.39 - if field.name == "fiscal_code" then 1.40 - value = string.upper(value) 1.41 - value = string.gsub(value, "[^A-Z0-9]", "") 1.42 - elseif field.name == "mobile_phone" then 1.43 - value = string.gsub(value, "[^0-9]", "") 1.44 - elseif field.type == "image" then 1.45 - if field.save_func then 1.46 - value = field.save_func(value) 1.47 + if not field.internal then 1.48 + if field.name == "date_of_birth" then 1.49 + local day = tonumber(param.get("verification_data_" .. field.name .. "_day")) 1.50 + local month = tonumber(param.get("verification_data_" .. field.name .. "_month")) 1.51 + local year = tonumber(param.get("verification_data_" .. field.name .. "_year")) 1.52 + local date = atom.date:new{ year = year, month = month, day = day } 1.53 + if date.invalid then 1.54 + slot.select("error", function() 1.55 + ui.container{ content = _"Please check date of birth" } 1.56 + slot.put_into("self_registration__invalid_" .. field.name, "invalid") 1.57 + end) 1.58 + errors = errors + 1 1.59 + end 1.60 + local today = atom.date:get_current() 1.61 + local date_16y_ago = atom.date:new{ year = today.year - 16, month = today.month, day = today.day } 1.62 + if date_16y_ago.invalid and today.month == 2 and today.day == 29 then 1.63 + date_16y_ago = atom.date:new{ year = today.year - 16, month = 2, day = 28 } 1.64 + end 1.65 + if date > date_16y_ago then 1.66 + request.redirect{ external = encode.url { module = "registration", view = "register_rejected_age" } } 1.67 + return 1.68 end 1.69 + verification.request_data[field.name] = string.format("%04i-%02i-%02i", year, month, day) 1.70 + 1.71 else 1.72 - value = string.gsub(value, "^%s+", "") 1.73 - value = string.gsub(value, "%s+$", "") 1.74 - value = string.gsub(value, "%s+", " ") 1.75 - end 1.76 - verification.request_data[field.name] = value 1.77 - end 1.78 -end 1.79 - 1.80 -local automatic_verification_possible = true 1.81 - 1.82 -local mobile_phone = verification.request_data.mobile_phone 1.83 - 1.84 -if not manual_verification then 1.85 - if config.self_registration.check_for_italien_mobile_phone then 1.86 - if not check_italian_mobile_phone_number(mobile_phone) then 1.87 - slot.select("error", function() 1.88 - ui.container{ content = _"Please check the mobile phone number (invalid format)" } 1.89 - end) 1.90 - errors = errors + 1 1.91 + local value = param.get("verification_data_" .. field.name) 1.92 + if not field.optional and (not value or (#value < 1 and (not manual_verification or field.name ~= "mobile_phone"))) then 1.93 + slot.put_into("self_registration__invalid_" .. field.name, "to_short") 1.94 + slot.select("error", function() 1.95 + ui.container{ content = _("Please enter: #{field_name}", { field_name = field.label }) } 1.96 + end) 1.97 + errors = errors + 1 1.98 + end 1.99 + if field.name == "fiscal_code" then 1.100 + value = string.upper(value) 1.101 + value = string.gsub(value, "[^A-Z0-9]", "") 1.102 + elseif field.name == "mobile_phone" then 1.103 + value = string.gsub(value, "[^0-9]", "") 1.104 + elseif field.type == "image" then 1.105 + if field.save_func then 1.106 + value = field.save_func(value) 1.107 + end 1.108 + else 1.109 + value = string.gsub(value, "^%s+", "") 1.110 + value = string.gsub(value, "%s+$", "") 1.111 + value = string.gsub(value, "%s+", " ") 1.112 + end 1.113 + verification.request_data[field.name] = value 1.114 end 1.115 end 1.116 1.117 - if config.self_registration.check_for_uk_mobile_phone then 1.118 - if not check_uk_mobile_phone_number(mobile_phone) then 1.119 - slot.select("error", function() 1.120 - ui.container{ content = _"Please check the mobile phone number (invalid format)" } 1.121 - end) 1.122 - errors = errors + 1 1.123 + local mobile_phone = verification.request_data.mobile_phone 1.124 + 1.125 + if not manual_verification then 1.126 + if config.self_registration.check_for_italien_mobile_phone then 1.127 + if not check_italian_mobile_phone_number(mobile_phone) then 1.128 + slot.select("error", function() 1.129 + ui.container{ content = _"Please check the mobile phone number (invalid format)" } 1.130 + end) 1.131 + errors = errors + 1 1.132 + end 1.133 + end 1.134 + 1.135 + if config.self_registration.check_for_uk_mobile_phone then 1.136 + if not check_uk_mobile_phone_number(mobile_phone) then 1.137 + slot.select("error", function() 1.138 + ui.container{ content = _"Please check the mobile phone number (invalid format)" } 1.139 + end) 1.140 + errors = errors + 1 1.141 + end 1.142 end 1.143 end 1.144 end
2.1 --- a/app/main/registration/_register_form.lua Mon Aug 06 13:42:37 2018 +0200 2.2 +++ b/app/main/registration/_register_form.lua Mon Aug 06 13:56:43 2018 +0200 2.3 @@ -7,128 +7,130 @@ 2.4 if field_error then 2.5 class = " is-invalid" 2.6 end 2.7 - if field.name == "date_of_birth" then 2.8 - slot.put("<br />") 2.9 - local label = field.label 2.10 - if field.optional then 2.11 - label = label .. config.self_registration.optional_field_indicator 2.12 - end 2.13 - ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" } 2.14 - slot.put(" ") 2.15 - local days = { { id = 0, name = _"day" } } 2.16 - for i = 1, 31 do 2.17 - table.insert(days, { id = i, name = i }) 2.18 - end 2.19 - local months = { 2.20 - { id = 0, name = _"month" }, 2.21 - { id = 1, name = "gennaio" }, 2.22 - { id = 2, name = "febbraio" }, 2.23 - { id = 3, name = "marzo" }, 2.24 - { id = 4, name = "aprile" }, 2.25 - { id = 5, name = "maggio" }, 2.26 - { id = 6, name = "giugno" }, 2.27 - { id = 7, name = "luglio" }, 2.28 - { id = 8, name = "agosto" }, 2.29 - { id = 9, name = "settembre" }, 2.30 - { id = 10, name = "ottobre" }, 2.31 - { id = 11, name = "novembre" }, 2.32 - { id = 12, name = "dicembre" }, 2.33 - } 2.34 - if config.self_registration.lang == "en" then 2.35 - months = { 2.36 + if not field.internal then 2.37 + if field.name == "date_of_birth" then 2.38 + slot.put("<br />") 2.39 + local label = field.label 2.40 + if field.optional then 2.41 + label = label .. config.self_registration.optional_field_indicator 2.42 + end 2.43 + ui.tag{ tag = "label", attr = { style = "vertical-align: bottom; border-bottom: 1px solid rgba(0,0,0, 0.12); color: #777; font-size: 16px;" }, content = field.label .. ":" } 2.44 + slot.put(" ") 2.45 + local days = { { id = 0, name = _"day" } } 2.46 + for i = 1, 31 do 2.47 + table.insert(days, { id = i, name = i }) 2.48 + end 2.49 + local months = { 2.50 { id = 0, name = _"month" }, 2.51 - { id = 1, name = "January" }, 2.52 - { id = 2, name = "February" }, 2.53 - { id = 3, name = "March" }, 2.54 - { id = 4, name = "April" }, 2.55 - { id = 5, name = "May" }, 2.56 - { id = 6, name = "June" }, 2.57 - { id = 7, name = "July" }, 2.58 - { id = 8, name = "August" }, 2.59 - { id = 9, name = "September" }, 2.60 - { id = 10, name = "October" }, 2.61 - { id = 11, name = "November" }, 2.62 - { id = 12, name = "December" }, 2.63 + { id = 1, name = "gennaio" }, 2.64 + { id = 2, name = "febbraio" }, 2.65 + { id = 3, name = "marzo" }, 2.66 + { id = 4, name = "aprile" }, 2.67 + { id = 5, name = "maggio" }, 2.68 + { id = 6, name = "giugno" }, 2.69 + { id = 7, name = "luglio" }, 2.70 + { id = 8, name = "agosto" }, 2.71 + { id = 9, name = "settembre" }, 2.72 + { id = 10, name = "ottobre" }, 2.73 + { id = 11, name = "novembre" }, 2.74 + { id = 12, name = "dicembre" }, 2.75 + } 2.76 + if config.self_registration.lang == "en" then 2.77 + months = { 2.78 + { id = 0, name = _"month" }, 2.79 + { id = 1, name = "January" }, 2.80 + { id = 2, name = "February" }, 2.81 + { id = 3, name = "March" }, 2.82 + { id = 4, name = "April" }, 2.83 + { id = 5, name = "May" }, 2.84 + { id = 6, name = "June" }, 2.85 + { id = 7, name = "July" }, 2.86 + { id = 8, name = "August" }, 2.87 + { id = 9, name = "September" }, 2.88 + { id = 10, name = "October" }, 2.89 + { id = 11, name = "November" }, 2.90 + { id = 12, name = "December" }, 2.91 + } 2.92 + end 2.93 + local years = { { id = 0, name = _"year" } } 2.94 + for i = 2002, 1900, -1 do 2.95 + table.insert(years, { id = i, name = i }) 2.96 + end 2.97 + ui.field.select{ 2.98 + container_attr = { style = "display: inline-block; " }, 2.99 + attr = { class = class }, 2.100 + foreign_records = days, 2.101 + foreign_id = "id", 2.102 + foreign_name = "name", 2.103 + name = "verification_data_" .. field.name .. "_day", 2.104 + value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" }) 2.105 + } 2.106 + slot.put(" ") 2.107 + ui.field.select{ 2.108 + container_attr = { style = "display: inline-block; " }, 2.109 + attr = { class = class }, 2.110 + foreign_records = months, 2.111 + foreign_id = "id", 2.112 + foreign_name = "name", 2.113 + name = "verification_data_" .. field.name .. "_month", 2.114 + value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" }) 2.115 + } 2.116 + slot.put(" ") 2.117 + ui.field.select{ 2.118 + container_attr = { style = "display: inline-block; " }, 2.119 + attr = { class = class }, 2.120 + foreign_records = years, 2.121 + foreign_id = "id", 2.122 + foreign_name = "name", 2.123 + name = "verification_data_" .. field.name .. "_year", 2.124 + value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" }) 2.125 + } 2.126 + slot.put("<br />") 2.127 + 2.128 + elseif field.type == "image" then 2.129 + ui.tag{ tag = "label", content = field.label } 2.130 + ui.tag{ tag = "input", attr = { type = "file", name = "verification_data_" .. field.name } } 2.131 + 2.132 + elseif field.name == "unit" then 2.133 + local units_selector = Unit:new_selector() 2.134 + :add_where{ "active" } 2.135 + if field.where then 2.136 + units_selector:add_where(field.where) 2.137 + end 2.138 + local units = {} 2.139 + if field.optional then 2.140 + table.insert(units, { 2.141 + id = "", 2.142 + name = _"None" 2.143 + }) 2.144 + end 2.145 + for i_unit, unit in ipairs(units_selector:exec()) do 2.146 + table.insert(units, unit) 2.147 + end 2.148 + ui.field.select{ 2.149 + label = field.label, 2.150 + foreign_records = units, 2.151 + foreign_id = "id", 2.152 + foreign_name = "name", 2.153 + name = "verification_data_" .. field.name, 2.154 + value = tonumber(request.get_param{ name = "verification_data_" .. field.name }) 2.155 + } 2.156 + else 2.157 + if field.name == "mobile_phone" then 2.158 + if config.self_registration.lang ~= "en" then 2.159 + ui.tag{ content = "+39" } 2.160 + slot.put(" ") 2.161 + end 2.162 + end 2.163 + ui.field.text{ 2.164 + container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class }, 2.165 + attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" }, 2.166 + label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name }, 2.167 + label = field.label, 2.168 + name = "verification_data_" .. field.name, 2.169 + value = request.get_param{ name = "verification_data_" .. field.name } 2.170 } 2.171 end 2.172 - local years = { { id = 0, name = _"year" } } 2.173 - for i = 2002, 1900, -1 do 2.174 - table.insert(years, { id = i, name = i }) 2.175 - end 2.176 - ui.field.select{ 2.177 - container_attr = { style = "display: inline-block; " }, 2.178 - attr = { class = class }, 2.179 - foreign_records = days, 2.180 - foreign_id = "id", 2.181 - foreign_name = "name", 2.182 - name = "verification_data_" .. field.name .. "_day", 2.183 - value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" }) 2.184 - } 2.185 - slot.put(" ") 2.186 - ui.field.select{ 2.187 - container_attr = { style = "display: inline-block; " }, 2.188 - attr = { class = class }, 2.189 - foreign_records = months, 2.190 - foreign_id = "id", 2.191 - foreign_name = "name", 2.192 - name = "verification_data_" .. field.name .. "_month", 2.193 - value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" }) 2.194 - } 2.195 - slot.put(" ") 2.196 - ui.field.select{ 2.197 - container_attr = { style = "display: inline-block; " }, 2.198 - attr = { class = class }, 2.199 - foreign_records = years, 2.200 - foreign_id = "id", 2.201 - foreign_name = "name", 2.202 - name = "verification_data_" .. field.name .. "_year", 2.203 - value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" }) 2.204 - } 2.205 slot.put("<br />") 2.206 - 2.207 - elseif field.type == "image" then 2.208 - ui.tag{ tag = "label", content = field.label } 2.209 - ui.tag{ tag = "input", attr = { type = "file", name = "verification_data_" .. field.name } } 2.210 - 2.211 - elseif field.name == "unit" then 2.212 - local units_selector = Unit:new_selector() 2.213 - :add_where{ "active" } 2.214 - if field.where then 2.215 - units_selector:add_where(field.where) 2.216 - end 2.217 - local units = {} 2.218 - if field.optional then 2.219 - table.insert(units, { 2.220 - id = "", 2.221 - name = _"None" 2.222 - }) 2.223 - end 2.224 - for i_unit, unit in ipairs(units_selector:exec()) do 2.225 - table.insert(units, unit) 2.226 - end 2.227 - ui.field.select{ 2.228 - label = field.label, 2.229 - foreign_records = units, 2.230 - foreign_id = "id", 2.231 - foreign_name = "name", 2.232 - name = "verification_data_" .. field.name, 2.233 - value = tonumber(request.get_param{ name = "verification_data_" .. field.name }) 2.234 - } 2.235 - else 2.236 - if field.name == "mobile_phone" then 2.237 - if config.self_registration.lang ~= "en" then 2.238 - ui.tag{ content = "+39" } 2.239 - slot.put(" ") 2.240 - end 2.241 - end 2.242 - ui.field.text{ 2.243 - container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class }, 2.244 - attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" }, 2.245 - label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name }, 2.246 - label = field.label, 2.247 - name = "verification_data_" .. field.name, 2.248 - value = request.get_param{ name = "verification_data_" .. field.name } 2.249 - } 2.250 end 2.251 - slot.put("<br />") 2.252 end
3.1 --- a/app/main/registration_admin/_action/update_verification.lua Mon Aug 06 13:42:37 2018 +0200 3.2 +++ b/app/main/registration_admin/_action/update_verification.lua Mon Aug 06 13:56:43 2018 +0200 3.3 @@ -30,6 +30,8 @@ 3.4 value = string.gsub(value, "^%s+", "") 3.5 value = string.gsub(value, "%s+$", "") 3.6 value = string.gsub(value, "%s+", " ") 3.7 + elseif field.name == "sequential_number" then 3.8 + value = old_verification_data.sequential_number 3.9 end 3.10 verification.verification_data[field.name] = value 3.11 end
4.1 --- a/app/main/registration_admin/verification.lua Mon Aug 06 13:42:37 2018 +0200 4.2 +++ b/app/main/registration_admin/verification.lua Mon Aug 06 13:56:43 2018 +0200 4.3 @@ -89,6 +89,15 @@ 4.4 name = field.name, 4.5 value = tonumber(data[field.name]) 4.6 } 4.7 + elseif field.name = "sequential_number" then 4.8 + ui.field.text{ 4.9 + container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" }, 4.10 + attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" }, 4.11 + label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name }, 4.12 + label = field.label, 4.13 + name = field.name, 4.14 + readonly = true 4.15 + } 4.16 else 4.17 ui.field.text{ 4.18 container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" },