annotate app/main/api/avatar.lua @ 1748:8d7c4d542c3d
Correctly store answer option for checkboxes
 | author | 
 bsw | 
 | date | 
 Mon Oct 11 10:55:14 2021 +0200 (2021-10-11) | 
 | parents | 
 bbb537ba81b2  | 
 | children | 
  | 
 
 | rev | 
   line source | 
| 
bsw@1635
 | 
     1 slot.set_layout(nil, "application/json")
 | 
| 
bsw@1635
 | 
     2 
 | 
| 
bsw@1635
 | 
     3 if not (
 | 
| 
bsw@1635
 | 
     4   app.scopes.read_authors
 | 
| 
bsw@1635
 | 
     5   or app.scopes.read_identities 
 | 
| 
bsw@1635
 | 
     6   or app.scopes.read_profiles
 | 
| 
bsw@1635
 | 
     7 ) then
 | 
| 
bsw@1635
 | 
     8   return util.api_error(403, "Forbidden", "insufficient_scope", "Scope read_authors or read_identities or read_profiles required")
 | 
| 
bsw@1635
 | 
     9 end
 | 
| 
bsw@1635
 | 
    10 
 | 
| 
bsw@1635
 | 
    11 local r = json.object{
 | 
| 
bsw@1635
 | 
    12   result = json.array()
 | 
| 
bsw@1635
 | 
    13 }
 | 
| 
bsw@1635
 | 
    14 
 | 
| 
bsw@1635
 | 
    15 local selector = MemberImage:new_selector()
 | 
| 
bsw@1635
 | 
    16   :add_where("image_type = 'avatar'")
 | 
| 
bsw@1635
 | 
    17   :add_where("scaled")
 | 
| 
bsw@1635
 | 
    18   :optional_object_mode()
 | 
| 
bsw@1635
 | 
    19 
 | 
| 
bsw@1635
 | 
    20 local member_id = param.get("member_id")
 | 
| 
bsw@1635
 | 
    21 if member_id then
 | 
| 
bsw@1635
 | 
    22   selector:add_where{ "member_id = ?", member_id }
 | 
| 
bsw@1635
 | 
    23 else
 | 
| 
bsw@1635
 | 
    24   return util.api_error(404, "Missing parameter", "no_member_id", "No member_id provided")
 | 
| 
bsw@1635
 | 
    25 end
 | 
| 
bsw@1635
 | 
    26 
 | 
| 
bsw@1635
 | 
    27 local member_image = selector:exec()
 | 
| 
bsw@1635
 | 
    28 
 | 
| 
bsw@1635
 | 
    29 local data
 | 
| 
bsw@1635
 | 
    30 local content_type
 | 
| 
bsw@1635
 | 
    31 
 | 
| 
bsw@1635
 | 
    32 if member_image then
 | 
| 
bsw@1635
 | 
    33   data = member_image.data
 | 
| 
bsw@1635
 | 
    34   content_type = member_image.content_type
 | 
| 
bsw@1635
 | 
    35 else
 | 
| 
bsw@1635
 | 
    36   local filename = WEBMCP_BASE_PATH .. "static/avatar.jpg"
 | 
| 
bsw@1635
 | 
    37   local f = assert(io.open(filename), "Cannot open default image file")
 | 
| 
bsw@1635
 | 
    38   data = f:read("*a")
 | 
| 
bsw@1635
 | 
    39   content_type = "image/jpeg"
 | 
| 
bsw@1635
 | 
    40   f:close()
 | 
| 
bsw@1635
 | 
    41 end
 | 
| 
bsw@1635
 | 
    42 
 | 
| 
bsw@1635
 | 
    43 slot.set_layout(nil, "image/jpeg")
 | 
| 
bsw@1635
 | 
    44 slot.put_into("data", data)
 | 
| 
bsw@1635
 | 
    45 
 |