Mercurial > libervia-backend
annotate libervia/backend/plugins/plugin_xep_0077.py @ 4226:3f7ca590a5da
cli (pubsub): use `PEP` when service is not specified in error message.
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 05 Mar 2024 17:31:56 +0100 |
parents | 4b842c1fb686 |
children | 0d7bb4df2343 |
rev | line source |
---|---|
3028 | 1 #!/usr/bin/env python3 |
3137 | 2 |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
4 # SAT plugin for managing xep-0077 |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
10 # (at your option) any later version. |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
15 # GNU Affero General Public License for more details. |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
609
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
84a6e83157c2
fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents:
594
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
3334
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
20 from twisted.words.protocols.jabber import jid, xmlstream, client, error as jabber_error |
3354
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
21 from twisted.internet import defer, reactor, ssl |
3334
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
22 from wokkel import data_form |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
24 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
25 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.core.log import getLogger |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
27 from libervia.backend.core.xmpp import SatXMPPEntity |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
28 from libervia.backend.tools import xml_tools |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
29 |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
30 log = getLogger(__name__) |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
30
diff
changeset
|
31 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
32 NS_REG = "jabber:iq:register" |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 PLUGIN_INFO = { |
2145
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
35 C.PI_NAME: "XEP 0077 Plugin", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
36 C.PI_IMPORT_NAME: "XEP-0077", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
37 C.PI_TYPE: "XEP", |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
38 C.PI_PROTOCOLS: ["XEP-0077"], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
39 C.PI_DEPENDENCIES: [], |
33c8c4973743
core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents:
1934
diff
changeset
|
40 C.PI_MAIN: "XEP_0077", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
41 C.PI_DESCRIPTION: _("""Implementation of in-band registration"""), |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 } |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
44 # FIXME: this implementation is incomplete |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
45 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
46 |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
47 class RegisteringAuthenticator(xmlstream.ConnectAuthenticator): |
2634
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
48 # FIXME: request IQ is not send to check available fields, |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
49 # while XEP recommand to use it |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
50 # FIXME: doesn't handle data form or oob |
2634
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
51 namespace = 'jabber:client' |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
52 |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
53 def __init__(self, jid_, password, email=None, check_certificate=True): |
3028 | 54 log.debug(_("Registration asked for {jid}").format(jid=jid_)) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
55 xmlstream.ConnectAuthenticator.__init__(self, jid_.host) |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
56 self.jid = jid_ |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
57 self.password = password |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
58 self.email = email |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
59 self.check_certificate = check_certificate |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
60 self.registered = defer.Deferred() |
2634
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
61 |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
62 def associateWithStream(self, xs): |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
63 xmlstream.ConnectAuthenticator.associateWithStream(self, xs) |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
64 xs.addObserver(xmlstream.STREAM_AUTHD_EVENT, self.register) |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
65 |
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
66 xs.initializers = [client.CheckVersionInitializer(xs)] |
3354
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
67 if self.check_certificate: |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
68 tls_required, configurationForTLS = True, None |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
69 else: |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
70 tls_required = False |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
71 configurationForTLS = ssl.CertificateOptions(trustRoot=None) |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
72 tls_init = xmlstream.TLSInitiatingInitializer( |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
73 xs, required=tls_required, configurationForTLS=configurationForTLS) |
aafb53248872
plugin XEP-0077: fixed "check_certificate" handling
Goffi <goffi@goffi.org>
parents:
3334
diff
changeset
|
74 |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
75 xs.initializers.append(tls_init) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
76 |
2634
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
77 def register(self, xmlstream): |
3028 | 78 log.debug(_("Stream started with {server}, now registering" |
2634
6c89cf856d28
plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents:
2624
diff
changeset
|
79 .format(server=self.jid.host))) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
80 iq = XEP_0077.build_register_iq(self.xmlstream, self.jid, self.password, self.email) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
81 d = iq.send(self.jid.host).addCallbacks(self.registration_cb, self.registration_eb) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
82 d.chainDeferred(self.registered) |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
83 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
84 def registration_cb(self, answer): |
3028 | 85 log.debug(_("Registration answer: {}").format(answer.toXml())) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
86 self.xmlstream.sendFooter() |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
87 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
88 def registration_eb(self, failure_): |
3028 | 89 log.info(_("Registration failure: {}").format(str(failure_.value))) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
90 self.xmlstream.sendFooter() |
2183 | 91 raise failure_ |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
92 |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
93 |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
94 class ServerRegister(xmlstream.XmlStreamFactory): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
95 |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
96 def __init__(self, *args, **kwargs): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
97 xmlstream.XmlStreamFactory.__init__(self, *args, **kwargs) |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
98 self.addBootstrap(xmlstream.STREAM_END_EVENT, self._disconnected) |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
99 |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
100 def clientConnectionLost(self, connector, reason): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
101 connector.disconnect() |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
102 |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
103 def _disconnected(self, reason): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
104 if not self.authenticator.registered.called: |
3028 | 105 err = jabber_error.StreamError("Server unexpectedly closed the connection") |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
106 try: |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
107 if reason.value.args[0][0][2] == "certificate verify failed": |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
108 err = exceptions.InvalidCertificate() |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
109 except (IndexError, TypeError): |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
110 pass |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
111 self.authenticator.registered.errback(err) |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
112 |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
113 |
588
beaf6bec2fcd
Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
587
diff
changeset
|
114 class XEP_0077(object): |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 def __init__(self, host): |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
116 log.info(_("Plugin XEP_0077 initialization")) |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 self.host = host |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
118 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
119 "in_band_register", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
120 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
121 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
123 method=self._in_band_register, |
3028 | 124 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
126 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
127 "in_band_account_new", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
128 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
129 in_sign="ssssi", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
131 method=self._register_new_account, |
3028 | 132 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
134 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
135 "in_band_unregister", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
137 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
138 out_sign="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
139 method=self._unregister, |
3028 | 140 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
141 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
142 host.bridge.add_method( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
143 "in_band_password_change", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
144 ".plugin", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
145 in_sign="ss", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
146 out_sign="", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
147 method=self._change_password, |
3028 | 148 async_=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
149 ) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
150 |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
151 @staticmethod |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
152 def build_register_iq(xmlstream_, jid_, password, email=None): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
153 iq_elt = xmlstream.IQ(xmlstream_, "set") |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
154 iq_elt["to"] = jid_.host |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
155 query_elt = iq_elt.addElement(("jabber:iq:register", "query")) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
156 username_elt = query_elt.addElement("username") |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
157 username_elt.addContent(jid_.user) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
158 password_elt = query_elt.addElement("password") |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
159 password_elt.addContent(password) |
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
160 if email is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
161 email_elt = query_elt.addElement("email") |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
162 email_elt.addContent(email) |
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
163 return iq_elt |
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
164 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
165 def _reg_cb(self, answer, client, post_treat_cb): |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 """Called after the first get IQ""" |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
167 try: |
3028 | 168 query_elt = next(answer.elements(NS_REG, "query")) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
169 except StopIteration: |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
170 raise exceptions.DataError("Can't find expected query element") |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
171 |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
172 try: |
3028 | 173 x_elem = next(query_elt.elements(data_form.NS_X_DATA, "x")) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
174 except StopIteration: |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
175 # XXX: it seems we have an old service which doesn't manage data forms |
993
301b342c697a
core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents:
941
diff
changeset
|
176 log.warning(_("Can't find data form")) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
177 raise exceptions.DataError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
178 _("This gateway can't be managed by SàT, sorry :(") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
179 ) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
180 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
181 def submit_form(data, profile): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
182 form_elt = xml_tools.xmlui_result_to_elt(data) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
183 |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
184 iq_elt = client.IQ() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
185 iq_elt["id"] = answer["id"] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
186 iq_elt["to"] = answer["from"] |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
187 query_elt = iq_elt.addElement("query", NS_REG) |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
188 query_elt.addChild(form_elt) |
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
189 d = iq_elt.send() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
190 d.addCallback(self._reg_success, client, post_treat_cb) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
191 d.addErrback(self._reg_failure, client) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
192 return d |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
193 |
39
2e3411a6baad
Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents:
37
diff
changeset
|
194 form = data_form.Form.fromElement(x_elem) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
195 submit_reg_id = self.host.register_callback( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
196 submit_form, with_data=True, one_shot=True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
197 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
198 return xml_tools.data_form_2_xmlui(form, submit_reg_id) |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
200 def _reg_eb(self, failure, client): |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 """Called when something is wrong with registration""" |
3028 | 202 log.info(_("Registration failure: %s") % str(failure.value)) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
203 raise failure |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
204 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
205 def _reg_success(self, answer, client, post_treat_cb): |
3028 | 206 log.debug(_("registration answer: %s") % answer.toXml()) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
207 if post_treat_cb is not None: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
208 post_treat_cb(jid.JID(answer["from"]), client.profile) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
209 return {} |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
210 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
211 def _reg_failure(self, failure, client): |
3028 | 212 log.info(_("Registration failure: %s") % str(failure.value)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
213 if failure.value.condition == "conflict": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
214 raise exceptions.ConflictError( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
215 _("Username already exists, please choose an other one") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
216 ) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
217 raise failure |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
36
diff
changeset
|
218 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
219 def _in_band_register(self, to_jid_s, profile_key=C.PROF_KEY_NONE): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
220 return self.in_band_register, jid.JID(to_jid_s, profile_key) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
221 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
222 def in_band_register(self, to_jid, post_treat_cb=None, profile_key=C.PROF_KEY_NONE): |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
223 """register to a service |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
224 |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
225 @param to_jid(jid.JID): jid of the service to register to |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
226 """ |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
227 # FIXME: this post_treat_cb arguments seems wrong, check it |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
228 client = self.host.get_client(profile_key) |
3028 | 229 log.debug(_("Asking registration for {}").format(to_jid.full())) |
230 reg_request = client.IQ("get") | |
594
e629371a28d3
Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
588
diff
changeset
|
231 reg_request["from"] = client.jid.full() |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 reg_request["to"] = to_jid.full() |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
233 reg_request.addElement("query", NS_REG) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 d = reg_request.send(to_jid.full()).addCallbacks( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
235 self._reg_cb, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
236 self._reg_eb, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
237 callbackArgs=[client, post_treat_cb], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
238 errbackArgs=[client], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
239 ) |
807
be4c5e24dab9
plugin XEP-0077, plugin XEP-0100, frontends: gateways have been entirely implemented in backend using the new refactored XMLUI and AdvancedListContainer. The now useless code has been removed from frontends.
Goffi <goffi@goffi.org>
parents:
771
diff
changeset
|
240 return d |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
241 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
242 def _register_new_account(self, jid_, password, email, host, port): |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
243 kwargs = {} |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
244 if email: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
245 kwargs["email"] = email |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
246 if host: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
247 kwargs["host"] = host |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
248 if port: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
249 kwargs["port"] = port |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
250 return self.register_new_account(jid.JID(jid_), password, **kwargs) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
251 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
252 def register_new_account( |
3426
8c25489bb79c
plugin XEP-0077: use `xmpp_domain` when set for `host`
Goffi <goffi@goffi.org>
parents:
3400
diff
changeset
|
253 self, jid_, password, email=None, host=None, port=C.XMPP_C2S_PORT |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
254 ): |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
255 """register a new account on a XMPP server |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
256 |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
257 @param jid_(jid.JID): request jid to register |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
258 @param password(unicode): password of the account |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
259 @param email(unicode): email of the account |
3426
8c25489bb79c
plugin XEP-0077: use `xmpp_domain` when set for `host`
Goffi <goffi@goffi.org>
parents:
3400
diff
changeset
|
260 @param host(None, unicode): host of the server to register to |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
261 @param port(int): port of the server to register to |
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
262 """ |
3426
8c25489bb79c
plugin XEP-0077: use `xmpp_domain` when set for `host`
Goffi <goffi@goffi.org>
parents:
3400
diff
changeset
|
263 if host is None: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
264 host = self.host.memory.config_get("", "xmpp_domain", "127.0.0.1") |
3028 | 265 check_certificate = host != "127.0.0.1" |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
266 authenticator = RegisteringAuthenticator( |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
267 jid_, password, email, check_certificate=check_certificate) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
268 registered_d = authenticator.registered |
2838
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
269 server_register = ServerRegister(authenticator) |
8018cf9aa55b
plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
270 reactor.connectTCP(host, port, server_register) |
2172
545a1261ac3b
core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents:
2145
diff
changeset
|
271 return registered_d |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
272 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
273 def _change_password(self, new_password, profile_key): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
274 client = self.host.get_client(profile_key) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
275 return self.change_password(client, new_password) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
276 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
277 def change_password(self, client, new_password): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
278 iq_elt = self.build_register_iq(client.xmlstream, client.jid, new_password) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
279 d = iq_elt.send(client.jid.host) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
280 d.addCallback( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
281 lambda __: self.host.memory.param_set( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
282 "Password", new_password, "Connection", profile_key=client.profile |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
283 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
284 ) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
285 return d |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
286 |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
287 def _unregister(self, to_jid_s, profile_key): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
288 client = self.host.get_client(profile_key) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
289 return self.unregister(client, jid.JID(to_jid_s)) |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
290 |
3334
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
291 def unregister( |
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
292 self, |
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
293 client: SatXMPPEntity, |
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
294 to_jid: jid.JID |
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
295 ) -> defer.Deferred: |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
296 """remove registration from a server/service |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
297 |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
298 BEWARE! if you remove registration from profile own server, this will |
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
299 DELETE THE XMPP ACCOUNT WITHOUT WARNING |
3334
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
300 @param to_jid: jid of the service or server |
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
301 None to delete client's account (DANGEROUS!) |
2177
09cfec4d8d19
plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents:
2175
diff
changeset
|
302 """ |
2175
75002ac33801
plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents:
2172
diff
changeset
|
303 iq_elt = client.IQ() |
3334
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
304 if to_jid is not None: |
2cd54c72fae4
plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`:
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
305 iq_elt["to"] = to_jid.full() |
3028 | 306 query_elt = iq_elt.addElement((NS_REG, "query")) |
307 query_elt.addElement("remove") | |
3400
77ad87763f32
plugin XEP-0077: disconnect client when deleting self account:
Goffi <goffi@goffi.org>
parents:
3354
diff
changeset
|
308 d = iq_elt.send() |
77ad87763f32
plugin XEP-0077: disconnect client when deleting self account:
Goffi <goffi@goffi.org>
parents:
3354
diff
changeset
|
309 if not to_jid or to_jid == jid.JID(client.jid.host): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
310 d.addCallback(lambda __: client.entity_disconnect()) |
3400
77ad87763f32
plugin XEP-0077: disconnect client when deleting self account:
Goffi <goffi@goffi.org>
parents:
3354
diff
changeset
|
311 return d |
77ad87763f32
plugin XEP-0077: disconnect client when deleting self account:
Goffi <goffi@goffi.org>
parents:
3354
diff
changeset
|
312 |