# HG changeset patch
# User bsw
# Date 1533556603 -7200
# Node ID 7532831a76180590b13b11e7d60e511cb0264239
# Parent 06675c87f45f7e6e34b30785e401aeb14aab0913
Allow internal registration fields
diff -r 06675c87f45f -r 7532831a7618 app/main/registration/_action/register.lua
--- a/app/main/registration/_action/register.lua Mon Aug 06 13:42:37 2018 +0200
+++ b/app/main/registration/_action/register.lua Mon Aug 06 13:56:43 2018 +0200
@@ -113,76 +113,76 @@
verification.request_data = json.object()
for i, field in ipairs(config.self_registration.fields) do
- if field.name == "date_of_birth" then
- local day = tonumber(param.get("verification_data_" .. field.name .. "_day"))
- local month = tonumber(param.get("verification_data_" .. field.name .. "_month"))
- local year = tonumber(param.get("verification_data_" .. field.name .. "_year"))
- local date = atom.date:new{ year = year, month = month, day = day }
- if date.invalid then
- slot.select("error", function()
- ui.container{ content = _"Please check date of birth" }
- slot.put_into("self_registration__invalid_" .. field.name, "invalid")
- end)
- errors = errors + 1
- end
- local today = atom.date:get_current()
- local date_16y_ago = atom.date:new{ year = today.year - 16, month = today.month, day = today.day }
- if date_16y_ago.invalid and today.month == 2 and today.day == 29 then
- date_16y_ago = atom.date:new{ year = today.year - 16, month = 2, day = 28 }
- end
- if date > date_16y_ago then
- request.redirect{ external = encode.url { module = "registration", view = "register_rejected_age" } }
- return
- end
- verification.request_data[field.name] = string.format("%04i-%02i-%02i", year, month, day)
-
- else
- local value = param.get("verification_data_" .. field.name)
- if not field.optional and (not value or (#value < 1 and (not manual_verification or field.name ~= "mobile_phone"))) then
- slot.put_into("self_registration__invalid_" .. field.name, "to_short")
- slot.select("error", function()
- ui.container{ content = _("Please enter: #{field_name}", { field_name = field.label }) }
- end)
- errors = errors + 1
- end
- if field.name == "fiscal_code" then
- value = string.upper(value)
- value = string.gsub(value, "[^A-Z0-9]", "")
- elseif field.name == "mobile_phone" then
- value = string.gsub(value, "[^0-9]", "")
- elseif field.type == "image" then
- if field.save_func then
- value = field.save_func(value)
+ if not field.internal then
+ if field.name == "date_of_birth" then
+ local day = tonumber(param.get("verification_data_" .. field.name .. "_day"))
+ local month = tonumber(param.get("verification_data_" .. field.name .. "_month"))
+ local year = tonumber(param.get("verification_data_" .. field.name .. "_year"))
+ local date = atom.date:new{ year = year, month = month, day = day }
+ if date.invalid then
+ slot.select("error", function()
+ ui.container{ content = _"Please check date of birth" }
+ slot.put_into("self_registration__invalid_" .. field.name, "invalid")
+ end)
+ errors = errors + 1
+ end
+ local today = atom.date:get_current()
+ local date_16y_ago = atom.date:new{ year = today.year - 16, month = today.month, day = today.day }
+ if date_16y_ago.invalid and today.month == 2 and today.day == 29 then
+ date_16y_ago = atom.date:new{ year = today.year - 16, month = 2, day = 28 }
+ end
+ if date > date_16y_ago then
+ request.redirect{ external = encode.url { module = "registration", view = "register_rejected_age" } }
+ return
end
+ verification.request_data[field.name] = string.format("%04i-%02i-%02i", year, month, day)
+
else
- value = string.gsub(value, "^%s+", "")
- value = string.gsub(value, "%s+$", "")
- value = string.gsub(value, "%s+", " ")
- end
- verification.request_data[field.name] = value
- end
-end
-
-local automatic_verification_possible = true
-
-local mobile_phone = verification.request_data.mobile_phone
-
-if not manual_verification then
- if config.self_registration.check_for_italien_mobile_phone then
- if not check_italian_mobile_phone_number(mobile_phone) then
- slot.select("error", function()
- ui.container{ content = _"Please check the mobile phone number (invalid format)" }
- end)
- errors = errors + 1
+ local value = param.get("verification_data_" .. field.name)
+ if not field.optional and (not value or (#value < 1 and (not manual_verification or field.name ~= "mobile_phone"))) then
+ slot.put_into("self_registration__invalid_" .. field.name, "to_short")
+ slot.select("error", function()
+ ui.container{ content = _("Please enter: #{field_name}", { field_name = field.label }) }
+ end)
+ errors = errors + 1
+ end
+ if field.name == "fiscal_code" then
+ value = string.upper(value)
+ value = string.gsub(value, "[^A-Z0-9]", "")
+ elseif field.name == "mobile_phone" then
+ value = string.gsub(value, "[^0-9]", "")
+ elseif field.type == "image" then
+ if field.save_func then
+ value = field.save_func(value)
+ end
+ else
+ value = string.gsub(value, "^%s+", "")
+ value = string.gsub(value, "%s+$", "")
+ value = string.gsub(value, "%s+", " ")
+ end
+ verification.request_data[field.name] = value
end
end
- if config.self_registration.check_for_uk_mobile_phone then
- if not check_uk_mobile_phone_number(mobile_phone) then
- slot.select("error", function()
- ui.container{ content = _"Please check the mobile phone number (invalid format)" }
- end)
- errors = errors + 1
+ local mobile_phone = verification.request_data.mobile_phone
+
+ if not manual_verification then
+ if config.self_registration.check_for_italien_mobile_phone then
+ if not check_italian_mobile_phone_number(mobile_phone) then
+ slot.select("error", function()
+ ui.container{ content = _"Please check the mobile phone number (invalid format)" }
+ end)
+ errors = errors + 1
+ end
+ end
+
+ if config.self_registration.check_for_uk_mobile_phone then
+ if not check_uk_mobile_phone_number(mobile_phone) then
+ slot.select("error", function()
+ ui.container{ content = _"Please check the mobile phone number (invalid format)" }
+ end)
+ errors = errors + 1
+ end
end
end
end
diff -r 06675c87f45f -r 7532831a7618 app/main/registration/_register_form.lua
--- a/app/main/registration/_register_form.lua Mon Aug 06 13:42:37 2018 +0200
+++ b/app/main/registration/_register_form.lua Mon Aug 06 13:56:43 2018 +0200
@@ -7,128 +7,130 @@
if field_error then
class = " is-invalid"
end
- if field.name == "date_of_birth" then
- slot.put("
")
- local label = field.label
- if field.optional then
- label = label .. config.self_registration.optional_field_indicator
- end
- 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 .. ":" }
- slot.put(" ")
- local days = { { id = 0, name = _"day" } }
- for i = 1, 31 do
- table.insert(days, { id = i, name = i })
- end
- local months = {
- { id = 0, name = _"month" },
- { id = 1, name = "gennaio" },
- { id = 2, name = "febbraio" },
- { id = 3, name = "marzo" },
- { id = 4, name = "aprile" },
- { id = 5, name = "maggio" },
- { id = 6, name = "giugno" },
- { id = 7, name = "luglio" },
- { id = 8, name = "agosto" },
- { id = 9, name = "settembre" },
- { id = 10, name = "ottobre" },
- { id = 11, name = "novembre" },
- { id = 12, name = "dicembre" },
- }
- if config.self_registration.lang == "en" then
- months = {
+ if not field.internal then
+ if field.name == "date_of_birth" then
+ slot.put("
")
+ local label = field.label
+ if field.optional then
+ label = label .. config.self_registration.optional_field_indicator
+ end
+ 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 .. ":" }
+ slot.put(" ")
+ local days = { { id = 0, name = _"day" } }
+ for i = 1, 31 do
+ table.insert(days, { id = i, name = i })
+ end
+ local months = {
{ id = 0, name = _"month" },
- { id = 1, name = "January" },
- { id = 2, name = "February" },
- { id = 3, name = "March" },
- { id = 4, name = "April" },
- { id = 5, name = "May" },
- { id = 6, name = "June" },
- { id = 7, name = "July" },
- { id = 8, name = "August" },
- { id = 9, name = "September" },
- { id = 10, name = "October" },
- { id = 11, name = "November" },
- { id = 12, name = "December" },
+ { id = 1, name = "gennaio" },
+ { id = 2, name = "febbraio" },
+ { id = 3, name = "marzo" },
+ { id = 4, name = "aprile" },
+ { id = 5, name = "maggio" },
+ { id = 6, name = "giugno" },
+ { id = 7, name = "luglio" },
+ { id = 8, name = "agosto" },
+ { id = 9, name = "settembre" },
+ { id = 10, name = "ottobre" },
+ { id = 11, name = "novembre" },
+ { id = 12, name = "dicembre" },
+ }
+ if config.self_registration.lang == "en" then
+ months = {
+ { id = 0, name = _"month" },
+ { id = 1, name = "January" },
+ { id = 2, name = "February" },
+ { id = 3, name = "March" },
+ { id = 4, name = "April" },
+ { id = 5, name = "May" },
+ { id = 6, name = "June" },
+ { id = 7, name = "July" },
+ { id = 8, name = "August" },
+ { id = 9, name = "September" },
+ { id = 10, name = "October" },
+ { id = 11, name = "November" },
+ { id = 12, name = "December" },
+ }
+ end
+ local years = { { id = 0, name = _"year" } }
+ for i = 2002, 1900, -1 do
+ table.insert(years, { id = i, name = i })
+ end
+ ui.field.select{
+ container_attr = { style = "display: inline-block; " },
+ attr = { class = class },
+ foreign_records = days,
+ foreign_id = "id",
+ foreign_name = "name",
+ name = "verification_data_" .. field.name .. "_day",
+ value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" })
+ }
+ slot.put(" ")
+ ui.field.select{
+ container_attr = { style = "display: inline-block; " },
+ attr = { class = class },
+ foreign_records = months,
+ foreign_id = "id",
+ foreign_name = "name",
+ name = "verification_data_" .. field.name .. "_month",
+ value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" })
+ }
+ slot.put(" ")
+ ui.field.select{
+ container_attr = { style = "display: inline-block; " },
+ attr = { class = class },
+ foreign_records = years,
+ foreign_id = "id",
+ foreign_name = "name",
+ name = "verification_data_" .. field.name .. "_year",
+ value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" })
+ }
+ slot.put("
")
+
+ elseif field.type == "image" then
+ ui.tag{ tag = "label", content = field.label }
+ ui.tag{ tag = "input", attr = { type = "file", name = "verification_data_" .. field.name } }
+
+ elseif field.name == "unit" then
+ local units_selector = Unit:new_selector()
+ :add_where{ "active" }
+ if field.where then
+ units_selector:add_where(field.where)
+ end
+ local units = {}
+ if field.optional then
+ table.insert(units, {
+ id = "",
+ name = _"None"
+ })
+ end
+ for i_unit, unit in ipairs(units_selector:exec()) do
+ table.insert(units, unit)
+ end
+ ui.field.select{
+ label = field.label,
+ foreign_records = units,
+ foreign_id = "id",
+ foreign_name = "name",
+ name = "verification_data_" .. field.name,
+ value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
+ }
+ else
+ if field.name == "mobile_phone" then
+ if config.self_registration.lang ~= "en" then
+ ui.tag{ content = "+39" }
+ slot.put(" ")
+ end
+ end
+ ui.field.text{
+ container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
+ attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
+ label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
+ label = field.label,
+ name = "verification_data_" .. field.name,
+ value = request.get_param{ name = "verification_data_" .. field.name }
}
end
- local years = { { id = 0, name = _"year" } }
- for i = 2002, 1900, -1 do
- table.insert(years, { id = i, name = i })
- end
- ui.field.select{
- container_attr = { style = "display: inline-block; " },
- attr = { class = class },
- foreign_records = days,
- foreign_id = "id",
- foreign_name = "name",
- name = "verification_data_" .. field.name .. "_day",
- value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_day" })
- }
- slot.put(" ")
- ui.field.select{
- container_attr = { style = "display: inline-block; " },
- attr = { class = class },
- foreign_records = months,
- foreign_id = "id",
- foreign_name = "name",
- name = "verification_data_" .. field.name .. "_month",
- value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_month" })
- }
- slot.put(" ")
- ui.field.select{
- container_attr = { style = "display: inline-block; " },
- attr = { class = class },
- foreign_records = years,
- foreign_id = "id",
- foreign_name = "name",
- name = "verification_data_" .. field.name .. "_year",
- value = tonumber(request.get_param{ name = "verification_data_" .. field.name .. "_year" })
- }
slot.put("
")
-
- elseif field.type == "image" then
- ui.tag{ tag = "label", content = field.label }
- ui.tag{ tag = "input", attr = { type = "file", name = "verification_data_" .. field.name } }
-
- elseif field.name == "unit" then
- local units_selector = Unit:new_selector()
- :add_where{ "active" }
- if field.where then
- units_selector:add_where(field.where)
- end
- local units = {}
- if field.optional then
- table.insert(units, {
- id = "",
- name = _"None"
- })
- end
- for i_unit, unit in ipairs(units_selector:exec()) do
- table.insert(units, unit)
- end
- ui.field.select{
- label = field.label,
- foreign_records = units,
- foreign_id = "id",
- foreign_name = "name",
- name = "verification_data_" .. field.name,
- value = tonumber(request.get_param{ name = "verification_data_" .. field.name })
- }
- else
- if field.name == "mobile_phone" then
- if config.self_registration.lang ~= "en" then
- ui.tag{ content = "+39" }
- slot.put(" ")
- end
- end
- ui.field.text{
- container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" .. class },
- attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
- label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
- label = field.label,
- name = "verification_data_" .. field.name,
- value = request.get_param{ name = "verification_data_" .. field.name }
- }
end
- slot.put("
")
end
diff -r 06675c87f45f -r 7532831a7618 app/main/registration_admin/_action/update_verification.lua
--- a/app/main/registration_admin/_action/update_verification.lua Mon Aug 06 13:42:37 2018 +0200
+++ b/app/main/registration_admin/_action/update_verification.lua Mon Aug 06 13:56:43 2018 +0200
@@ -30,6 +30,8 @@
value = string.gsub(value, "^%s+", "")
value = string.gsub(value, "%s+$", "")
value = string.gsub(value, "%s+", " ")
+ elseif field.name == "sequential_number" then
+ value = old_verification_data.sequential_number
end
verification.verification_data[field.name] = value
end
diff -r 06675c87f45f -r 7532831a7618 app/main/registration_admin/verification.lua
--- a/app/main/registration_admin/verification.lua Mon Aug 06 13:42:37 2018 +0200
+++ b/app/main/registration_admin/verification.lua Mon Aug 06 13:56:43 2018 +0200
@@ -89,6 +89,15 @@
name = field.name,
value = tonumber(data[field.name])
}
+ elseif field.name = "sequential_number" then
+ ui.field.text{
+ container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" },
+ attr = { id = "lf-register__data_" .. field.name, class = "mdl-textfield__input" },
+ label_attr = { class = "mdl-textfield__label", ["for"] = "lf-register__data" .. field.name },
+ label = field.label,
+ name = field.name,
+ readonly = true
+ }
else
ui.field.text{
container_attr = { class = "mdl-textfield mdl-js-textfield mdl-textfield--floating-label" },