core: misc improvments:
- added some constants for message types and presence
- removed profile authentification specific methods in favor of a more generic "validated" key
This commit is contained in:
parent
6e144c6458
commit
05e5e1448b
1 changed files with 35 additions and 14 deletions
|
|
@ -48,20 +48,20 @@ class ProfileManager(object):
|
|||
def gotProfileCipher(profile_cipher):
|
||||
if self.host.memory.auth_sessions.profileGetUnique(profile):
|
||||
# case 1: profile already authenticated
|
||||
return {'authenticated_profile': profile, 'caller': data['caller']}
|
||||
return {'validated': C.str(True)}
|
||||
self.profile_ciphers[profile] = profile_cipher
|
||||
if 'profile_password' in data:
|
||||
# case 2: password is provided by the caller
|
||||
return self._verifyPassword(data, profile)
|
||||
|
||||
def check_empty_password(empty_password_result):
|
||||
if 'authenticated_profile' in empty_password_result:
|
||||
def check_empty_password(verify_password_result):
|
||||
validated = C.bool(verify_password_result['validated'])
|
||||
if validated:
|
||||
# case 3: there's no password for this profile
|
||||
return empty_password_result
|
||||
return verify_password_result
|
||||
|
||||
# case 4: prompt the user for a password
|
||||
def xmlui_cb(data_, profile):
|
||||
data_['caller'] = data['caller']
|
||||
return self._verifyPassword(data_, profile)
|
||||
|
||||
callback_id = self.host.registerCallback(xmlui_cb, with_data=True, one_shot=True)
|
||||
|
|
@ -69,11 +69,10 @@ class ProfileManager(object):
|
|||
form_ui.addPassword('profile_password', value='')
|
||||
return {'xmlui': form_ui.toXml()}
|
||||
|
||||
check_empty_data = {'profile_password': '', 'caller': data['caller']}
|
||||
check_empty_data = {'profile_password': ''}
|
||||
d = self._verifyPassword(check_empty_data, profile)
|
||||
return d.addCallback(check_empty_password)
|
||||
|
||||
assert(data['caller'])
|
||||
d = self.host.memory.asyncGetStringParamA(C.PROFILE_PASS_PATH[1], C.PROFILE_PASS_PATH[0], profile_key=profile)
|
||||
d.addCallback(gotProfileCipher)
|
||||
d.addErrback(self.getParamError)
|
||||
|
|
@ -82,7 +81,7 @@ class ProfileManager(object):
|
|||
def getParamError(self, failure):
|
||||
_dialog = xml_tools.XMLUI('popup', title=D_('Error'))
|
||||
_dialog.addText(D_("Can't get profile parameter."))
|
||||
return {'xmlui': _dialog.toXml()}
|
||||
return {'xmlui': _dialog.toXml(), 'validated': C.str(False)}
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def _verifyPassword(self, data, profile):
|
||||
|
|
@ -93,7 +92,6 @@ class ProfileManager(object):
|
|||
@return: deferred dict
|
||||
"""
|
||||
assert(profile in self.profile_ciphers)
|
||||
assert(data['caller'])
|
||||
|
||||
try:
|
||||
profile_password = data[xml_tools.formEscape('profile_password')]
|
||||
|
|
@ -103,10 +101,10 @@ class ProfileManager(object):
|
|||
if not verified:
|
||||
_dialog = xml_tools.XMLUI('popup', title=D_('Connection error'))
|
||||
_dialog.addText(D_("The provided profile password doesn't match."))
|
||||
defer.returnValue({'xmlui': _dialog.toXml()})
|
||||
defer.returnValue({'xmlui': _dialog.toXml(), 'validated': C.str(False)})
|
||||
|
||||
yield self.host.memory.newAuthSession(profile_password, profile)
|
||||
defer.returnValue({'authenticated_profile': profile, 'caller': data['caller']})
|
||||
defer.returnValue({'validated': C.str(True)})
|
||||
|
||||
def _changeXMPPPassword(self, data, profile):
|
||||
session_data = self._sessions.profileGetUnique(profile)
|
||||
|
|
|
|||
Loading…
Reference in a new issue