annotate sat/plugins/plugin_xep_0077.py @ 2886:b06cb71079fa

core (xmpp): new networkEnabled() and networkDisabled() methods: those methods can be called by platform specific plugins when network is known to be (un)available. This way, connection attempts can be cancelled when no network is available, saving resources (notably battery on mobile devices), or attempts can be restarted immediately when network is known to be available again.
author Goffi <goffi@goffi.org>
date Sat, 06 Apr 2019 19:05:57 +0200
parents 8018cf9aa55b
children ab2696e34d29
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1934
2daf7b4c6756 use of /usr/bin/env instead of /usr/bin/python in shebang
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
1 #!/usr/bin/env python2
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
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
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2765
diff changeset
5 # Copyright (C) 2009-2019 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
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 761
diff changeset
20 from sat.core.i18n import _
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 876
diff changeset
21 from sat.core.constants import Const as C
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
22 from sat.core import exceptions
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
23 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
24
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
25 log = getLogger(__name__)
2838
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
26 from twisted.words.protocols.jabber import jid, xmlstream, client, error as jabber_error
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
27 from twisted.internet import defer, reactor
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
28 from sat.tools import xml_tools
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
30 from wokkel import data_form
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):
2634
6c89cf856d28 plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
54 log.debug(_(u"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)]
2838
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
67 tls_init = xmlstream.TLSInitiatingInitializer(xs)
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
68 tls_init.required = False
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
69 tls_init.check_certificate = self.check_certificate
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
70 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
71
2634
6c89cf856d28 plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
72 def register(self, xmlstream):
6c89cf856d28 plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
73 log.debug(_(u"Stream started with {server}, now registering"
6c89cf856d28 plugin XEP-0077: fixed RegisteringAuthenticator to use TLS if possible
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
74 .format(server=self.jid.host)))
2175
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
75 iq = XEP_0077.buildRegisterIQ(self.xmlstream, self.jid, self.password, self.email)
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
76 d = iq.send(self.jid.host).addCallbacks(self.registrationCb, self.registrationEb)
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
77 d.chainDeferred(self.registered)
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
78
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
79 def registrationCb(self, answer):
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
80 log.debug(_(u"Registration answer: {}").format(answer.toXml()))
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
81 self.xmlstream.sendFooter()
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
82
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
83 def registrationEb(self, failure_):
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
84 log.info(_("Registration failure: {}").format(unicode(failure_.value)))
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
85 self.xmlstream.sendFooter()
2183
1b42bd8c10fb plugin XEP-0077: minor raise fix
Goffi <goffi@goffi.org>
parents: 2177
diff changeset
86 raise failure_
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
87
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
88
2838
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
89 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
90
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
91 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
92 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
93 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
94
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
95 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
96 connector.disconnect()
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
97
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
98 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
99 if not self.authenticator.registered.called:
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
100 err = jabber_error.StreamError(u"Server unexpectedly closed the connection")
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
101 try:
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
102 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
103 err = exceptions.InvalidCertificate()
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
104 except (IndexError, TypeError):
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
105 pass
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
106 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
107
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
108
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
109 class XEP_0077(object):
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 941
diff changeset
111 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
112 self.host = host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
113 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 "inBandRegister",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 in_sign="ss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 method=self._inBandRegister,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 "inBandAccountNew",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 in_sign="ssssi",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 method=self._registerNewAccount,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 "inBandUnregister",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
131 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
132 in_sign="ss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
133 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 method=self._unregister,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
135 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
137 host.bridge.addMethod(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
138 "inBandPasswordChange",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
139 ".plugin",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
140 in_sign="ss",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 out_sign="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
142 method=self._changePassword,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
143 async=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
144 )
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
145
2175
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
146 @staticmethod
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
147 def buildRegisterIQ(xmlstream_, jid_, password, email=None):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
148 iq_elt = xmlstream.IQ(xmlstream_, "set")
2175
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
149 iq_elt["to"] = jid_.host
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
150 query_elt = iq_elt.addElement(("jabber:iq:register", "query"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
151 username_elt = query_elt.addElement("username")
2175
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
152 username_elt.addContent(jid_.user)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
153 password_elt = query_elt.addElement("password")
2175
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
154 password_elt.addContent(password)
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
155 if email is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 email_elt = query_elt.addElement("email")
2175
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
157 email_elt.addContent(email)
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
158 return iq_elt
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
159
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
160 def _regCb(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
161 """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
162 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
163 query_elt = answer.elements(NS_REG, "query").next()
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
164 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
165 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
166
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
167 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 x_elem = query_elt.elements(data_form.NS_X_DATA, "x").next()
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 # 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
171 log.warning(_("Can't find data form"))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 raise exceptions.DataError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 _("This gateway can't be managed by SàT, sorry :(")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
174 )
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
175
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
176 def submitForm(data, profile):
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
177 form_elt = xml_tools.XMLUIResultToElt(data)
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
178
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
179 iq_elt = client.IQ()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 iq_elt["id"] = answer["id"]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 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
182 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
183 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
184 d = iq_elt.send()
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
185 d.addCallback(self._regSuccess, client, post_treat_cb)
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
186 d.addErrback(self._regFailure, client)
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 return d
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
188
39
2e3411a6baad Wix: external server management in gateways manager, SàT: bug fixes in gateway management
Goffi <goffi@goffi.org>
parents: 37
diff changeset
189 form = data_form.Form.fromElement(x_elem)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
190 submit_reg_id = self.host.registerCallback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 submitForm, with_data=True, one_shot=True
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 )
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
193 return xml_tools.dataForm2XMLUI(form, submit_reg_id)
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
194
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
195 def _regEb(self, failure, client):
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
196 """Called when something is wrong with registration"""
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
197 log.info(_("Registration failure: %s") % unicode(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
198 raise failure
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
199
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
200 def _regSuccess(self, answer, client, post_treat_cb):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
201 log.debug(_(u"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
202 if post_treat_cb is not None:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
203 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
204 return {}
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
205
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
206 def _regFailure(self, failure, client):
1409
3265a2639182 massive (preventive) addition of 'u' (unicode) before the strings passed to logging functions
souliane <souliane@mailoo.org>
parents: 1396
diff changeset
207 log.info(_(u"Registration failure: %s") % unicode(failure.value))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
208 if failure.value.condition == "conflict":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
209 raise exceptions.ConflictError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
210 _("Username already exists, please choose an other one")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
211 )
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
212 raise failure
37
a61beb21d16d Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents: 36
diff changeset
213
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 876
diff changeset
214 def _inBandRegister(self, to_jid_s, profile_key=C.PROF_KEY_NONE):
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
215 return self.inBandRegister, jid.JID(to_jid_s, profile_key)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
216
916
1a759096ccbd core: use of Const for profile_key + replaced '@DEFAULT@' default profile_key by '@NONE@'
Goffi <goffi@goffi.org>
parents: 876
diff changeset
217 def inBandRegister(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
218 """register to a service
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
219
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
220 @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
221 """
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
222 # FIXME: this post_treat_cb arguments seems wrong, check it
538
2c4016921403 core, frontends, bridgen plugins: fixed methods which were unproperly managing multi-profiles
Goffi <goffi@goffi.org>
parents: 480
diff changeset
223 client = self.host.getClient(profile_key)
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
224 log.debug(_(u"Asking registration for {}").format(to_jid.full()))
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
225 reg_request = client.IQ(u"get")
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
226 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
227 reg_request["to"] = to_jid.full()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 reg_request.addElement("query", NS_REG)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
229 d = reg_request.send(to_jid.full()).addCallbacks(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 self._regCb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 self._regEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
232 callbackArgs=[client, post_treat_cb],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 errbackArgs=[client],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234 )
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
235 return d
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
236
2177
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
237 def _registerNewAccount(self, jid_, password, email, host, port):
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
238 kwargs = {}
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
239 if email:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
240 kwargs["email"] = email
2177
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
241 if host:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
242 kwargs["host"] = host
2177
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
243 if port:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 kwargs["port"] = port
2177
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
245 return self.registerNewAccount(jid.JID(jid_), password, **kwargs)
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
246
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
247 def registerNewAccount(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
248 self, jid_, password, email=None, host=u"127.0.0.1", port=C.XMPP_C2S_PORT
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
249 ):
2172
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
250 """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
251
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
252 @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
253 @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
254 @param email(unicode): email of the account
545a1261ac3b core, plugin XEP-0077: in-band registration fix and move:
Goffi <goffi@goffi.org>
parents: 2145
diff changeset
255 @param host(unicode): host 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
256 @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
257 """
2838
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
258 check_certificate = host != u"127.0.0.1"
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
259 authenticator = RegisteringAuthenticator(
8018cf9aa55b plugin XEP-0077: correctly report invalid certificate + errback on unexpected stream close
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
260 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
261 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
262 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
263 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
264 return registered_d
2175
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
265
2177
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
266 def _changePassword(self, new_password, profile_key):
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
267 client = self.host.getClient(profile_key)
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
268 return self.changePassword(client, new_password)
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
269
2175
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
270 def changePassword(self, client, new_password):
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
271 iq_elt = self.buildRegisterIQ(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
272 d = iq_elt.send(client.jid.host)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
273 d.addCallback(
2765
378188abe941 misc: replaced all "dummy" by the more conventional and readable "__" ("_" being used for gettext)
Goffi <goffi@goffi.org>
parents: 2634
diff changeset
274 lambda __: self.host.memory.setParam(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
275 "Password", new_password, "Connection", profile_key=client.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
276 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
277 )
2177
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
278 return d
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
279
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
280 def _unregister(self, to_jid_s, profile_key):
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
281 client = self.host.getClient(profile_key)
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
282 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
283
2177
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
284 def unregister(self, client, to_jid):
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
285 """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
286
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
287 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
288 DELETE THE XMPP ACCOUNT WITHOUT WARNING
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
289 @param to_jid(jid.JID): jid of the service or server
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
290 """
2175
75002ac33801 plugin XEP-0077: added changePassword and removeRegistration methods
Goffi <goffi@goffi.org>
parents: 2172
diff changeset
291 iq_elt = client.IQ()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
292 iq_elt["to"] = to_jid.full()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
293 query_elt = iq_elt.addElement((NS_REG, u"query"))
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
294 query_elt.addElement(u"remove")
2177
09cfec4d8d19 plugin XEP-0077: added inBandAccountNew, inBandUnregister and inBandPasswordChange bridge methods
Goffi <goffi@goffi.org>
parents: 2175
diff changeset
295 return iq_elt.send()