Mercurial > prosody-hg
annotate plugins/mod_invites.lua @ 14151:4985de195749 13.0
Added tag 13.0.5 for changeset 2a66728d9e29
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Wed, 29 Apr 2026 12:31:38 +0100 |
| parents | f0b2a05bcedc |
| 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"; |
|
14014
f0b2a05bcedc
mod_invites: Return error when generating password reset for non-existent account
Matthew Wild <mwild1@gmail.com>
parents:
13896
diff
changeset
|
3 local usermanager = require "prosody.core.usermanager"; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 local url = require "socket.url"; |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12834
diff
changeset
|
5 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
|
6 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
|
7 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
|
8 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
|
9 |
|
13701
1aa7efabeacb
mod_cloud_notify, mod_cron, mod_invites: Add 'prosody.' prefix to requires
Matthew Wild <mwild1@gmail.com>
parents:
13674
diff
changeset
|
10 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
|
11 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
|
12 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
|
13 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
|
14 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
|
15 end; |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
16 }); |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
17 |
|
13209
c8d949cf6b09
plugins: Switch to :get_option_period() for time range options
Kim Alvefur <zash@zash.se>
parents:
13161
diff
changeset
|
18 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
|
19 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 local token_storage; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 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
|
22 token_storage = module:open_store("invite_token", "map"); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 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
|
26 return url.build({ |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 scheme = "xmpp", |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 path = jid, |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 query = action..";preauth="..token..(params and (";"..params) or ""), |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 }); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 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
|
34 local token = id.medium(); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 local created_at = os.time(); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 local expires = created_at + (ttl or default_ttl); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 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
|
40 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 local invite = { |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 type = invite_action; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 jid = invite_jid; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
44 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
45 token = token; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 allow_registration = allow_registration; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 additional_data = additional_data; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 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
|
50 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 created_at = created_at; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 expires = expires; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 reusable = reusable; |
|
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 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 module:fire_event("invite-created", invite); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 if allow_registration then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 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
|
61 if not ok then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 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
|
63 return nil, "internal-server-error"; |
|
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 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 if invite_action == "roster" then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 local username = jid_node(invite_jid); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 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
|
70 if not ok then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
71 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
|
72 return nil, "internal-server-error"; |
|
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 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 return invite; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 -- 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
|
80 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
|
81 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
|
82 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
|
83 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 -- 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
|
86 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
|
87 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
|
88 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 -- 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
|
91 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
|
92 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
|
93 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 -- 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
|
96 -- 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
|
97 -- during that time period |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 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
|
99 local merged_additional_data = { |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 groups = group_ids; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 }; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
102 if additional_data then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
103 for k, v in pairs(additional_data) do |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
104 merged_additional_data[k] = v; |
|
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 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
107 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
|
108 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
109 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
110 -- 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
|
111 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
|
112 local store = module:open_store("invite_token"); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
113 local now = os.time(); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
114 local function is_valid_invite(_, invite) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
115 return invite.expires > now; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
116 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
117 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
|
118 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
119 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
120 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
|
121 if not token then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
122 return nil, "no-token"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
123 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
124 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
125 -- Fetch from host store (account invite) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
126 local token_info = token_storage:get(nil, token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
127 if not token_info then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
128 return nil, "token-invalid"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
129 elseif os.time() > token_info.expires then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
130 return nil, "token-expired"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
131 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
132 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
133 return token_info; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
134 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
135 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
136 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
|
137 if not token then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
138 return nil, "no-token"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
139 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
140 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
141 return token_storage:set(nil, token, nil); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
142 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
143 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
144 local valid_invite_methods = {}; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
145 local valid_invite_mt = { __index = valid_invite_methods }; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
146 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
147 function valid_invite_methods:use() |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
148 if self.reusable then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
149 return true; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
150 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
151 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
152 if self.username then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
153 -- 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
|
154 -- assumption that they now have a mutual subscription |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
155 token_storage:set(self.username, self.token, nil); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
156 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
157 token_storage:set(nil, self.token, nil); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
158 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
159 return true; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
160 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
161 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
162 -- 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
|
163 -- returned invite after it is actually successfully used |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
164 -- 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
|
165 -- the invite) must be passed. |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
166 -- 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
|
167 -- 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
|
168 -- be set to their username. |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
169 function get(token, username) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
170 if not token then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
171 return nil, "no-token"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
172 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
173 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
174 local valid_until, inviter; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
175 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
176 -- Fetch from host store (account invite) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
177 local token_info = token_storage:get(nil, token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
178 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
179 if username then -- token being used for subscription |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
180 -- Fetch from user store (subscription invite) |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
181 valid_until = token_storage:get(username, token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
182 else -- token being used for account creation |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
183 valid_until = token_info and token_info.expires; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
184 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
|
185 username = jid_node(token_info.jid); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
186 inviter = username; |
|
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 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
189 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
190 if not valid_until then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
191 module:log("debug", "Got unknown token: %s", token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
192 return nil, "token-invalid"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
193 elseif os.time() > valid_until then |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
194 module:log("debug", "Got expired token: %s", token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
195 return nil, "token-expired"; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
196 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
197 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
198 return setmetatable({ |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
199 token = token; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
200 username = username; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
201 inviter = inviter; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 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
|
206 }, valid_invite_mt); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
207 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
208 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
209 function use(token) --luacheck: ignore 131/use |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
210 local invite = get(token); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
211 return invite and invite:use(); |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
212 end |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
213 |
|
13613
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
214 -- 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
|
215 -- 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
|
216 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
|
217 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
|
218 |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
219 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
|
220 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
|
221 |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
222 -- 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 else |
|
ecafafec7806
mod_invites: Consider password reset a distinct type wrt invite page
Kim Alvefur <zash@zash.se>
parents:
13741
diff
changeset
|
228 invite_type = "account"; |
|
ecafafec7806
mod_invites: Consider password reset a distinct type wrt invite page
Kim Alvefur <zash@zash.se>
parents:
13741
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 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
|
233 else |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
234 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
|
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 end |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
237 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
|
238 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
|
239 end |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
240 |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
241 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
|
242 end |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
243 |
|
9cd5b3484a1d
mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents:
13520
diff
changeset
|
244 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
|
245 |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
246 --- shell command |
|
13741
e9edf9b50f32
mod_invites: Hide --group flag unless mod_invites_groups is enabled
Matthew Wild <mwild1@gmail.com>
parents:
13740
diff
changeset
|
247 -- 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
|
248 -- 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
|
249 -- 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
|
250 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
|
251 |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
252 module:add_item("shell-command", { |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
253 section = "invite"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
254 section_desc = "Create and manage invitations"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
255 name = "create_account"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
256 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
|
257 args = { |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
258 { 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
|
259 }; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
260 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
|
261 flags = { |
|
13741
e9edf9b50f32
mod_invites: Hide --group flag unless mod_invites_groups is enabled
Matthew Wild <mwild1@gmail.com>
parents:
13740
diff
changeset
|
262 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
|
263 value_params = { expires_after = true }; |
|
17b5a10bd9c9
mod_invites: Fix --admin to not require a value
Kim Alvefur <zash@zash.se>
parents:
13892
diff
changeset
|
264 kv_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
|
265 }; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
266 |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 local groups = opts and opts.group or {}; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
271 |
|
13740
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
272 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
|
273 -- 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
|
274 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
|
275 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
276 |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
277 local ttl; |
|
13740
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 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
|
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 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
284 |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
285 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
|
286 roles = roles; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
287 groups = groups; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
288 }, ttl)); |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
289 |
|
12834
dcbff9f038a0
mod_invites: Prefer landing page over xmpp URI in shell command
Kim Alvefur <zash@zash.se>
parents:
12151
diff
changeset
|
290 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
|
291 end; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
292 }); |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
293 |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
294 module:add_item("shell-command", { |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
295 section = "invite"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
296 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
|
297 name = "create_reset"; |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
298 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
|
299 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
|
300 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
|
301 flags = { |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
302 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
|
303 }; |
|
13673
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
304 |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
305 handler = function (self, user_jid, opts) --luacheck: ignore 212/self |
|
14014
f0b2a05bcedc
mod_invites: Return error when generating password reset for non-existent account
Matthew Wild <mwild1@gmail.com>
parents:
13896
diff
changeset
|
306 local username, host = 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
|
307 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
|
308 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
|
309 end |
|
14014
f0b2a05bcedc
mod_invites: Return error when generating password reset for non-existent account
Matthew Wild <mwild1@gmail.com>
parents:
13896
diff
changeset
|
310 if not usermanager.user_exists(username, host) then |
|
f0b2a05bcedc
mod_invites: Return error when generating password reset for non-existent account
Matthew Wild <mwild1@gmail.com>
parents:
13896
diff
changeset
|
311 return nil, "The specified user account does not exist: " .. username; |
|
f0b2a05bcedc
mod_invites: Return error when generating password reset for non-existent account
Matthew Wild <mwild1@gmail.com>
parents:
13896
diff
changeset
|
312 end |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
313 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
|
314 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
|
315 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
|
316 end |
|
13673
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 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
|
321 end; |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
322 }); |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
323 |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
324 module:add_item("shell-command", { |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
325 section = "invite"; |
|
a186f1cfae75
mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents:
13613
diff
changeset
|
326 section_desc = "Create and manage invitations"; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
327 name = "create_contact"; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
328 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
|
329 args = { { name = "user_jid", type = "string" } }; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
330 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
|
331 flags = { |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
332 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
|
333 kv_params = { allow_registration = true }; |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
334 }; |
|
13353
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
335 |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 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
|
340 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
341 local ttl; |
|
13740
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 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
|
346 end |
|
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
347 end |
|
13740
4cf2caa63277
mod_invites: Fix traceback when no flags passed
Matthew Wild <mwild1@gmail.com>
parents:
13738
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 end; |
|
27512ebcc8af
mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents:
13209
diff
changeset
|
352 }); |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
353 |
|
13674
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
354 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
|
355 section = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
356 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
|
357 name = "show"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
358 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
|
359 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
|
360 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
|
361 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
366 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
|
367 |
|
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.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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 else |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
377 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
|
378 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
379 else |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
380 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
|
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 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
|
384 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
|
385 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
386 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
387 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
|
388 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
|
389 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
390 print(""); |
|
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.uri 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("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
|
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.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
|
397 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
|
398 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
399 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
400 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
|
401 print(""); |
|
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 then |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
403 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
|
404 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
|
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.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
|
407 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
|
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 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
410 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
|
411 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
|
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 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
|
414 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
|
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 end |
|
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 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
|
419 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
420 }); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
421 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
422 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
|
423 section = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
424 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
|
425 name = "delete"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
426 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
|
427 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
|
428 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
|
429 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
430 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
|
431 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
|
432 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
|
433 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
|
434 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
435 }); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
436 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
437 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
|
438 section = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
439 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
|
440 name = "list"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
441 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
|
442 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
|
443 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
|
444 |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
445 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
|
446 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
|
447 { |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
448 title = "Token"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
449 key = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
450 width = 24; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
451 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
|
452 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
|
453 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
454 }; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
455 { |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
456 title = "Expires"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
457 key = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
458 width = 20; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
459 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
|
460 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
|
461 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
462 }; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
463 { |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
464 title = "Description"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
465 key = "invite"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
466 width = "100%"; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
475 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
|
476 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
|
477 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
478 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
|
479 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
480 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
481 }; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
482 }, 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
|
483 |
|
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()); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
485 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
|
486 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
|
487 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
|
488 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
|
489 end |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
490 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
|
491 end; |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
492 }); |
|
1ba58459c919
mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents:
13673
diff
changeset
|
493 |
|
13161
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
494 local subcommands = {}; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
495 |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
496 --- prosodyctl command |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
497 function module.command(arg) |
|
13161
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 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
|
502 return 2; |
|
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
503 end |
|
13161
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
504 return subcommands[cmd](arg); |
|
9ba11ef91ce4
mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents:
13096
diff
changeset
|
505 end |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
506 |
|
13738
26a0f653793e
mod_invites: Deprecate 'mod_invites generate' in favour of new shell commands
Matthew Wild <mwild1@gmail.com>
parents:
13725
diff
changeset
|
507 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
|
508 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
|
509 return 1; |
|
12142
87532eebd0b8
mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
510 end |
