Mercurial > prosody-hg
annotate plugins/mod_invites_adhoc.lua @ 13652:a08065207ef0
net.server_epoll: Call :shutdown() on TLS sockets when supported
Comment from Matthew:
This fixes a potential issue where the Prosody process gets blocked on sockets
waiting for them to close. Unlike non-TLS sockets, closing a TLS socket sends
layer 7 data, and this can cause problems for sockets which are in the process
of being cleaned up.
This depends on LuaSec changes which are not yet upstream.
From Martijn's original email:
So first my analysis of luasec. in ssl.c the socket is put into blocking
mode right before calling SSL_shutdown() inside meth_destroy(). My best
guess to why this is is because meth_destroy is linked to the __close
and __gc methods, which can't exactly be called multiple times and
luasec does want to make sure that a tls session is shutdown as clean
as possible.
I can't say I disagree with this reasoning and don't want to change this
behaviour. My solution to this without changing the current behaviour is
to introduce a shutdown() method. I am aware that this overlaps in a
conflicting way with tcp's shutdown method, but it stays close to the
OpenSSL name. This method calls SSL_shutdown() in the current
(non)blocking mode of the underlying socket and returns a boolean
whether or not the shutdown is completed (matching SSL_shutdown()'s 0
or 1 return values), and returns the familiar ssl_ioerror() strings on
error with a false for completion. This error can then be used to
determine if we have wantread/wantwrite to finalize things. Once
meth_shutdown() has been called once a shutdown flag will be set, which
indicates to meth_destroy() that the SSL_shutdown() has been handled
by the application and it shouldn't be needed to set the socket to
blocking mode. I've left the SSL_shutdown() call in the
LSEC_STATE_CONNECTED to prevent TOCTOU if the application reaches a
timeout for the shutdown code, which might allow SSL_shutdown() to
clean up anyway at the last possible moment.
Another thing I've changed to luasec is the call to socket_setblocking()
right before calling close(2) in socket_destroy() in usocket.c.
According to the latest POSIX[0]:
Note that the requirement for close() on a socket to block for up to
the current linger interval is not conditional on the O_NONBLOCK
setting.
Which I read to mean that removing O_NONBLOCK on the socket before close
doesn't impact the behaviour and only causes noise in system call
tracers. I didn't touch the windows bits of this, since I don't do
windows.
For the prosody side of things I've made the TLS shutdown bits resemble
interface:onwritable(), and put it under a combined guard of self._tls
and self.conn.shutdown. The self._tls bit is there to prevent getting
stuck on this condition, and self.conn.shutdown is there to prevent the
code being called by instances where the patched luasec isn't deployed.
The destroy() method can be called from various places and is read by
me as the "we give up" error path. To accommodate for these unexpected
entrypoints I've added a single call to self.conn:shutdown() to prevent
the socket being put into blocking mode. I have no expectations that
there is any other use here. Same as previous, the self.conn.shutdown
check is there to make sure it's not called on unpatched luasec
deployments and self._tls is there to make sure we don't call shutdown()
on tcp sockets.
I wouldn't recommend logging of the conn:shutdown() error inside
close(), since a lot of clients simply close the connection before
SSL_shutdown() is done.
| author | Martijn van Duren <martijn@openbsd.org> |
|---|---|
| date | Thu, 06 Feb 2025 15:04:38 +0000 |
| parents | dba43269db5e |
| children |
| rev | line source |
|---|---|
|
12145
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- XEP-0401: Easy User Onboarding |
|
12977
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
2 local dataforms = require "prosody.util.dataforms"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
3 local datetime = require "prosody.util.datetime"; |
|
74b9e05af71e
plugins: Prefix module imports with prosody namespace
Kim Alvefur <zash@zash.se>
parents:
12642
diff
changeset
|
4 local split_jid = require "prosody.util.jid".split; |
|
13527
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
5 local adhocutil = require "prosody.util.adhoc"; |
|
12145
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 local new_adhoc = module:require("adhoc").new; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 -- Whether local users can invite other users to create an account on this server |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local allow_user_invites = module:get_option_boolean("allow_user_invites", false); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 -- Who can see and use the contact invite command. It is strongly recommended to |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 -- keep this available to all local users. To allow/disallow invite-registration |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 -- on the server, use the option above instead. |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 local allow_contact_invites = module:get_option_boolean("allow_contact_invites", true); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 |
|
13170
082c7d856e61
core, plugins: Split prosody:user role into prosody:{guest,registered,member}
Matthew Wild <mwild1@gmail.com>
parents:
12977
diff
changeset
|
16 module:default_permission(allow_user_invites and "prosody:registered" or "prosody:admin", ":invite-users"); |
|
12145
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 local invites; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 if prosody.shutdown then -- COMPAT hack to detect prosodyctl |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 invites = module:depends("invites"); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 end |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local invite_result_form = dataforms.new({ |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 title = "Your invite has been created", |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 name = "url" ; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 var = "landing-url"; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 label = "Invite web page"; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 desc = "Share this link"; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 }, |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 name = "uri"; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 label = "Invite URI"; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 desc = "This alternative link can be opened with some XMPP clients"; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 }, |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 name = "expire"; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
38 label = "Invite valid until"; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
39 }, |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
40 }); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
41 |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
42 -- This is for checking if the specified JID may create invites |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
43 -- that allow people to register accounts on this host. |
|
12642
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12491
diff
changeset
|
44 local function may_invite_new_users(context) |
|
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12491
diff
changeset
|
45 return module:may(":invite-users", context); |
|
12145
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
46 end |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
47 |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
48 module:depends("adhoc"); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
49 |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
50 -- This command is available to all local users, even if allow_user_invites = false |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
51 -- If allow_user_invites is false, creating an invite still works, but the invite will |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
52 -- not be valid for registration on the current server, only for establishing a roster |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
53 -- subscription. |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
54 module:provides("adhoc", new_adhoc("Create new contact invite", "urn:xmpp:invite#invite", |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
55 function (_, data) |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
56 local username, host = split_jid(data.from); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
57 if host ~= module.host then |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
58 return { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
59 status = "completed"; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
60 error = { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
61 message = "This command is only available to users of "..module.host; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
62 }; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
63 }; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
64 end |
|
12642
9061f9621330
Switch to a new role-based authorization framework, removing is_admin()
Matthew Wild <mwild1@gmail.com>
parents:
12491
diff
changeset
|
65 local invite = invites.create_contact(username, may_invite_new_users(data), { |
|
12145
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
66 source = data.from |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
67 }); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
68 --TODO: check errors |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
69 return { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
70 status = "completed"; |
|
13470
19a9ec94f575
mod_invites_adhoc: Fix result form type (thanks betarays)
Kim Alvefur <zash@zash.se>
parents:
12491
diff
changeset
|
71 result = { |
|
12145
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
72 layout = invite_result_form; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
73 values = { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
74 uri = invite.uri; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
75 url = invite.landing_page; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
76 expire = datetime.datetime(invite.expires); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
77 }; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
78 }; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
79 }; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
80 end, allow_contact_invites and "local_user" or "admin")); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
81 |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
82 -- This is an admin-only command that creates a new invitation suitable for registering |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
83 -- a new account. It does not add the new user to the admin's roster. |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
84 module:provides("adhoc", new_adhoc("Create new account invite", "urn:xmpp:invite#create-account", |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
85 function (_, data) |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
86 local invite = invites.create_account(nil, { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
87 source = data.from |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
88 }); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
89 --TODO: check errors |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
90 return { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
91 status = "completed"; |
|
13470
19a9ec94f575
mod_invites_adhoc: Fix result form type (thanks betarays)
Kim Alvefur <zash@zash.se>
parents:
12491
diff
changeset
|
92 result = { |
|
12145
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
93 layout = invite_result_form; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
94 values = { |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
95 uri = invite.uri; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
96 url = invite.landing_page; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
97 expire = datetime.datetime(invite.expires); |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
98 }; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
99 }; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
100 }; |
|
212bac94aedd
mod_invites_adhoc: Import from prosody-modules@5001104f0275
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
101 end, "admin")); |
|
13527
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
102 |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
103 local password_reset_form = dataforms.new({ |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
104 title = "Generate Password Reset Invite"; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
105 { |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
106 name = "accountjid"; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
107 type = "jid-single"; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
108 required = true; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
109 label = "The XMPP ID for the account to generate a password reset invite for"; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
110 }; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
111 }); |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
112 |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
113 module:provides("adhoc", new_adhoc("Create password reset invite", "xmpp:prosody.im/mod_invites_adhoc#password-reset", |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
114 adhocutil.new_simple_form(password_reset_form, |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
115 function (fields, err) |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
116 if err then return { status = "completed"; error = { message = "Fill in the form correctly" } }; end |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
117 local username = split_jid(fields.accountjid); |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
118 local invite = invites.create_account_reset(username); |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
119 return { |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
120 status = "completed"; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
121 result = { |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
122 layout = invite_result_form; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
123 values = { |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
124 uri = invite.uri; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
125 url = invite.landing_page; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
126 expire = datetime.datetime(invite.expires); |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
127 }; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
128 }; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
129 }; |
|
dba43269db5e
mod_invites_adhoc: Add password reset command
Kim Alvefur <zash@zash.se>
parents:
13472
diff
changeset
|
130 end), "admin")); |
