Mercurial > prosody-modules
comparison mod_invites/mod_invites.lua @ 4077:f85ea76447dd
mod_invites: Allow inclusion of 'additional data' in invites (from Snikket)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 07 Sep 2020 12:59:00 +0100 |
parents | 80830d97da81 |
children | 2f0c8670d2fa |
comparison
equal
deleted
inserted
replaced
4076:f1f796e551f1 | 4077:f85ea76447dd |
---|---|
12 path = jid, | 12 path = jid, |
13 query = action..";preauth="..token..(params and (";"..params) or ""), | 13 query = action..";preauth="..token..(params and (";"..params) or ""), |
14 }); | 14 }); |
15 end | 15 end |
16 | 16 |
17 local function create_invite(invite_action, invite_jid, allow_registration) | 17 local function create_invite(invite_action, invite_jid, allow_registration, additional_data) |
18 local token = id.medium(); | 18 local token = id.medium(); |
19 | 19 |
20 local created_at = os.time(); | 20 local created_at = os.time(); |
21 local expires = created_at + invite_ttl; | 21 local expires = created_at + invite_ttl; |
22 | 22 |
26 type = invite_action; | 26 type = invite_action; |
27 jid = invite_jid; | 27 jid = invite_jid; |
28 | 28 |
29 token = token; | 29 token = token; |
30 allow_registration = allow_registration; | 30 allow_registration = allow_registration; |
31 additional_data = additional_data; | |
31 | 32 |
32 uri = get_uri(invite_action, invite_jid, token, invite_params); | 33 uri = get_uri(invite_action, invite_jid, token, invite_params); |
33 | 34 |
34 created_at = created_at; | 35 created_at = created_at; |
35 expires = expires; | 36 expires = expires; |
56 | 57 |
57 return invite; | 58 return invite; |
58 end | 59 end |
59 | 60 |
60 -- Create invitation to register an account (optionally restricted to the specified username) | 61 -- Create invitation to register an account (optionally restricted to the specified username) |
61 function create_account(account_username) --luacheck: ignore 131/create_account | 62 function create_account(account_username, additional_data) --luacheck: ignore 131/create_account |
62 local jid = account_username and (account_username.."@"..module.host) or module.host; | 63 local jid = account_username and (account_username.."@"..module.host) or module.host; |
63 return create_invite("register", jid, true); | 64 return create_invite("register", jid, true, additional_data); |
64 end | 65 end |
65 | 66 |
66 -- Create invitation to become a contact of a local user | 67 -- Create invitation to become a contact of a local user |
67 function create_contact(username, allow_registration) --luacheck: ignore 131/create_contact | 68 function create_contact(username, allow_registration, additional_data) --luacheck: ignore 131/create_contact |
68 return create_invite("roster", username.."@"..module.host, allow_registration); | 69 return create_invite("roster", username.."@"..module.host, allow_registration, additional_data); |
69 end | 70 end |
70 | 71 |
71 local valid_invite_methods = {}; | 72 local valid_invite_methods = {}; |
72 local valid_invite_mt = { __index = valid_invite_methods }; | 73 local valid_invite_mt = { __index = valid_invite_methods }; |
73 | 74 |
118 | 119 |
119 return setmetatable({ | 120 return setmetatable({ |
120 token = token; | 121 token = token; |
121 username = username; | 122 username = username; |
122 inviter = inviter; | 123 inviter = inviter; |
124 additional_data = token_info and token_info.additional_data or nil; | |
123 }, valid_invite_mt); | 125 }, valid_invite_mt); |
124 end | 126 end |
125 | 127 |
126 function use(token) --luacheck: ignore 131/use | 128 function use(token) --luacheck: ignore 131/use |
127 local invite = get(token); | 129 local invite = get(token); |