diff src/stdui/ui_profile_manager.py @ 1263:cfd636203e8f frontends_multi_profiles

core: misc improvments: - added some constants for message types and presence - removed profile authentification specific methods in favor of a more generic "validated" key
author Goffi <goffi@goffi.org>
date Wed, 10 Dec 2014 18:36:11 +0100
parents 628e320eab1f
children a8d7500090f6
line wrap: on
line diff
--- a/src/stdui/ui_profile_manager.py	Wed Dec 10 18:32:33 2014 +0100
+++ b/src/stdui/ui_profile_manager.py	Wed Dec 10 18:36:11 2014 +0100
@@ -48,20 +48,20 @@
         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 @@
                 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 @@
     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 @@
         @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 @@
         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)