Annotate

plugins/mod_invites.lua @ 13684:026a75a443de 13.0

mod_admin_shell: Hide secondary role commands, focus on primary roles Secondary roles are an advanced feature without any strong use cases currently. Having multiple ways to manage roles is confusing. Now the 'user:role' command will just show the primary role if that is all there is, but will list secondary roles too if there are any (which in 99.9% of cases there won't be).
author Matthew Wild <mwild1@gmail.com>
date Thu, 13 Feb 2025 16:18:59 +0000
parent 13674:1ba58459c919
child 13701:1aa7efabeacb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
13613
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
9 local url_escape = require "util.http".urlencode;
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
10 local render_url = require "util.interpolation".new("%b{}", 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
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
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
224 invite_type = "account";
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
225 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
226 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
227 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
228 else
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
229 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
230 end
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
231 end
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
232 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
233 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
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
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
236 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
237 end
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
238
9cd5b3484a1d mod_invites: Add support for invites_page option to use external invites pages
Matthew Wild <mwild1@gmail.com>
parents: 13520
diff changeset
239 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
240
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
241 --- shell command
13353
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
242 module:add_item("shell-command", {
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
243 section = "invite";
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
244 section_desc = "Create and manage invitations";
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
245 name = "create_account";
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
246 desc = "Create an invitation to make an account on this server with the specified JID (supply only a hostname to allow any username)";
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
247 args = { { name = "user_jid", type = "string" } };
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
248 host_selector = "user_jid";
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
249
13355
a6c8a50cdfb5 mod_invites: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents: 13353
diff changeset
250 handler = function (self, user_jid) --luacheck: ignore 212/self
a6c8a50cdfb5 mod_invites: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents: 13353
diff changeset
251 local username = jid_split(user_jid);
13353
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
252 local invite, err = create_account(username);
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253 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
254 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
255 end;
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
256 });
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
257
13353
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
258 module:add_item("shell-command", {
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
259 section = "invite";
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
260 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
261 name = "create_reset";
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
262 desc = "Create a password reset link for the specified user";
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
263 args = { { name = "user_jid", type = "string" }, { name = "duration", type = "string" } };
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
264 host_selector = "user_jid";
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
265
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
266 handler = function (self, user_jid, duration) --luacheck: ignore 212/self
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
267 local username = jid_split(user_jid);
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
268 local duration_sec = require "prosody.util.human.io".parse_duration(duration or "1d");
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
269 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
270 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
271 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
272 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
273 end;
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
274 });
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
275
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
276 module:add_item("shell-command", {
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
277 section = "invite";
a186f1cfae75 mod_invites: Shell command to create reset links
Matthew Wild <mwild1@gmail.com>
parents: 13613
diff changeset
278 section_desc = "Create and manage invitations";
13353
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
279 name = "create_contact";
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
280 desc = "Create an invitation to become contacts with the specified user";
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
281 args = { { name = "user_jid", type = "string" }, { name = "allow_registration" } };
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
282 host_selector = "user_jid";
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
283
13355
a6c8a50cdfb5 mod_invites: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents: 13353
diff changeset
284 handler = function (self, user_jid, allow_registration) --luacheck: ignore 212/self
a6c8a50cdfb5 mod_invites: Fix linter issues
Matthew Wild <mwild1@gmail.com>
parents: 13353
diff changeset
285 local username = jid_split(user_jid);
13353
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
286 local invite, err = create_contact(username, allow_registration);
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
287 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
288 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
289 end;
27512ebcc8af mod_invites: Use new shell-command API
Matthew Wild <mwild1@gmail.com>
parents: 13209
diff changeset
290 });
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
291
13674
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
292 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
293 section = "invite";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
294 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
295 name = "show";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
296 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
297 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
298 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
299
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
300 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
301 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
302 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
303
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
304 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
305
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 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
314 else
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
315 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
316 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
317 else
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
318 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
319 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
320
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
321 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
322 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
323 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
324
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
325 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
326 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
327
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
328 print("");
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
329
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
330 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
331 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
332 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
333
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
334 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
335 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
336 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
337
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
338 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
339 print("");
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
340 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
341 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
342 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
343 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
344 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
345 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
346 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
347 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
348 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
349 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
350 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
351 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
352 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
353 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
354 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
355
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
356 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
357 end;
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
358 });
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
359
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
360 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
361 section = "invite";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
362 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
363 name = "delete";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
364 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
365 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
366 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
367
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
368 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
369 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
370 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
371 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
372 end;
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
373 });
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
374
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
375 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
376 section = "invite";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
377 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
378 name = "list";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
379 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
380 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
381 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
382
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
383 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
384 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
385 {
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
386 title = "Token";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
387 key = "invite";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
388 width = 24;
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
389 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
390 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
391 end;
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
392 };
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
393 {
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
394 title = "Expires";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
395 key = "invite";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
396 width = 20;
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
397 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
398 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
399 end;
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
400 };
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
401 {
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
402 title = "Description";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
403 key = "invite";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
404 width = "100%";
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
405 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
406 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
407 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
408 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
409 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
410 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
411 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
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 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
414 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
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 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
417 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
418 end;
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
419 };
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
420 }, 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
421
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
422 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
423 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
424 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
425 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
426 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
427 end
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
428 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
429 end;
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
430 });
1ba58459c919 mod_invites: Add shell commands to list, show and delete pending invitations
Matthew Wild <mwild1@gmail.com>
parents: 13673
diff changeset
431
13161
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
432 local subcommands = {};
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
433
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
434 --- prosodyctl command
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
435 function module.command(arg)
13161
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
436 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
437 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
438 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
439 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
440 return 2;
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
441 end
13161
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
442 return subcommands[cmd](arg);
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
443 end
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
444
13161
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
445 function subcommands.generate(arg)
13412
0e96d6a29a12 mod_invites: Show short help instead of traceback on missing hostname
Kim Alvefur <zash@zash.se>
parents: 13411
diff changeset
446 local function help(short)
13161
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
447 print("usage: prosodyctl mod_" .. module.name .. " generate DOMAIN --reset USERNAME")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
448 print("usage: prosodyctl mod_" .. module.name .. " generate DOMAIN [--admin] [--role ROLE] [--group GROUPID]...")
13412
0e96d6a29a12 mod_invites: Show short help instead of traceback on missing hostname
Kim Alvefur <zash@zash.se>
parents: 13411
diff changeset
449 if short then return 2 end
13161
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
450 print()
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
451 print("This command has two modes: password reset and new account.")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
452 print("If --reset is given, the command operates in password reset mode and in new account mode otherwise.")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
453 print()
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
454 print("required arguments in password reset mode:")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
455 print()
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
456 print(" --reset USERNAME Generate a password reset link for the given USERNAME.")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
457 print()
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
458 print("optional arguments in new account mode:")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
459 print()
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
460 print(" --admin Make the new user privileged")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
461 print(" Equivalent to --role prosody:admin")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
462 print(" --role ROLE Grant the given ROLE to the new user")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
463 print(" --group GROUPID Add the user to the group with the given ID")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
464 print(" Can be specified multiple times")
13410
7efdd143fdfc mod_invites: Allow specifying invite ttl on command line
Kim Alvefur <zash@zash.se>
parents: 13355
diff changeset
465 print(" --expires-after T Time until the invite expires (e.g. '1 week')")
13161
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
466 print()
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
467 print("--group can be specified multiple times; the user will be added to all groups.")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
468 print()
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
469 print("--reset and the other options cannot be mixed.")
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
470 return 2
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
471 end
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
472
13411
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
473 local earlyopts = argparse.parse(arg, { short_params = { h = "help"; ["?"] = "help" } });
13413
992389af2372 mod_invites: Fix argument handling
Kim Alvefur <zash@zash.se>
parents: 13412
diff changeset
474 if earlyopts.help or not earlyopts[1] then
13411
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
475 return help();
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
476 end
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
477
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
478 local sm = require "prosody.core.storagemanager";
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
479 local mm = require "prosody.core.modulemanager";
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
480
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
481 local host = table.remove(arg, 1); -- pop host
13412
0e96d6a29a12 mod_invites: Show short help instead of traceback on missing hostname
Kim Alvefur <zash@zash.se>
parents: 13411
diff changeset
482 if not host then return help(true) end
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
483 sm.initialize_host(host);
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
484 module.host = host; --luacheck: ignore 122/module
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
485 token_storage = module:open_store("invite_token", "map");
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
486
13411
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
487 local opts = argparse.parse(arg, {
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
488 short_params = { h = "help"; ["?"] = "help"; g = "group" };
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
489 value_params = { group = true; reset = true; role = true };
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
490 array_params = { group = true; role = true };
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
491 });
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
492
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
493 if opts.help then
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
494 return help();
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
495 end
d815882d2692 mod_invites: Show help if --help passed instead of hostname
Kim Alvefur <zash@zash.se>
parents: 13410
diff changeset
496
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
497 -- Load mod_invites
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
498 local invites = module:depends("invites");
12151
669d93f1db6a mod_invites: Comment on module loading for HTTP invite URLs
Kim Alvefur <zash@zash.se>
parents: 12143
diff changeset
499 -- Optional community module that if used, needs to be loaded here
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
500 local invites_page_module = module:get_option_string("invites_page_module", "invites_page");
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
501 if mm.get_modules_for_host(host):contains(invites_page_module) then
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
502 module:depends(invites_page_module);
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
503 end
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
504
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
505 local allow_reset;
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
506
13161
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
507 if opts.reset then
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
508 local nodeprep = require "prosody.util.encodings".stringprep.nodeprep;
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
509 local username = nodeprep(opts.reset)
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
510 if not username then
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
511 print("Please supply a valid username to generate a reset link for");
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
512 return 2;
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
513 end
13161
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
514 allow_reset = username;
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
515 end
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
516
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
517 local roles = opts.role or {};
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
518 local groups = opts.groups or {};
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
519
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
520 if opts.admin then
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
521 -- Insert it first since we don't get order out of argparse
9ba11ef91ce4 mod_invites: Refactor argument handling using util.argparse
Kim Alvefur <zash@zash.se>
parents: 13096
diff changeset
522 table.insert(roles, 1, "prosody:admin");
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
523 end
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
524
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
525 local invite;
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
526 if allow_reset then
13096
9638ff8b1c81 mod_invites: Fix password reset invites
Kim Alvefur <zash@zash.se>
parents: 13012
diff changeset
527 if roles[1] then
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
528 print("--role/--admin and --reset are mutually exclusive")
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
529 return 2;
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
530 end
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
531 if #groups > 0 then
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
532 print("--group and --reset are mutually exclusive")
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
533 end
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
534 invite = assert(invites.create_account_reset(allow_reset));
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
535 else
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
536 invite = assert(invites.create_account(nil, {
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
537 roles = roles,
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
538 groups = groups
13410
7efdd143fdfc mod_invites: Allow specifying invite ttl on command line
Kim Alvefur <zash@zash.se>
parents: 13355
diff changeset
539 }, opts.expires_after and human_io.parse_duration(opts.expires_after)));
12142
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
540 end
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
541
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
542 print(invite.landing_page or invite.uri);
87532eebd0b8 mod_invites: Import from prosdy-modules@5fc306239db3
Kim Alvefur <zash@zash.se>
parents:
diff changeset
543 end