plugin XEP-0070: use a confirm dialog instead of a form + simplified a bit the code
This commit is contained in:
parent
744cb0c503
commit
d5c9fa5e31
1 changed files with 59 additions and 81 deletions
|
|
@ -95,43 +95,21 @@ class XEP_0070(object):
|
|||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue