Mercurial > prosody-modules
comparison mod_http_admin_api/mod_http_admin_api.lua @ 4351:c0b1b2a61e3c
mod_http_admin_api: Add support for creating reusable/group/custom-ttl invites
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Sun, 17 Jan 2021 17:50:42 +0000 |
| parents | 270025e76bf8 |
| children | f6da234b21b8 |
comparison
equal
deleted
inserted
replaced
| 4350:270025e76bf8 | 4351:c0b1b2a61e3c |
|---|---|
| 93 event.response.headers["Content-Type"] = json_content_type; | 93 event.response.headers["Content-Type"] = json_content_type; |
| 94 return json.encode(token_info_to_invite_info(invite)); | 94 return json.encode(token_info_to_invite_info(invite)); |
| 95 end | 95 end |
| 96 | 96 |
| 97 function create_invite(event) | 97 function create_invite(event) |
| 98 local invite = invites.create_account(nil, { source = "admin_api/"..event.session.username }); | 98 local invite_options; |
| 99 | |
| 100 local request = event.request; | |
| 101 if request.body and #request.body > 0 then | |
| 102 if request.headers.content_type ~= json_content_type then | |
| 103 module:log("warn", "Invalid content type"); | |
| 104 return 400; | |
| 105 end | |
| 106 invite_options = json.decode(event.request.body); | |
| 107 if not invite_options then | |
| 108 module:log("warn", "Invalid JSON"); | |
| 109 return 400; | |
| 110 end | |
| 111 end | |
| 112 | |
| 113 local invite; | |
| 114 if invite_options and invite_options.reusable then | |
| 115 invite = invites.create_group(invite_options.group, invite_options.ttl, { | |
| 116 source = "admin_api/"..event.session.username; | |
| 117 }); | |
| 118 else | |
| 119 invite = invites.create_account(nil, { | |
| 120 source = "admin_api/"..event.session.username; | |
| 121 groups = { invite_options.group }; | |
| 122 }); | |
| 123 end | |
| 99 if not invite then | 124 if not invite then |
| 100 return 500; | 125 return 500; |
| 101 end | 126 end |
| 102 | 127 |
| 103 event.response.headers["Content-Type"] = json_content_type; | 128 event.response.headers["Content-Type"] = json_content_type; |
