diff sat/plugins/plugin_xep_0070.py @ 2625:a55a14c3cbf4

plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 21:15:34 +0200
parents 56f94936df1e
children ab2696e34d29
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0070.py	Wed Jun 27 20:14:46 2018 +0200
+++ b/sat/plugins/plugin_xep_0070.py	Wed Jun 27 21:15:34 2018 +0200
@@ -95,43 +95,21 @@
         auth_method = auth_elt["method"]
         auth_url = auth_elt["url"]
         self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt)
+        title = D_(u"Auth confirmation")
+        message = D_(u"{auth_url} needs to validate your identity, do you agree?\n"
+                     u"Validation code : {auth_id}\n\n"
+                     u"Please check that this code is the same as on {auth_url}"
+                    ).format(auth_url=auth_url, auth_id=auth_id)
+        d = xml_tools.deferConfirm(self.host, message=message, title=title,
+            profile=client.profile)
+        d.addCallback(self._authRequestCallback, client)
 
-        confirm_ui = xml_tools.XMLUI("form", title=D_(u"Auth confirmation"), submit_id="")
-        confirm_ui.addText(
-            D_(u"{} needs to validate your identity, do you agreeĀ ?".format(auth_url))
-        )
-        confirm_ui.addText(D_(u"Validation code : {}".format(auth_id)))
-        confirm_ui.addText(
-            D_(u"Please check that this code is the same as on {}".format(auth_url))
-        )
-        confirm_ui.addText(u"")
-        confirm_ui.addText(D_(u"Submit to authorize, cancel otherwise."))
-        d = xml_tools.deferredUI(self.host, confirm_ui, chained=False)
-        d.addCallback(self._authRequestCallback, client.profile)
-        self.host.actionNew({u"xmlui": confirm_ui.toXml()}, profile=client.profile)
-
-    def _authRequestCallback(self, result, profile):
-        client = self.host.getClient(profile)
+    def _authRequestCallback(self, authorized, client):
         try:
-            cancelled = result["cancelled"]
+            auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest.pop(
+                client)
         except KeyError:
-            cancelled = False
-
-        authorized = False
-
-        if cancelled:
-            auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest[client]
-            del self._dictRequest[client]
             authorized = False
-        else:
-            try:
-                auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest[
-                    client
-                ]
-                del self._dictRequest[client]
-                authorized = True
-            except KeyError:
-                authorized = False
 
         if authorized:
             if stanzaType == IQ: