Software /
code /
prosody-modules
Annotate
mod_invites/mod_invites.lua @ 4346:671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 17 Jan 2021 17:42:49 +0000 |
parent | 4344:844cfc8c4039 |
child | 4347:0ec482e617bb |
rev | line source |
---|---|
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local id = require "util.id"; |
4341
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
2 local it = require "util.iterators"; |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 local url = require "socket.url"; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 local jid_node = require "util.jid".node; |
4096
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
5 local jid_split = require "util.jid".split; |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
4346
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
7 local default_ttl = module:get_option_number("invite_expiry", 86400 * 7); |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
4096
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
9 local token_storage; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
10 if prosody.process_type == "prosody" or prosody.shutdown then |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
11 token_storage = module:open_store("invite_token", "map"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
12 end |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local function get_uri(action, jid, token, params) --> string |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 return url.build({ |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 scheme = "xmpp", |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 path = jid, |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 query = action..";preauth="..token..(params and (";"..params) or ""), |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 }); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
4346
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
22 local function create_invite(invite_action, invite_jid, allow_registration, additional_data, ttl, reusable) |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local token = id.medium(); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 local created_at = os.time(); |
4346
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
26 local expires = created_at + (ttl or default_ttl); |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 local invite_params = (invite_action == "roster" and allow_registration) and "ibr=y" or nil; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 local invite = { |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 type = invite_action; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 jid = invite_jid; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 token = token; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 allow_registration = allow_registration; |
4077
f85ea76447dd
mod_invites: Allow inclusion of 'additional data' in invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
3776
diff
changeset
|
36 additional_data = additional_data; |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 uri = get_uri(invite_action, invite_jid, token, invite_params); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 created_at = created_at; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 expires = expires; |
4346
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
42 |
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
43 reusable = reusable; |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 }; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 module:fire_event("invite-created", invite); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 if allow_registration then |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 local ok, err = token_storage:set(nil, token, invite); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 if not ok then |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 module:log("warn", "Failed to store account invite: %s", err); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 return nil, "internal-server-error"; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 if invite_action == "roster" then |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 local username = jid_node(invite_jid); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 local ok, err = token_storage:set(username, token, expires); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 if not ok then |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 module:log("warn", "Failed to store subscription invite: %s", err); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 return nil, "internal-server-error"; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 return invite; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 -- Create invitation to register an account (optionally restricted to the specified username) |
4077
f85ea76447dd
mod_invites: Allow inclusion of 'additional data' in invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
3776
diff
changeset
|
69 function create_account(account_username, additional_data) --luacheck: ignore 131/create_account |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 local jid = account_username and (account_username.."@"..module.host) or module.host; |
4077
f85ea76447dd
mod_invites: Allow inclusion of 'additional data' in invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
3776
diff
changeset
|
71 return create_invite("register", jid, true, additional_data); |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 |
4078
2f0c8670d2fa
mod_invites: Add API to create account reset invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4077
diff
changeset
|
74 -- Create invitation to reset the password for an account |
2f0c8670d2fa
mod_invites: Add API to create account reset invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4077
diff
changeset
|
75 function create_account_reset(account_username) --luacheck: ignore 131/create_account_reset |
2f0c8670d2fa
mod_invites: Add API to create account reset invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4077
diff
changeset
|
76 return create_account(account_username, { allow_reset = account_username }); |
2f0c8670d2fa
mod_invites: Add API to create account reset invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4077
diff
changeset
|
77 end |
2f0c8670d2fa
mod_invites: Add API to create account reset invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4077
diff
changeset
|
78 |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 -- Create invitation to become a contact of a local user |
4077
f85ea76447dd
mod_invites: Allow inclusion of 'additional data' in invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
3776
diff
changeset
|
80 function create_contact(username, allow_registration, additional_data) --luacheck: ignore 131/create_contact |
f85ea76447dd
mod_invites: Allow inclusion of 'additional data' in invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
3776
diff
changeset
|
81 return create_invite("roster", username.."@"..module.host, allow_registration, additional_data); |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 |
4341
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
84 -- Iterates pending (non-expired, unused) invites that allow registration |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
85 function pending_account_invites() --luacheck: ignore 131/pending_account_invites |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
86 local store = module:open_store("invite_token"); |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
87 local now = os.time(); |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
88 local function is_valid_invite(_, invite) |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
89 return invite.expires > now; |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
90 end |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
91 return it.filter(is_valid_invite, pairs(store:get(nil) or {})); |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
92 end |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
93 |
4344
844cfc8c4039
mod_invites: Fix some more luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
4342
diff
changeset
|
94 function get_account_invite_info(token) --luacheck: ignore 131/get_account_invite_info |
4341
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
95 if not token then |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
96 return nil, "no-token"; |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
97 end |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
98 |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
99 -- Fetch from host store (account invite) |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
100 local token_info = token_storage:get(nil, token); |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
101 if not token_info then |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
102 return nil, "token-invalid"; |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
103 elseif os.time() > token_info.expires then |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
104 return nil, "token-expired"; |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
105 end |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
106 |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
107 return token_info; |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
108 end |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
109 |
4344
844cfc8c4039
mod_invites: Fix some more luacheck warnings
Matthew Wild <mwild1@gmail.com>
parents:
4342
diff
changeset
|
110 function delete_account_invite(token) --luacheck: ignore 131/delete_account_invite |
4341
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
111 if not token then |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
112 return nil, "no-token"; |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
113 end |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
114 |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
115 return token_storage:set(nil, token, nil); |
a104440c20a4
mod_invites: Add internal API to list, read and delete account invites
Matthew Wild <mwild1@gmail.com>
parents:
4096
diff
changeset
|
116 end |
4080
14a3f5223074
mod_invites: Whitespace (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4079
diff
changeset
|
117 |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 local valid_invite_methods = {}; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 local valid_invite_mt = { __index = valid_invite_methods }; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 function valid_invite_methods:use() |
4346
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
122 if self.reusable then |
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
123 return true; |
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
124 end |
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
125 |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 if self.username then |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 -- Also remove the contact invite if present, on the |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 -- assumption that they now have a mutual subscription |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 token_storage:set(self.username, self.token, nil); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 token_storage:set(nil, self.token, nil); |
4096
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
132 |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 return true; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 -- Get a validated invite (or nil, err). Must call :use() on the |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 -- returned invite after it is actually successfully used |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 -- For "roster" invites, the username of the local user (who issued |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 -- the invite) must be passed. |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 -- If no username is passed, but the registration is a roster invite |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 -- from a local user, the "inviter" field of the returned invite will |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 -- be set to their username. |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 function get(token, username) |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 if not token then |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 return nil, "no-token"; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 local valid_until, inviter; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 |
4079
b68b917e568f
mod_invites: Include invite type and uri in validated invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4078
diff
changeset
|
150 -- Fetch from host store (account invite) |
b68b917e568f
mod_invites: Include invite type and uri in validated invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4078
diff
changeset
|
151 local token_info = token_storage:get(nil, token); |
b68b917e568f
mod_invites: Include invite type and uri in validated invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4078
diff
changeset
|
152 |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 if username then -- token being used for subscription |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 -- Fetch from user store (subscription invite) |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 valid_until = token_storage:get(username, token); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 else -- token being used for account creation |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 valid_until = token_info and token_info.expires; |
4081
3c18d8deeb38
mod_invites: Fix potential traceback when invalid token used (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4080
diff
changeset
|
158 if token_info and token_info.type == "roster" then |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 username = jid_node(token_info.jid); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 inviter = username; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 if not valid_until then |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 module:log("debug", "Got unknown token: %s", token); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 return nil, "token-invalid"; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 elseif os.time() > valid_until then |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 module:log("debug", "Got expired token: %s", token); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 return nil, "token-expired"; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 return setmetatable({ |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 token = token; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 username = username; |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 inviter = inviter; |
4079
b68b917e568f
mod_invites: Include invite type and uri in validated invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4078
diff
changeset
|
176 type = token_info and token_info.type or "roster"; |
b68b917e568f
mod_invites: Include invite type and uri in validated invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
4078
diff
changeset
|
177 uri = token_info and token_info.uri or get_uri("roster", username.."@"..module.host, token); |
4077
f85ea76447dd
mod_invites: Allow inclusion of 'additional data' in invites (from Snikket)
Matthew Wild <mwild1@gmail.com>
parents:
3776
diff
changeset
|
178 additional_data = token_info and token_info.additional_data or nil; |
4346
671bc55f0fc9
mod_invites: Add support to internal API for creating reusable and custom-TTL invites
Matthew Wild <mwild1@gmail.com>
parents:
4344
diff
changeset
|
179 reusable = token_info.reusable; |
3776
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 }, valid_invite_mt); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 end |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 function use(token) --luacheck: ignore 131/use |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 local invite = get(token); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 return invite and invite:use(); |
80830d97da81
mod_invites: New module providing an API to create/manage invite tokens
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 end |
4096
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
187 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
188 --- shell command |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
189 do |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
190 -- Since the console is global this overwrites the command for |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
191 -- each host it's loaded on, but this should be fine. |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
192 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
193 local get_module = require "core.modulemanager".get_module; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
194 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
195 local console_env = module:shared("/*/admin_shell/env"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
196 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
197 -- luacheck: ignore 212/self |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
198 console_env.invite = {}; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
199 function console_env.invite:create_account(user_jid) |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
200 local username, host = jid_split(user_jid); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
201 local mod_invites, err = get_module(host, "invites"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
202 if not mod_invites then return nil, err or "mod_invites not loaded on this host"; end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
203 local invite, err = mod_invites.create_account(username); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
204 if not invite then return nil, err; end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
205 return true, invite.uri; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
206 end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
207 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
208 function console_env.invite:create_contact(user_jid, allow_registration) |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
209 local username, host = jid_split(user_jid); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
210 local mod_invites, err = get_module(host, "invites"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
211 if not mod_invites then return nil, err or "mod_invites not loaded on this host"; end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
212 local invite, err = mod_invites.create_contact(username, allow_registration); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
213 if not invite then return nil, err; end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
214 return true, invite.uri; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
215 end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
216 end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
217 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
218 --- prosodyctl command |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
219 function module.command(arg) |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
220 if #arg < 2 or arg[1] ~= "generate" then |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
221 print("usage: prosodyctl mod_"..module.name.." generate example.com"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
222 return; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
223 end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
224 table.remove(arg, 1); -- pop command |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
225 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
226 local sm = require "core.storagemanager"; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
227 local mm = require "core.modulemanager"; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
228 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
229 local host = arg[1]; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
230 assert(hosts[host], "Host "..tostring(host).." does not exist"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
231 sm.initialize_host(host); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
232 table.remove(arg, 1); -- pop host |
4342
84e60c3d6e61
mod_invites: Fix luacheck warning
Matthew Wild <mwild1@gmail.com>
parents:
4341
diff
changeset
|
233 module.host = host; --luacheck: ignore 122/module |
4096
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
234 token_storage = module:open_store("invite_token", "map"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
235 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
236 -- Load mod_invites |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
237 local invites = module:depends("invites"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
238 local invites_page_module = module:get_option_string("invites_page_module", "invites_page"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
239 if mm.get_modules_for_host(host):contains(invites_page_module) then |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
240 module:depends(invites_page_module); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
241 end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
242 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
243 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
244 local invite, roles; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
245 if arg[1] == "--reset" then |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
246 local nodeprep = require "util.encodings".stringprep.nodeprep; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
247 local username = nodeprep(arg[2]); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
248 if not username then |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
249 print("Please supply a valid username to generate a reset link for"); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
250 return; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
251 end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
252 invite = assert(invites.create_account_reset(username)); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
253 else |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
254 if arg[1] == "--admin" then |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
255 roles = { ["prosody:admin"] = true }; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
256 elseif arg[1] == "--role" then |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
257 roles = { [arg[2]] = true }; |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
258 end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
259 invite = assert(invites.create_account(nil, { roles = roles })); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
260 end |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
261 |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
262 print(invite.landing_page or invite.uri); |
24f4eb35ab60
mod_invites: Absorb shell and prosodyctl commands from mod_easy_invite
Matthew Wild <mwild1@gmail.com>
parents:
4081
diff
changeset
|
263 end |