core, stdui (profile manager), quick_app: ask for another XMPP password when profile authentication succeed but XMPP connection fails
This commit is contained in:
parent
ea05b4e0d6
commit
8be7416569
4 changed files with 34 additions and 4 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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 ##
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue