From 8be74165693b02d25e3d728b54f4e3d6c5015572 Mon Sep 17 00:00:00 2001 From: souliane Date: Wed, 21 May 2014 23:15:01 +0200 Subject: [PATCH] core, stdui (profile manager), quick_app: ask for another XMPP password when profile authentication succeed but XMPP connection fails --- frontends/src/quick_frontend/quick_app.py | 2 +- src/core/constants.py | 3 ++- src/core/sat_main.py | 1 + src/stdui/ui_profile_manager.py | 32 +++++++++++++++++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/frontends/src/quick_frontend/quick_app.py b/frontends/src/quick_frontend/quick_app.py index dd7bbf59..16dec97e 100644 --- a/frontends/src/quick_frontend/quick_app.py +++ b/frontends/src/quick_frontend/quick_app.py @@ -236,7 +236,7 @@ class QuickApp(object): log.debug(_("Connection Error")) self.disconnected(profile) if error_type == "AUTH_ERROR": - self.showDialog(_("Can't connect to account, please check your password"), _("Connection error"), "error") + self.launchAction(C.CHANGE_XMPP_PASSWD_ID, {}, profile_key=profile) else: log.error(_('FIXME: error_type %s not implemented') % error_type) diff --git a/src/core/constants.py b/src/core/constants.py index f3ebc22a..3ee745bc 100644 --- a/src/core/constants.py +++ b/src/core/constants.py @@ -110,8 +110,9 @@ class Const(object): LOG_LEVELS = (LOG_LVL_DEBUG, LOG_LVL_INFO, LOG_LVL_WARNING, LOG_LVL_ERROR, LOG_LVL_CRITICAL) - # HARD-CODED ACTIONS IDS + # HARD-CODED ACTIONS IDS (generated with uuid.uuid4) AUTHENTICATE_PROFILE_ID = u'b03bbfa8-a4ae-4734-a248-06ce6c7cf562' + CHANGE_XMPP_PASSWD_ID = u'878b9387-de2b-413b-950f-e424a147bcd0' ## Misc ## diff --git a/src/core/sat_main.py b/src/core/sat_main.py index 37f3b13b..9d606b1e 100644 --- a/src/core/sat_main.py +++ b/src/core/sat_main.py @@ -238,6 +238,7 @@ class SAT(service.Service): d.addCallback(connectXMPPClient) return d + self._initialised.addErrback(lambda dummy: None) # allow successive attempts return self._initialised.addCallback(backendInitialised) @defer.inlineCallbacks diff --git a/src/stdui/ui_profile_manager.py b/src/stdui/ui_profile_manager.py index 445de399..6027c3f7 100644 --- a/src/stdui/ui_profile_manager.py +++ b/src/stdui/ui_profile_manager.py @@ -22,6 +22,7 @@ from sat.core.i18n import _, D_ from sat.core.constants import Const as C from sat.tools import xml_tools from sat.memory.crypto import PasswordHasher +from sat.memory.memory import ProfileSessions from twisted.internet import defer @@ -31,7 +32,10 @@ class ProfileManager(object): def __init__(self, host): self.host = host self.profile_ciphers = {} + self._sessions = ProfileSessions() host.registerCallback(self._authenticateProfile, force_id=C.AUTHENTICATE_PROFILE_ID, with_data=True) + host.registerCallback(self._changeXMPPPassword, force_id=C.CHANGE_XMPP_PASSWD_ID, with_data=True) + self.__new_xmpp_passwd_id = host.registerCallback(self._changeXMPPPasswordCb, with_data=True) def _authenticateProfile(self, data, profile): """Get the data/dialog for connecting a profile @@ -96,9 +100,33 @@ class ProfileManager(object): profile_password = data['profile_password'] # not received from a user input verified = yield PasswordHasher.verify(profile_password, self.profile_ciphers[profile]) if not verified: - _dialog = xml_tools.XMLUI('popup', title=D_('Error')) - _dialog.addText(_("The provided profile password doesn't match.")) + _dialog = xml_tools.XMLUI('popup', title=D_('Connection error')) + _dialog.addText(D_("The provided profile password doesn't match.")) defer.returnValue({'xmlui': _dialog.toXml()}) yield self.host.memory.newAuthSession(profile_password, profile) defer.returnValue({'authenticated_profile': profile, 'caller': data['caller']}) + + def _changeXMPPPassword(self, data, profile): + session_data = self._sessions.profileGetUnique(profile) + if not session_data: + server = self.host.memory.getParamA("Server", "Connection", profile_key=profile) + session_id, session_data = self._sessions.newSession({'count': 0, 'server': server}, profile) + if session_data['count'] > 2: # 3 attempts with a new password after the initial try + self._sessions.profileDelUnique(profile) + _dialog = xml_tools.XMLUI('popup', title=D_('Connection error')) + _dialog.addText(D_("Can't connect to %s. Please check your connection details.") % session_data['server']) + return {'xmlui': _dialog.toXml()} + session_data['count'] += 1 + counter = ' (%d)' % session_data['count'] if session_data['count'] > 1 else '' + title = D_('XMPP password for %(profile)s%(counter)s') % {'profile': profile, 'counter': counter} + form_ui = xml_tools.XMLUI("form", title=title, submit_id=self.__new_xmpp_passwd_id) + form_ui.addText(D_("Can't connect to %s. Please check your connection details or try with another password.") % session_data['server']) + form_ui.addPassword('xmpp_password', value='') + return {'xmlui': form_ui.toXml()} + + def _changeXMPPPasswordCb(self, data, profile): + xmpp_password = data[xml_tools.formEscape('xmpp_password')] + d = self.host.memory.setParam("Password", xmpp_password, "Connection", profile_key=profile) + d.addCallback(lambda dummy: self.host.asyncConnect(profile)) + return {}