Mercurial > libervia-backend
changeset 1043:066308706dc6
core, stdui (profile manager), quick_app: ask for another XMPP password when profile authentication succeed but XMPP connection fails
author | souliane <souliane@mailoo.org> |
---|---|
date | Wed, 21 May 2014 23:15:01 +0200 |
parents | 59de0c7a28ec |
children | 85c110c0be86 |
files | frontends/src/quick_frontend/quick_app.py src/core/constants.py src/core/sat_main.py src/stdui/ui_profile_manager.py |
diffstat | 4 files changed, 34 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_app.py Wed May 21 21:14:40 2014 +0200 +++ b/frontends/src/quick_frontend/quick_app.py Wed May 21 23:15:01 2014 +0200 @@ -236,7 +236,7 @@ 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)
--- a/src/core/constants.py Wed May 21 21:14:40 2014 +0200 +++ b/src/core/constants.py Wed May 21 23:15:01 2014 +0200 @@ -110,8 +110,9 @@ 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 ##
--- a/src/core/sat_main.py Wed May 21 21:14:40 2014 +0200 +++ b/src/core/sat_main.py Wed May 21 23:15:01 2014 +0200 @@ -238,6 +238,7 @@ d.addCallback(connectXMPPClient) return d + self._initialised.addErrback(lambda dummy: None) # allow successive attempts return self._initialised.addCallback(backendInitialised) @defer.inlineCallbacks
--- a/src/stdui/ui_profile_manager.py Wed May 21 21:14:40 2014 +0200 +++ b/src/stdui/ui_profile_manager.py Wed May 21 23:15:01 2014 +0200 @@ -22,6 +22,7 @@ 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 @@ 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 @@ 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 {}