Annotate

mod_invites_api/mod_invites_api.lua @ 5638:4379e0e84ee5

mod_invites_api: fix error messages when not `found`.
author Trần H. Trung <xmpp:trần.h.trung@trung.fun>
date Mon, 31 Jul 2023 13:15:54 +0700
parent 5637:38783b8acbc9
child 5639:1664bd4c274b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local http_formdecode = require "net.http".formdecode;
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
2 local jid = require "util.jid";
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
3 local usermanager = require "core.usermanager";
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
4 local datetime = require "util.datetime";
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
6 -- Whether local users can invite other users to create an account on this server
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
7 local allow_user_invites = module:get_option_boolean("allow_user_invites", false);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
8 -- Who can see and use the contact invite command. It is strongly recommened to
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
9 -- keep this available to all local users. To allow/disallow invite-registration
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
10 -- on the server, use the option above instead.
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
11 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
12
5629
160868fdddd6 mod_invites_api: remove unnecessary variables.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5628
diff changeset
13 local api_key_store, api_key_store_kv, invites, date;
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 -- COMPAT: workaround to avoid executing inside prosodyctl
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 if prosody.shutdown then
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 module:depends("http");
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 api_key_store = module:open_store("invite_api_keys", "map");
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 invites = module:depends("invites");
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
19 api_key_store_kv = module:open_store("invite_api_keys");
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local function get_api_user(request, params)
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 local combined_key;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local auth_header = request.headers.authorization;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 if not auth_header then
5143
1cae382e88a1 mod_invites_api: Fix traceback when no query params (thanks Menel)
Matthew Wild <mwild1@gmail.com>
parents: 5142
diff changeset
28 params = params or http_formdecode(request.url.query or "=");
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 combined_key = params.key;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 else
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local auth_type, value = auth_header:match("^(%S+)%s(%S+)$");
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 if auth_type ~= "Bearer" then
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 return;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 combined_key = value;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 if not combined_key then
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 return;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 local key_id, key_token = combined_key:match("^([^/]+)/(.+)$");
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 if not key_id then
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 return;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 local api_user = api_key_store:get(nil, key_id);
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 if not api_user or api_user.token ~= key_token then
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 return;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 -- TODO: key expiry, rate limiting, etc.
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 return api_user;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 function handle_request(event)
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 local query_params = http_formdecode(event.request.url.query);
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 local api_user = get_api_user(event.request, query_params);
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 if not api_user then
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 return 403;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66
4216
35b678609b79 mod_invites_api: Allow restricting HTTP methods per key (once implemented)
Matthew Wild <mwild1@gmail.com>
parents: 4115
diff changeset
67 if api_user.allowed_methods and not api_user.allowed_methods[event.request.method] then
35b678609b79 mod_invites_api: Allow restricting HTTP methods per key (once implemented)
Matthew Wild <mwild1@gmail.com>
parents: 4115
diff changeset
68 return 405;
35b678609b79 mod_invites_api: Allow restricting HTTP methods per key (once implemented)
Matthew Wild <mwild1@gmail.com>
parents: 4115
diff changeset
69 end
35b678609b79 mod_invites_api: Allow restricting HTTP methods per key (once implemented)
Matthew Wild <mwild1@gmail.com>
parents: 4115
diff changeset
70
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
71 local invite;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
72 local username, domain = jid.prepped_split(api_user.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
73 if username and usermanager.user_exists(username, domain) then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
74 local ttl = module:get_option_number("invite_expiry", 86400 * 7);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
75 invite = invites.create_contact(username,
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
76 allow_user_invites, -- allow_registration
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
77 { source = "api/token/"..api_user.id }, -- additional_data
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
78 ttl
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
79 );
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
80 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
81 invite = invites.create_account(nil, { source = "api/token/"..api_user.id });
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
82 end
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 if not invite then
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 return 500;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 event.response.headers.Location = invite.landing_page or invite.uri;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 if query_params.redirect then
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 return 303;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 return 201;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 if invites then
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 module:provides("http", {
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 route = {
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 ["GET"] = handle_request;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 };
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100 });
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
103 function get_value(callback)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
104 for key_id, key_info in pairs(api_key_store_kv:get(nil) or {}) do
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
105 date = datetime.datetime(key_info.created_at);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
106 callback(key_id, key_info);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
107 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
108 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
109
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
110 local function get_url(id, token)
5628
a74b07764d3f mod_invites_api: use the nice `module:http_url()` to get the correct url.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5595
diff changeset
111 local url_base = module:context(module.host):http_url(module.name, "/"..module.name);
a74b07764d3f mod_invites_api: use the nice `module:http_url()` to get the correct url.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5595
diff changeset
112 return url_base.."?key="..id.."/"..token.."&redirect=true";
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
113 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
114
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115 function module.command(arg)
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 if #arg < 2 then
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
117 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
118 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
119 print("Create:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
120 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
121 print("> prosodyctl mod_"..module.name.." create JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
122 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
123 print("Query:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
124 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
125 print("> prosodyctl mod_"..module.name.." get JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
126 print("> prosodyctl mod_"..module.name.." date JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
127 print("> prosodyctl mod_"..module.name.." id JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
128 print("> prosodyctl mod_"..module.name.." key JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
129 print("> prosodyctl mod_"..module.name.." url JID NAME");
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 print("");
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
131 print("Revoke:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
132 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
133 print("> prosodyctl mod_"..module.name.." delete JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
134 print("> prosodyctl mod_"..module.name.." delete-id HOST ID");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
135 print("");
5637
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
136 print("Adjust:");
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 print("");
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
138 print("> prosodyctl mod_"..module.name.." renew JID NAME");
5637
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
139 print("> prosodyctl mod_"..module.name.." rename JID NAME NEW_NAME");
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
140 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
141 print("Help:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
142 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
143 print("> prosodyctl mod_"..module.name.." help COMMAND");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
144 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
145 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
146 return;
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 local command = table.remove(arg, 1);
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
150 if command == "help" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
151 help_command = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
152 if help_command == "create" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
153 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
154 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
155 print("Create a key:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
156 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
157 print("> prosodyctl mod_"..module.name.." create JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
158 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
159 print("------------------------------------------------------------------------");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
160 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
161 print("Usage:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
162 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
163 print(" `JID` can either be a user's account or a host.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
164 print(" When `JID` is a host, you need to supply a `NAME`.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
165 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
166 print(" Each user's account can only have 1 API key but hosts are unlimited.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
167 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
168 print("========================================================================");
5637
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
169 elseif help_command == "rename" then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
170 print("========================================================================");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
171 print("");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
172 print("Re-name a key:");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
173 print("");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
174 print("> prosodyctl mod_"..module.name.." rename JID NAME NEW_NAME");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
175 print("");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
176 print("------------------------------------------------------------------------");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
177 print("");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
178 print("Usage:");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
179 print("");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
180 print(" `JID` can only be a valid host.");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
181 print("");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
182 print(" You need to supply a `NEW_NAME` to replace « `NAME` » the old one.");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
183 print("");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
184 print("========================================================================");
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
185 elseif help_command == "renew" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
186 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
187 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
188 print("Re-new a key:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
189 print("");
5637
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
190 print("> prosodyctl mod_"..module.name.." renew JID NAME");
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
191 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
192 print("------------------------------------------------------------------------");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
193 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
194 print("Usage:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
195 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
196 print(" `JID` can either be a user's account or a host.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
197 print(" When `JID` is a host, you need to supply a `NAME`.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
198 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
199 print(" The old `ID` will be kept and a new token will be generated for the API");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
200 print(" key you specified.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
201 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
202 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
203 elseif help_command == "get" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
204 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
205 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
206 print("Get info of a key:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
207 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
208 print("> prosodyctl mod_"..module.name.." get JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
209 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
210 print("------------------------------------------------------------------------");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
211 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
212 print("Usage:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
213 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
214 print(" When `JID` is a domain, it will list all the keys under that host.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
215 print(" When `JID` is a user's account, it fetches the key for that user.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
216 print(" If you supply both a host and a `NAME`, it fetches the key with `NAME`");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
217 print(" under that host.")
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
218 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
219 print(" Output for a host is: DATE, ID, JID, NAME.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
220 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
221 print(" Output for a user's account is: DATE, ID, URL.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
222 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
223 print(" Output for a host with a valid `NAME` is: DATE, ID, URL.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
224 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
225 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
226 elseif help_command == "date" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
227 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
228 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
229 print("Get the time stamp of a key:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
230 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
231 print("> prosodyctl mod_"..module.name.." date JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
232 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
233 print("------------------------------------------------------------------------");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
234 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
235 print("Usage:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
236 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
237 print(" Same as the `get` command but print only the birthday of the key.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
238 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
239 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
240 elseif help_command == "id" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
241 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
242 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
243 print("Print the ID of a key:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
244 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
245 print("> prosodyctl mod_"..module.name.." id JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
246 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
247 print("------------------------------------------------------------------------");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
248 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
249 print("Usage:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
250 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
251 print(" Same as the `get` command but print only the ID of the key.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
252 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
253 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
254 elseif help_command == "key" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
255 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
256 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
257 print("Print the API key:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
258 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
259 print("> prosodyctl mod_"..module.name.." key JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
260 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
261 print("------------------------------------------------------------------------");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
262 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
263 print("Usage:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
264 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
265 print(" Same as the `get` command but print only the key.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
266 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
267 print(" The key has the format: ID/TOKEN");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
268 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
269 print(" The `renew` command will generate a new token and revoke the old one.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
270 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
271 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
272 elseif help_command == "url" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
273 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
274 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
275 print("Print the URL of a key:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
276 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
277 print("> prosodyctl mod_"..module.name.." url JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
278 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
279 print("------------------------------------------------------------------------");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
280 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
281 print("Usage:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
282 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
283 print(" Same as the `get` command but print only the URL of the key.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
284 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
285 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
286 elseif help_command == "delete" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
287 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
288 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
289 print("Delete a key by JID and NAME:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
290 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
291 print("> prosodyctl mod_"..module.name.." delete JID NAME");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
292 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
293 print("------------------------------------------------------------------------");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
294 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
295 print("Usage:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
296 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
297 print(" Same as `create` command but delete the key specified.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
298 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
299 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
300 elseif help_command == "delete-id" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
301 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
302 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
303 print("Delete API key by ID:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
304 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
305 print("> prosodyctl mod_"..module.name.." delete HOST ID");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
306 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
307 print("------------------------------------------------------------------------");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
308 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
309 print("Usage:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
310 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
311 print(" Input must be a valid host - cannot be a user's account.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
312 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
313 print(" To get the ID of a key, use the `id` command.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
314 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
315 print("========================================================================");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
316 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
317 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
318 end
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
319
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
320 local username, domain = jid.prepped_split(table.remove(arg, 1));
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
321 if not prosody.hosts[domain] then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
322 print("Error: please supply a valid host.");
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
323 return 1;
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
324 end
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
325 require "core.storagemanager".initialize_host(domain);
5636
7e5701fbae88 mod_invites_api: add `module:depends("http");` to use `module:http_url()` in `prosodyctl`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5629
diff changeset
326 module:depends("http");
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
327 module.host = domain; --luacheck: ignore 122/module
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
328 usermanager.initialize_host(module.host);
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
329 api_key_store = module:open_store("invite_api_keys", "map");
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
330 api_key_store_kv = module:open_store("invite_api_keys");
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
331
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
332 if command == "create" then
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
333 local util_id = require "util.id".short();
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
334 local util_token = require "util.id".long();
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
335 local found = false;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
336 local os_time = os.time();
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
337 if username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
338 if usermanager.user_exists(username, module.host) then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
339 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
340 if username.."@"..module.host == info.jid then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
341 date = datetime.datetime(info.created_at);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
342 print("Found:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
343 print(date, id, info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
344 util_id = id;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
345 util_token = info.token;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
346 found = true;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
347 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
348 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
349 if found == false then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
350 api_key_store:set(nil, util_id, {
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
351 id = util_id;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
352 token = util_token;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
353 name = nil;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
354 jid = username.."@"..domain;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
355 created_at = os_time;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
356 allowed_methods = { GET = true, POST = true };
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
357 });
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
358 date = datetime.datetime(os_time);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
359 print("Created:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
360 print(date, util_id.."/"..util_token, username.."@"..domain);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
361 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
362 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
363 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
364 print("Error: "..username.."@"..domain.." does not exists.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
365 return 1;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
366 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
367 elseif domain then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
368 local arg_name = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
369 if not arg_name or arg_name == "" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
370 print("Error: key for host needs a `NAME`.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
371 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
372 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
373 found = false;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
374 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
375 if domain == info.jid and arg_name == info.name then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
376 date = datetime.datetime(info.created_at);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
377 print("Found:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
378 print(date, id, info.jid, info.name);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
379 util_id = id;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
380 util_token = info.token;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
381 found = true;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
382 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
383 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
384 if found == false then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
385 api_key_store:set(nil, util_id, {
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
386 id = util_id;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
387 token = util_token;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
388 name = arg_name;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
389 jid = domain;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
390 created_at = os_time;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
391 allowed_methods = { GET = true, POST = true };
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
392 });
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
393 date = datetime.datetime(os_time);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
394 print("Created:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
395 print(date, util_id.."/"..util_token, domain, arg_name);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
396 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
397 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
398 end
5637
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
399 elseif command == "rename" then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
400 local util_token = require "util.id".long();
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
401 local os_time = os.time();
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
402 if username then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
403 local found;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
404 if usermanager.user_exists(username, module.host) then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
405 get_value(function (id, info)
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
406 if username.."@"..module.host == info.jid then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
407 print("Found:");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
408 print(date, id.."/"..util_token, info.jid);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
409 found = true;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
410 end
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
411 end);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
412 if not found then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
413 print("Error: Could not find the key for "..username.."@"..domain);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
414 return 1;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
415 end
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
416 print("Error: not allow to rename user's account.");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
417 return 1;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
418 else
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
419 print("Error: "..username.."@"..domain.." does not exists.");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
420 return 1;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
421 end
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
422 elseif domain then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
423 local arg_name_orig = table.remove(arg, 1);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
424 if not arg_name_orig or arg_name_orig == "" then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
425 print("Error: key for host needs a `NAME`.");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
426 return 1;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
427 end
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
428 local arg_name_new = table.remove(arg, 1);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
429 if not arg_name_new or arg_name_new == "" then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
430 print("Error: need a `NEW_NAME` to replace "..arg_name_orig);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
431 return 1;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
432 end
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
433
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
434 found = false;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
435 get_value(function (id, info)
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
436 if domain == info.jid and arg_name_orig == info.name then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
437 api_key_store:set(nil, id, {
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
438 id = id;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
439 token = info.token;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
440 name = arg_name_new;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
441 jid = domain;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
442 created_at = os_time;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
443 allowed_methods = { GET = true, POST = true };
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
444 });
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
445 date = datetime.datetime(os_time);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
446 print("Re-named:");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
447 print(date, id.."/"..info.token, info.jid, arg_name_new);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
448 found = true;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
449 end
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
450 end);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
451 if not found then
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
452 date = datetime.datetime(os_time);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
453 print("Error: Could not find "..arg_name_orig.." in "..domain);
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
454 print("");
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
455 print("To make this API key, run:");
5638
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
456 print("> prosodyctl "..module.name.." create "..domain.." "..arg_name_orig);
5637
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
457 return 1;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
458 end
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
459 return;
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
460 end
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
461 elseif command == "renew" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
462 local util_token = require "util.id".long();
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
463 local os_time = os.time();
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
464 if username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
465 local found;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
466 if usermanager.user_exists(username, module.host) then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
467 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
468 if username.."@"..module.host == info.jid then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
469 api_key_store:set(nil, id, {
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
470 id = id;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
471 token = util_token;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
472 name = arg[1];
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
473 jid = username.."@"..domain;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
474 created_at = os_time;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
475 allowed_methods = { GET = true, POST = true };
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
476 });
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
477 found = true;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
478 date = datetime.datetime(os_time);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
479 print("Re-newed:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
480 print(date, id.."/"..util_token, info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
481 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
482 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
483 if not found then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
484 print("Error: Could not find the key for "..username.."@"..domain);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
485 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
486 print("To make this API key, run:");
5638
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
487 print("> prosodyctl "..module.name.." create "..username.."@"..domain);
5637
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
488 return 1;
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
489 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
490 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
491 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
492 print("Error: "..username.."@"..domain.." does not exists.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
493 return 1;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
494 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
495 elseif domain then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
496 local arg_name = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
497 if not arg_name or arg_name == "" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
498 print("Error: key for host needs a `NAME`.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
499 return 1;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
500 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
501 found = false;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
502 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
503 if domain == info.jid and arg_name == info.name then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
504 api_key_store:set(nil, id, {
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
505 id = id;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
506 token = util_token;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
507 name = arg_name;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
508 jid = domain;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
509 created_at = os_time;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
510 allowed_methods = { GET = true, POST = true };
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
511 });
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
512 date = datetime.datetime(os_time);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
513 print("Re-newed:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
514 print(date, id.."/"..util_token, info.jid, info.name);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
515 found = true;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
516 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
517 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
518 if not found then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
519 print("Error: Could not find "..arg_name.." in "..domain);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
520 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
521 print("To make this API key, run:");
5638
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
522 print("> prosodyctl "..module.name.." create "..domain.." "..arg_name);
5637
38783b8acbc9 mod_invites_api: add `rename` command.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5636
diff changeset
523 return 1;
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
524 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
525 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
526 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
527 elseif command == "get" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
528 local name = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
529 local found = false;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
530 if name and not username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
531 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
532 if info.name == name then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
533 print(date, id, get_url(id, info.token));
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
534 found = true;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
535 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
536 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
537 if found == false then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
538 print("Error: could not find "..name.." in "..domain);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
539 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
540 print("You can create it with:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
541 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
542 print("> prosodyctl "..module.name.." create "..domain.." "..name);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
543 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
544 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
545 elseif username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
546 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
547 local j = jid.prepped_split(info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
548 if j == username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
549 print(date, id, get_url(id, info.token));
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
550 found = true;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
551 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
552 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
553 if found == false then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
554 print("Error: could not find the key for "..username.."@"..domain);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
555 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
556 print("You can create it with:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
557 print("");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
558 print("> prosodyctl "..module.name.." create "..username.."@"..domain);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
559 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
560 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
561 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
562 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
563 if info.jid == module.host then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
564 print(date, id, info.jid, info.name or "<unknown>");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
565 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
566 print(date, id, info.jid, info.name or "");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
567 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
568 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
569 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
570 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
571 elseif command == "date" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
572 local name = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
573 if name and not username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
574 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
575 if info.name == name then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
576 print(date);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
577 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
578 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
579 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
580 elseif username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
581 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
582 local j = jid.prepped_split(info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
583 if j == username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
584 print(date);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
585 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
586 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
587 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
588 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
589 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
590 if info.jid == module.host then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
591 print(date, info.jid, info.name or "<unknown>");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
592 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
593 print(date, info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
594 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
595 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
596 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
597 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
598 elseif command == "id" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
599 local name = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
600 if name and not username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
601 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
602 if info.name == name then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
603 print(id);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
604 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
605 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
606 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
607 elseif username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
608 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
609 local j = jid.prepped_split(info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
610 if j == username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
611 print(id);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
612 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
613 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
614 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
615 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
616 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
617 if info.jid == module.host then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
618 print(id, info.jid, info.name or "<unknown>");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
619 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
620 print(id, info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
621 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
622 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
623 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
624 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
625 elseif command == "key" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
626 local name = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
627 if name and not username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
628 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
629 if info.name == name then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
630 print(id.."/"..info.token);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
631 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
632 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
633 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
634 elseif username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
635 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
636 local j = jid.prepped_split(info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
637 if j == username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
638 print(id.."/"..info.token);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
639 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
640 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
641 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
642 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
643 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
644 if info.jid == module.host then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
645 print(id.."/"..info.token, info.jid, info.name or "<unknown>");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
646 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
647 print(id.."/"..info.token, info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
648 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
649 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
650 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
651 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
652 elseif command == "url" then
5638
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
653 found = false;
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
654 local name = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
655 if name and not username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
656 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
657 if info.name == name then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
658 print(get_url(id, info.token));
5638
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
659 found = true;
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
660 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
661 end);
5638
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
662 if not found then
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
663 date = datetime.datetime(os_time);
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
664 print("Error: Could not find "..name.." in "..domain);
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
665 print("");
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
666 print("To make this API key, run:");
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
667 print("> prosodyctl "..module.name.." create "..domain.." "..name);
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
668 return 1;
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
669 end
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
670 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
671 elseif username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
672 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
673 local j = jid.prepped_split(info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
674 if j == username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
675 print(get_url(id, info.token));
5638
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
676 found = true;
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
677 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
678 end);
5638
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
679 if not found then
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
680 date = datetime.datetime(os_time);
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
681 print("Error: Could not find "..username.."@"..domain);
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
682 print("");
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
683 print("To make this API key, run:");
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
684 print("> prosodyctl "..module.name.." create "..username.."@"..domain);
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
685 return 1;
4379e0e84ee5 mod_invites_api: fix error messages when not `found`.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5637
diff changeset
686 end
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
687 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
688 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
689 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
690 if info.jid == module.host then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
691 print(get_url(id, info.token), info.jid, info.name or "<unknown>");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
692 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
693 print(get_url(id, info.token), info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
694 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
695 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
696 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
697 end
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
698 elseif command == "delete" then
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
699 local name = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
700 if name and not username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
701 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
702 if info.name == name then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
703 api_key_store:set(nil, id, nil);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
704 print("Deleted:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
705 print(date, id.."/"..info.token, info.jid, info.name or "");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
706 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
707 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
708 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
709 elseif username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
710 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
711 local j = jid.prepped_split(info.jid);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
712 if j == username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
713 api_key_store:set(nil, id, nil);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
714 print("Deleted:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
715 print(date, id.."/"..info.token, info.jid, info.name or "");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
716 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
717 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
718 return;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
719 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
720 print("Error: Needs a valid `JID`. Or a host and a `NAME`.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
721 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
722 elseif command == "delete-id" then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
723 if username then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
724 print("Error: Input must be a valid host - cannot be a user's account.");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
725 return 1;
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
726 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
727 local arg_id = table.remove(arg, 1);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
728 if not api_key_store:get(nil, arg_id) then
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
729 print("Error: key not found");
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
730 return 1;
5595
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
731 else
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
732 get_value(function (id, info)
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
733 if arg_id == id then
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
734 api_key_store:set(nil, id, nil);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
735 print("Deleted:");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
736 print(date, id, info.jid, info.name or "");
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
737 end
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
738 end);
f7410850941f mod_invites_api: Change and add new commands for `module.command` to improve UX.
Trần H. Trung <xmpp:trần.h.trung@trung.fun>
parents: 5143
diff changeset
739 return;
4115
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
740 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
741 else
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
742 print("Unknown command - "..command);
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
743 end
165ade4ce97b mod_invites_api: New module to create new invites over HTTP
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
744 end