comparison sat/plugins/plugin_xep_0077.py @ 3334:2cd54c72fae4

plugin XEP-0077: None can now be used in `to_jid` argument in `unregister`: if None is used, the XMPP account of the profile will be deleted.
author Goffi <goffi@goffi.org>
date Thu, 13 Aug 2020 23:46:18 +0200
parents 559a625a236b
children aafb53248872
comparison
equal deleted inserted replaced
3333:ac9342f359e9 3334:2cd54c72fae4
15 # GNU Affero General Public License for more details. 15 # GNU Affero General Public License for more details.
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from twisted.words.protocols.jabber import jid, xmlstream, client, error as jabber_error
21 from twisted.internet import defer, reactor
22 from wokkel import data_form
20 from sat.core.i18n import _ 23 from sat.core.i18n import _
21 from sat.core.constants import Const as C 24 from sat.core.constants import Const as C
22 from sat.core import exceptions 25 from sat.core import exceptions
23 from sat.core.log import getLogger 26 from sat.core.log import getLogger
27 from sat.core.xmpp import SatXMPPEntity
28 from sat.tools import xml_tools
24 29
25 log = getLogger(__name__) 30 log = getLogger(__name__)
26 from twisted.words.protocols.jabber import jid, xmlstream, client, error as jabber_error
27 from twisted.internet import defer, reactor
28 from sat.tools import xml_tools
29
30 from wokkel import data_form
31 31
32 NS_REG = "jabber:iq:register" 32 NS_REG = "jabber:iq:register"
33 33
34 PLUGIN_INFO = { 34 PLUGIN_INFO = {
35 C.PI_NAME: "XEP 0077 Plugin", 35 C.PI_NAME: "XEP 0077 Plugin",
279 279
280 def _unregister(self, to_jid_s, profile_key): 280 def _unregister(self, to_jid_s, profile_key):
281 client = self.host.getClient(profile_key) 281 client = self.host.getClient(profile_key)
282 return self.unregister(client, jid.JID(to_jid_s)) 282 return self.unregister(client, jid.JID(to_jid_s))
283 283
284 def unregister(self, client, to_jid): 284 def unregister(
285 self,
286 client: SatXMPPEntity,
287 to_jid: jid.JID
288 ) -> defer.Deferred:
285 """remove registration from a server/service 289 """remove registration from a server/service
286 290
287 BEWARE! if you remove registration from profile own server, this will 291 BEWARE! if you remove registration from profile own server, this will
288 DELETE THE XMPP ACCOUNT WITHOUT WARNING 292 DELETE THE XMPP ACCOUNT WITHOUT WARNING
289 @param to_jid(jid.JID): jid of the service or server 293 @param to_jid: jid of the service or server
294 None to delete client's account (DANGEROUS!)
290 """ 295 """
291 iq_elt = client.IQ() 296 iq_elt = client.IQ()
292 iq_elt["to"] = to_jid.full() 297 if to_jid is not None:
298 iq_elt["to"] = to_jid.full()
293 query_elt = iq_elt.addElement((NS_REG, "query")) 299 query_elt = iq_elt.addElement((NS_REG, "query"))
294 query_elt.addElement("remove") 300 query_elt.addElement("remove")
295 return iq_elt.send() 301 return iq_elt.send()