Software /
code /
prosody-modules
Changeset
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 | 4350:270025e76bf8 |
children | 4352:f6da234b21b8 |
files | mod_http_admin_api/mod_http_admin_api.lua |
diffstat | 1 files changed, 26 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mod_http_admin_api/mod_http_admin_api.lua Sun Jan 17 17:46:47 2021 +0000 +++ b/mod_http_admin_api/mod_http_admin_api.lua Sun Jan 17 17:50:42 2021 +0000 @@ -95,7 +95,32 @@ end function create_invite(event) - local invite = invites.create_account(nil, { source = "admin_api/"..event.session.username }); + local invite_options; + + local request = event.request; + if request.body and #request.body > 0 then + if request.headers.content_type ~= json_content_type then + module:log("warn", "Invalid content type"); + return 400; + end + invite_options = json.decode(event.request.body); + if not invite_options then + module:log("warn", "Invalid JSON"); + return 400; + end + end + + local invite; + if invite_options and invite_options.reusable then + invite = invites.create_group(invite_options.group, invite_options.ttl, { + source = "admin_api/"..event.session.username; + }); + else + invite = invites.create_account(nil, { + source = "admin_api/"..event.session.username; + groups = { invite_options.group }; + }); + end if not invite then return 500; end