comparison 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
comparison
equal deleted inserted replaced
2624:56f94936df1e 2625:a55a14c3cbf4
93 auth_elt = elt.elements(NS_HTTP_AUTH, "confirm").next() 93 auth_elt = elt.elements(NS_HTTP_AUTH, "confirm").next()
94 auth_id = auth_elt["id"] 94 auth_id = auth_elt["id"]
95 auth_method = auth_elt["method"] 95 auth_method = auth_elt["method"]
96 auth_url = auth_elt["url"] 96 auth_url = auth_elt["url"]
97 self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt) 97 self._dictRequest[client] = (auth_id, auth_method, auth_url, stanzaType, elt)
98 title = D_(u"Auth confirmation")
99 message = D_(u"{auth_url} needs to validate your identity, do you agree?\n"
100 u"Validation code : {auth_id}\n\n"
101 u"Please check that this code is the same as on {auth_url}"
102 ).format(auth_url=auth_url, auth_id=auth_id)
103 d = xml_tools.deferConfirm(self.host, message=message, title=title,
104 profile=client.profile)
105 d.addCallback(self._authRequestCallback, client)
98 106
99 confirm_ui = xml_tools.XMLUI("form", title=D_(u"Auth confirmation"), submit_id="") 107 def _authRequestCallback(self, authorized, client):
100 confirm_ui.addText(
101 D_(u"{} needs to validate your identity, do you agreeĀ ?".format(auth_url))
102 )
103 confirm_ui.addText(D_(u"Validation code : {}".format(auth_id)))
104 confirm_ui.addText(
105 D_(u"Please check that this code is the same as on {}".format(auth_url))
106 )
107 confirm_ui.addText(u"")
108 confirm_ui.addText(D_(u"Submit to authorize, cancel otherwise."))
109 d = xml_tools.deferredUI(self.host, confirm_ui, chained=False)
110 d.addCallback(self._authRequestCallback, client.profile)
111 self.host.actionNew({u"xmlui": confirm_ui.toXml()}, profile=client.profile)
112
113 def _authRequestCallback(self, result, profile):
114 client = self.host.getClient(profile)
115 try: 108 try:
116 cancelled = result["cancelled"] 109 auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest.pop(
110 client)
117 except KeyError: 111 except KeyError:
118 cancelled = False
119
120 authorized = False
121
122 if cancelled:
123 auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest[client]
124 del self._dictRequest[client]
125 authorized = False 112 authorized = False
126 else:
127 try:
128 auth_id, auth_method, auth_url, stanzaType, elt = self._dictRequest[
129 client
130 ]
131 del self._dictRequest[client]
132 authorized = True
133 except KeyError:
134 authorized = False
135 113
136 if authorized: 114 if authorized:
137 if stanzaType == IQ: 115 if stanzaType == IQ:
138 # iq 116 # iq
139 log.debug(_(u"XEP-0070 reply iq")) 117 log.debug(_(u"XEP-0070 reply iq"))