liquid_feedback_frontend

view app/main/member/_action/update.lua @ 1817:757a87af4c83

Added validation hook for profile updates
author bsw
date Mon Dec 13 11:57:35 2021 +0100 (2021-12-13)
parents 32cc544d5a5b
children
line source
1 local profile = app.session.member.profile
3 for i, field in ipairs(config.member_profile_fields) do
4 if not util.is_profile_field_locked(app.session.member, field.id) and not field.validate_func then
5 local value = param.get(field.id)
6 if value == "" then
7 value = null
8 end
9 profile.profile[field.id] = value
10 end
11 end
13 if not util.is_profile_field_locked(profile, "statement") then
14 local formatting_engine = param.get("formatting_engine") or config.enforce_formatting_engine
16 local formatting_engine_valid = false
17 for i, fe in pairs(config.formatting_engines) do
18 if formatting_engine == fe.id then
19 formatting_engine_valid = true
20 end
21 end
22 if not formatting_engine_valid then
23 error("invalid formatting engine!")
24 end
27 local statement = param.get("statement")
29 if statement ~= profile.statement or
30 formatting_engine ~= profile.formatting_engine then
31 profile.formatting_engine = formatting_engine
32 profile.statement = statement
33 profile:render_content(true)
34 end
36 end
38 if not util.is_profile_field_locked(profile, "birthday") then
39 if tostring(profile.birthday) == "invalid_date" then
40 profile.birthday = nil
41 slot.put_into("error", _"Date format is not valid. Please use following format: YYYY-MM-DD")
42 return false
43 end
44 end
46 local search_strings = {}
47 for i, field in ipairs(config.member_profile_fields) do
48 if field.index and profile.profile[field.id] and #(profile.profile[field.id]) > 0 then
49 search_strings[#search_strings+1] = profile.profile[field.id]
50 end
51 end
53 if profile.statement and #(profile.statement) > 0 then
54 search_strings[#search_strings+1] = profile.statement
55 end
57 profile.profile_text_data = table.concat(search_strings, " ")
59 profile:save()
62 slot.put_into("notice", _"Your page has been updated")

Impressum / About Us