Mercurial > prosody-hg
annotate plugins/mod_invites.lua @ 13946:f5e8ab42c708
mod_http_file_share: Check that files are still there with correct size
Failed uploads can leave behind unused slots. Files shouldn't change
size after they have been successfully uploaded, but might as well
double check it.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 04 Dec 2021 18:56:51 +0100 |
| parents | b019a30cc1b2 |
| children | 42e035cd3322 |
| rev | line source |
|---|---|
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12834
diff
changeset
|
1 local id = require "prosody.util.id"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12834
diff
changeset
|
2 local it = require "prosody.util.iterators"; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local url = require "socket.url"; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12834
diff
changeset
|
4 local jid_node = require "prosody.util.jid".node; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12834
diff
changeset
|
5 local jid_split = require "prosody.util.jid".split; |
|
13161
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
6 local argparse = require "prosody.util.argparse"; |
|
13410
7efdd143fdfc
mod_invites: Allow specifying invite ttl on command line
Kim Alvefur <zash@zash.se>
parents:
13355
diff
changeset
|
7 local human_io = require "prosody.util.human.io"; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
|
13701
1aa7efabeacb
mod_cloud_notify, mod_cron, mod_invites: Add 'prosody.' prefix to requires
Matthew Wild <mwild1@gmail.com>
parents:
13674
diff
changeset
|
9 local url_escape = require "prosody.util.http".urlencode; |
|
1aa7efabeacb
mod_cloud_notify, mod_cron, mod_invites: Add 'prosody.' prefix to requires
Matthew Wild <mwild1@gmail.com>
parents:
13674
diff
changeset
|
10 local render_url = require "prosody.util.interpolation".new("%b{}", url_escape, { |
|
13613
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
11 urlescape = url_escape; |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
12 noscheme = function (urlstring) |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
13 return (urlstring:gsub("^[^:]+:", "")); |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
14 end; |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
15 }); |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
16 |
|
13209
c8d949cf6b09
plugins: Switch to :get_option_period() for time range options
Kim Alvefur <zash@zash.se>
parents:
13161
diff
changeset
|
17 local default_ttl = module:get_option_period("invite_expiry", "1 week"); |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local token_storage; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 if prosody.process_type == "prosody" or prosody.shutdown then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 token_storage = module:open_store("invite_token", "map"); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 local function get_uri(action, jid, token, params) --> string |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 return url.build({ |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 scheme = "xmpp", |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 path = jid, |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 query = action..";preauth="..token..(params and (";"..params) or ""), |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 }); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 local function create_invite(invite_action, invite_jid, allow_registration, additional_data, ttl, reusable) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 local token = id.medium(); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 local created_at = os.time(); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 local expires = created_at + (ttl or default_ttl); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 local invite_params = (invite_action == "roster" and allow_registration) and "ibr=y" or nil; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 local invite = { |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 type = invite_action; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 jid = invite_jid; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 token = token; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 allow_registration = allow_registration; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 additional_data = additional_data; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 uri = get_uri(invite_action, invite_jid, token, invite_params); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 created_at = created_at; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 expires = expires; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 reusable = reusable; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 }; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 module:fire_event("invite-created", invite); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 if allow_registration then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 local ok, err = token_storage:set(nil, token, invite); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 if not ok then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 module:log("warn", "Failed to store account invite: %s", err); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 return nil, "internal-server-error"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
65 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 if invite_action == "roster" then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 local username = jid_node(invite_jid); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 local ok, err = token_storage:set(username, token, expires); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 if not ok then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 module:log("warn", "Failed to store subscription invite: %s", err); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 return nil, "internal-server-error"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 return invite; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 -- Create invitation to register an account (optionally restricted to the specified username) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 function create_account(account_username, additional_data, ttl) --luacheck: ignore 131/create_account |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 local jid = account_username and (account_username.."@"..module.host) or module.host; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 return create_invite("register", jid, true, additional_data, ttl); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 -- Create invitation to reset the password for an account |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 function create_account_reset(account_username, ttl) --luacheck: ignore 131/create_account_reset |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 return create_account(account_username, { allow_reset = account_username }, ttl or 86400); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 -- Create invitation to become a contact of a local user |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 function create_contact(username, allow_registration, additional_data, ttl) --luacheck: ignore 131/create_contact |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 return create_invite("roster", username.."@"..module.host, allow_registration, additional_data, ttl); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
92 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 -- Create invitation to register an account and join a user group |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 -- If explicit ttl is passed, invite is valid for multiple signups |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 -- during that time period |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 function create_group(group_ids, additional_data, ttl) --luacheck: ignore 131/create_group |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 local merged_additional_data = { |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 groups = group_ids; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 }; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 if additional_data then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 for k, v in pairs(additional_data) do |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 merged_additional_data[k] = v; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
105 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
106 return create_invite("register", module.host, true, merged_additional_data, ttl, not not ttl); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
108 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 -- Iterates pending (non-expired, unused) invites that allow registration |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 function pending_account_invites() --luacheck: ignore 131/pending_account_invites |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
111 local store = module:open_store("invite_token"); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
112 local now = os.time(); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 local function is_valid_invite(_, invite) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 return invite.expires > now; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 return it.filter(is_valid_invite, pairs(store:get(nil) or {})); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
118 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 function get_account_invite_info(token) --luacheck: ignore 131/get_account_invite_info |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 if not token then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
121 return nil, "no-token"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 -- Fetch from host store (account invite) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 local token_info = token_storage:get(nil, token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 if not token_info then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 return nil, "token-invalid"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 elseif os.time() > token_info.expires then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
129 return nil, "token-expired"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
130 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
131 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 return token_info; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 function delete_account_invite(token) --luacheck: ignore 131/delete_account_invite |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 if not token then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
137 return nil, "no-token"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 return token_storage:set(nil, token, nil); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 local valid_invite_methods = {}; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 local valid_invite_mt = { __index = valid_invite_methods }; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 function valid_invite_methods:use() |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 if self.reusable then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 return true; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 if self.username then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 -- Also remove the contact invite if present, on the |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 -- assumption that they now have a mutual subscription |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
154 token_storage:set(self.username, self.token, nil); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
156 token_storage:set(nil, self.token, nil); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
157 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
158 return true; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
159 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
161 -- Get a validated invite (or nil, err). Must call :use() on the |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
162 -- returned invite after it is actually successfully used |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
163 -- For "roster" invites, the username of the local user (who issued |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
164 -- the invite) must be passed. |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
165 -- If no username is passed, but the registration is a roster invite |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
166 -- from a local user, the "inviter" field of the returned invite will |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
167 -- be set to their username. |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
168 function get(token, username) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
169 if not token then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
170 return nil, "no-token"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
171 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
172 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
173 local valid_until, inviter; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
174 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
175 -- Fetch from host store (account invite) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
176 local token_info = token_storage:get(nil, token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
177 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
178 if username then -- token being used for subscription |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
179 -- Fetch from user store (subscription invite) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
180 valid_until = token_storage:get(username, token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
181 else -- token being used for account creation |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
182 valid_until = token_info and token_info.expires; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
183 if token_info and token_info.type == "roster" then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
184 username = jid_node(token_info.jid); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
185 inviter = username; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
186 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
187 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
188 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
189 if not valid_until then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
190 module:log("debug", "Got unknown token: %s", token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
191 return nil, "token-invalid"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
192 elseif os.time() > valid_until then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
193 module:log("debug", "Got expired token: %s", token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
194 return nil, "token-expired"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
195 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
196 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
197 return setmetatable({ |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
198 token = token; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
199 username = username; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
200 inviter = inviter; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
201 type = token_info and token_info.type or "roster"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
202 uri = token_info and token_info.uri or get_uri("roster", username.."@"..module.host, token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
203 additional_data = token_info and token_info.additional_data or nil; |
|
13519
0b6af170617b
mod_invites: Fix traceback when token_info isn’t set
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
12834
diff
changeset
|
204 reusable = token_info and token_info.reusable or false; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
205 }, valid_invite_mt); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
206 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
207 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
208 function use(token) --luacheck: ignore 131/use |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
209 local invite = get(token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
210 return invite and invite:use(); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
211 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
212 |
|
13613
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
213 -- Point at e.g. a deployment of https://github.com/modernxmpp/easy-xmpp-invitation |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
214 -- This URL must always be absolute, as it is shared standalone |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
215 local invite_url_template = module:get_option_string("invites_page"); |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
216 local invites_page_supports = module:get_option_set("invites_page_supports", { "account", "contact", "account-and-contact" }); |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
217 |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
218 local function add_landing_url(invite) |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
219 if not invite_url_template or invite.landing_page then return; end |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
220 |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
221 -- Determine whether this type of invitation is supported by the landing page |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
222 local invite_type; |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
223 if invite.type == "register" then |
|
13851
ecafafec7806
mod_invites: Consider password reset a distinct type wrt invite page
Kim Alvefur <zash@zash.se>
parents:
13741
diff
changeset
|
224 if invite.additional_data and invite.additional_data.allow_reset then |
|
ecafafec7806
mod_invites: Consider password reset a distinct type wrt invite page
Kim Alvefur <zash@zash.se>
parents:
13741
diff
changeset
|
225 invite_type = "password-reset"; |
|
ecafafec7806
mod_invites: Consider password reset a distinct type wrt invite page
Kim Alvefur <zash@zash.se>
parents:
13741
diff
changeset
|
226 else |
|
ecafafec7806
mod_invites: Consider password reset a distinct type wrt invite page
Kim Alvefur <zash@zash.se>
parents:
13741
diff
changeset
|
227 invite_type = "account"; |
|
ecafafec7806
mod_invites: Consider password reset a distinct type wrt invite page
Kim Alvefur <zash@zash.se>
parents:
13741
diff
changeset
|
228 end |
|
13613
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
229 elseif invite.type == "roster" then |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
230 if invite.allow_registration then |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
231 invite_type = "account-and-contact"; |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
232 else |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
233 invite_type = "contact-only"; |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
234 end |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
235 end |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
236 if not invites_page_supports:contains(invite_type) then |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
237 return; -- Invitation type unsupported |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
238 end |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
239 |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
240 invite.landing_page = render_url(invite_url_template, { host = module.host, invite = invite }); |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
241 end |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
242 |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
243 module:hook("invite-created", add_landing_url, -1); |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
244 |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
245 --- shell command |
|
13741
e9edf9b50f32
mod_invites: Hide --group flag unless mod_invites_groups is enabled
Matthew Wild <mwild1@gmail.com>
parents:
13740
diff
changeset
|
246 -- COMPAT: Dynamic groups are work in progress as of 13.0, so we'll use the |
|
e9edf9b50f32
mod_invites: Hide --group flag unless mod_invites_groups is enabled
Matthew Wild <mwild1@gmail.com>
parents:
13740
diff
changeset
|
247 -- presence of mod_invites_groups (a community module) to determine whether to |
|
e9edf9b50f32
mod_invites: Hide --group flag unless mod_invites_groups is enabled
Matthew Wild <mwild1@gmail.com>
parents:
13740
diff
changeset
|
248 -- expose our support for invites to groups. |
|
e9edf9b50f32
mod_invites: Hide --group flag unless mod_invites_groups is enabled
Matthew Wild <mwild1@gmail.com>
parents:
13740
diff
changeset
|
249 local have_group_invites = module:get_option_inherited_set("modules_enabled"):contains("invites_groups"); |
|
e9edf9b50f32
mod_invites: Hide --group flag unless mod_invites_groups is enabled
Matthew Wild <mwild1@gmail.com>
parents:
13740
diff
changeset
|
250 |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
251 module:add_item("shell-command", { |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
252 section = "invite"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
253 section_desc = "Create and manage invitations"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
254 name = "create_account"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
255 desc = "Create an invitation to make an account on this server with the specified JID (supply only a hostname to allow any username)"; |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
256 args = { |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
257 { name = "user_jid", type = "string" }; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
258 }; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
259 host_selector = "user_jid"; |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
260 flags = { |
|
13741
e9edf9b50f32
mod_invites: Hide --group flag unless mod_invites_groups is enabled
Matthew Wild <mwild1@gmail.com>
parents:
13740
diff
changeset
|
261 array_params = { role = true, group = have_group_invites }; |
|
13896
17b5a10bd9c9
mod_invites: Fix --admin to not require a value
Kim Alvefur <zash@zash.se>
parents:
13892
diff
changeset
|
262 value_params = { expires_after = true }; |
|
13899
b019a30cc1b2
mod_invites: Switch to new bool_params for util.argparse
Matthew Wild <mwild1@gmail.com>
parents:
13896
diff
changeset
|
263 bool_params = { admin = true }; |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
264 }; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
265 |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
266 handler = function (self, user_jid, opts) --luacheck: ignore 212/self |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
267 local username = jid_split(user_jid); |
|
13740
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
268 local roles = opts and opts.role or {}; |
|
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
269 local groups = opts and opts.group or {}; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
270 |
|
13740
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
271 if opts and opts.admin then |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
272 -- Insert it first since we don't get order out of argparse |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
273 table.insert(roles, 1, "prosody:admin"); |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
274 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
275 |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
276 local ttl; |
|
13740
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
277 if opts and opts.expires_after then |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
278 ttl = human_io.parse_duration(opts.expires_after); |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
279 if not ttl then |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
280 return false, "Unable to parse duration: "..opts.expires_after; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
281 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
282 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
283 |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
284 local invite = assert(create_account(username, { |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
285 roles = roles; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
286 groups = groups; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
287 }, ttl)); |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
288 |
|
12834
dcbff9f038a0
mod_invites: Prefer landing page over xmpp URI in shell command
Kim Alvefur <zash@zash.se>
parents:
12151
diff
changeset
|
289 return true, invite.landing_page or invite.uri; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
290 end; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
291 }); |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
292 |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
293 module:add_item("shell-command", { |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
294 section = "invite"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
295 section_desc = "Create and manage invitations"; |
|
13673
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
296 name = "create_reset"; |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
297 desc = "Create a password reset link for the specified user"; |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
298 args = { { name = "user_jid", type = "string" } }; |
|
13673
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
299 host_selector = "user_jid"; |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
300 flags = { |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
301 value_params = { expires_after = true }; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
302 }; |
|
13673
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
303 |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
304 handler = function (self, user_jid, opts) --luacheck: ignore 212/self |
|
13673
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
305 local username = jid_split(user_jid); |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
306 if not username then |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
307 return nil, "Supply the JID of the account you want to generate a password reset for"; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
308 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
309 local duration_sec = require "prosody.util.human.io".parse_duration(opts and opts.expires_after or "1d"); |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
310 if not duration_sec then |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
311 return nil, "Unable to parse duration: "..opts.expires_after; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
312 end |
|
13673
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
313 local invite, err = create_account_reset(username, duration_sec); |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
314 if not invite then return nil, err; end |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
315 self.session.print(invite.landing_page or invite.uri); |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
316 return true, ("Password reset link for %s valid until %s"):format(user_jid, os.date("%Y-%m-%d %T", invite.expires)); |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
317 end; |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
318 }); |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
319 |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
320 module:add_item("shell-command", { |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
321 section = "invite"; |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
322 section_desc = "Create and manage invitations"; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
323 name = "create_contact"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
324 desc = "Create an invitation to become contacts with the specified user"; |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
325 args = { { name = "user_jid", type = "string" } }; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
326 host_selector = "user_jid"; |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
327 flags = { |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
328 value_params = { expires_after = true }; |
|
13899
b019a30cc1b2
mod_invites: Switch to new bool_params for util.argparse
Matthew Wild <mwild1@gmail.com>
parents:
13896
diff
changeset
|
329 bool_params = { allow_registration = true }; |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
330 }; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
331 |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
332 handler = function (self, user_jid, opts) --luacheck: ignore 212/self |
|
13355
a6c8a50cdfb5
mod_invites: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents:
13353
diff
changeset
|
333 local username = jid_split(user_jid); |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
334 if not username then |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
335 return nil, "Supply the JID of the account you want the recipient to become a contact of"; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
336 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
337 local ttl; |
|
13740
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
338 if opts and opts.expires_after then |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
339 ttl = require "prosody.util.human.io".parse_duration(opts.expires_after); |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
340 if not ttl then |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
341 return nil, "Unable to parse duration: "..opts.expires_after; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
342 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
343 end |
|
13740
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
344 local invite, err = create_contact(username, opts and opts.allow_registration, nil, ttl); |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
345 if not invite then return nil, err; end |
|
12834
dcbff9f038a0
mod_invites: Prefer landing page over xmpp URI in shell command
Kim Alvefur <zash@zash.se>
parents:
12151
diff
changeset
|
346 return true, invite.landing_page or invite.uri; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
347 end; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
348 }); |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
349 |
|
13674
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
350 module:add_item("shell-command", { |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
351 section = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
352 section_desc = "Create and manage invitations"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
353 name = "show"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
354 desc = "Show details of an account invitation token"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
355 args = { { name = "host", type = "string" }, { name = "token", type = "string" } }; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
356 host_selector = "host"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
357 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
358 handler = function (self, host, token) --luacheck: ignore 212/self 212/host |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
359 local invite, err = get_account_invite_info(token); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
360 if not invite then return nil, err; end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
361 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
362 local print = self.session.print; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
363 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
364 if invite.type == "roster" then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
365 print("Invitation to register and become a contact of "..invite.jid); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
366 elseif invite.type == "register" then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
367 local jid_user, jid_host = jid_split(invite.jid); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
368 if invite.additional_data and invite.additional_data.allow_reset then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
369 print("Password reset for "..invite.additional_data.allow_reset.."@"..jid_host); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
370 elseif jid_user then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
371 print("Invitation to register on "..jid_host.." with username '"..jid_user.."'"); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
372 else |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
373 print("Invitation to register on "..jid_host); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
374 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
375 else |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
376 print("Unknown invitation type"); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
377 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
378 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
379 if invite.inviter then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
380 print("Creator:", invite.inviter); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
381 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
382 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
383 print("Created:", os.date("%Y-%m-%d %T", invite.created_at)); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
384 print("Expires:", os.date("%Y-%m-%d %T", invite.expires)); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
385 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
386 print(""); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
387 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
388 if invite.uri then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
389 print("XMPP URI:", invite.uri); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
390 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
391 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
392 if invite.landing_page then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
393 print("Web link:", invite.landing_page); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
394 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
395 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
396 if invite.additional_data then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
397 print(""); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
398 if invite.additional_data.roles then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
399 if invite.additional_data.roles[1] then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
400 print("Role:", invite.additional_data.roles[1]); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
401 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
402 if invite.additional_data.roles[2] then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
403 print("Secondary roles:", table.concat(invite.additional_data.roles, ", ", 2, #invite.additional_data.roles)); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
404 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
405 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
406 if invite.additional_data.groups then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
407 print("Groups:", table.concat(invite.additional_data.groups, ", ")); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
408 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
409 if invite.additional_data.note then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
410 print("Comment:", invite.additional_data.note); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
411 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
412 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
413 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
414 return true, "Invitation valid"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
415 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
416 }); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
417 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
418 module:add_item("shell-command", { |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
419 section = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
420 section_desc = "Create and manage invitations"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
421 name = "delete"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
422 desc = "Delete/revoke an invitation token"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
423 args = { { name = "host", type = "string" }, { name = "token", type = "string" } }; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
424 host_selector = "host"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
425 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
426 handler = function (self, host, token) --luacheck: ignore 212/self 212/host |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
427 local invite, err = delete_account_invite(token); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
428 if not invite then return nil, err; end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
429 return true, "Invitation deleted"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
430 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
431 }); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
432 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
433 module:add_item("shell-command", { |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
434 section = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
435 section_desc = "Create and manage invitations"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
436 name = "list"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
437 desc = "List pending invitations which allow account registration"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
438 args = { { name = "host", type = "string" } }; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
439 host_selector = "host"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
440 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
441 handler = function (self, host) -- luacheck: ignore 212/host |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
442 local print_row = human_io.table({ |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
443 { |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
444 title = "Token"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
445 key = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
446 width = 24; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
447 mapper = function (invite) |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
448 return invite.token; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
449 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
450 }; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
451 { |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
452 title = "Expires"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
453 key = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
454 width = 20; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
455 mapper = function (invite) |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
456 return os.date("%Y-%m-%dT%T", invite.expires); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
457 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
458 }; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
459 { |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
460 title = "Description"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
461 key = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
462 width = "100%"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
463 mapper = function (invite) |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
464 if invite.type == "roster" then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
465 return "Contact with "..invite.jid; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
466 elseif invite.type == "register" then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
467 local jid_user, jid_host = jid_split(invite.jid); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
468 if invite.additional_data and invite.additional_data.allow_reset then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
469 return "Password reset for "..invite.additional_data.allow_reset.."@"..jid_host; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
470 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
471 if jid_user then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
472 return "Register on "..jid_host.." with username "..jid_user; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
473 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
474 return "Register on "..jid_host; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
475 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
476 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
477 }; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
478 }, self.session.width); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
479 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
480 self.session.print(print_row()); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
481 local count = 0; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
482 for _, invite in pending_account_invites() do |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
483 count = count + 1; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
484 self.session.print(print_row({ invite = invite })); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
485 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
486 return true, ("%d pending invites"):format(count); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
487 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
488 }); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
489 |
|
13161
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
490 local subcommands = {}; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
491 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
492 --- prosodyctl command |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
493 function module.command(arg) |
|
13161
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
494 local opts = argparse.parse(arg, { short_params = { h = "help"; ["?"] = "help" } }); |
|
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
495 local cmd = table.remove(arg, 1); -- pop command |
|
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
496 if opts.help or not cmd or not subcommands[cmd] then |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
497 print("usage: prosodyctl mod_"..module.name.." generate example.com"); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
498 return 2; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
499 end |
|
13161
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
500 return subcommands[cmd](arg); |
|
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
501 end |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
502 |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
503 function subcommands.generate() |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
504 print("This command is deprecated. Please see 'prosodyctl shell help invite' for available commands."); |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
505 return 1; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
506 end |
