liquid_feedback_frontend
view app/main/api/profile.lua @ 1486:00ce64d26e9e
Fixed redirection after registration without redirect params
| author | bsw | 
|---|---|
| date | Sun Nov 04 19:32:13 2018 +0100 (2018-11-04) | 
| parents | 32cc544d5a5b | 
| children | 757a87af4c83 | 
 line source
     1 slot.set_layout(nil, "application/json")
     3 local r = json.object{}
     5 if request.is_post() then
     6   if not app.scopes.update_profile then
     7     return util.api_error(403, "Forbidden", "insufficient_scope", "Scope update_profile required")
     8   end
     9   local profile = app.access_token.member.profile
    10   local fields = json.import(param.get("update"))
    11   if not fields then
    12     return util.api_error(400, "Bad Request", "profile_data_expected", "JSON object with updated profile data expected")
    13   end
    14   for i, field in ipairs(config.member_profile_fields) do
    15     if json.type(fields, field.id) ~= "nil" then
    16       local value = fields[field.id]
    17       if value ~= nil and (field.type == "string" or field.type == "text") and json.type(value) ~= "string" then
    18         return util.api_error(400, "Bad Request", "string_expected", "JSON encoded string value expected")
    19       end
    20       profile.profile[field.id] = value
    21     end
    22   end
    23   profile:save()
    24   r.status = 'ok'
    25   slot.put_into("data", json.export(r))
    26   slot.put_into("data", "\n")
    27 else
    28   local member_id = tonumber(param.get("member_id"))
    29   local profile
    30   if member_id then
    31     if not app.scopes.read_profiles then
    32       return util.api_error(403, "Forbidden", "insufficient_scope", "Scope profile required")
    33     end
    34     local member = Member:by_id(member_id)
    35     if not member then
    36       return util.api_error(400, "Bad Request", "member_not_found", "No member with requested member_id")
    37     end
    38     profile = member.profile
    39   elseif app.access_token then
    40     if not app.scopes.profile and not app.scopes.read_profiles then
    41       return util.api_error(403, "Forbidden", "insufficient_scope", "Scope profile required")
    42     end
    43     profile = app.access_token.member.profile
    44   else
    45     return util.api_error(400, "Bad Request", "no_member_id", "No member_id requested")
    46   end
    47   if profile then
    48     r = execute.chunk{ module = "api", chunk = "_profile", params = { profile = profile } }
    49   end
    50   slot.put_into("data", json.export(json.object{ result = r }))
    51   slot.put_into("data", "\n")
    52 end
