changeset 1212:628e320eab1f

memory: Sessions.newSession can be called with a forced session ID
author souliane <souliane@mailoo.org>
date Sun, 21 Sep 2014 13:10:55 +0200 (2014-09-21)
parents 9355f48f979e
children b5928601d7aa
files src/memory/memory.py src/plugins/plugin_misc_account.py src/plugins/plugin_misc_register_account.py src/stdui/ui_profile_manager.py
diffstat 4 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/memory/memory.py	Sun Sep 21 13:06:53 2014 +0200
+++ b/src/memory/memory.py	Sun Sep 21 13:10:55 2014 +0200
@@ -47,14 +47,16 @@
         self._sessions = dict()
         self.timeout = timeout or Sessions.DEFAULT_TIMEOUT
 
-    def newSession(self, session_data=None, profile=None):
+    def newSession(self, session_data=None, session_id=None, profile=None):
         """ Create a new session
         @param session_data: mutable data to use, default to a dict
+        @param session_id (str): force the session_id to the given string
         @param profile: if set, the session is owned by the profile,
                         and profileGet must be used instead of __getitem__
         @return: session_id, session_data
         """
-        session_id = str(uuid4())
+        if session_id is None:
+            session_id = str(uuid4())
         timer = reactor.callLater(self.timeout, self._purgeSession, session_id)
         if session_data is None:
             session_data = {}
@@ -268,7 +270,7 @@
         """
         def gotPersonalKey(personal_key):
             """Create the session for this profile and store the personal key"""
-            self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile)
+            self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=profile)
             log.debug('auth session created for profile %s' % profile)
 
         d = PersistentDict(C.MEMORY_CRYPTO_NAMESPACE, profile).load()
@@ -319,7 +321,7 @@
         @return: Deferred
         """
         personal_key = BlockCipher.getRandomKey(base64=True)  # generated once for all and saved in a PersistentDict
-        self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, name)  # will be encrypted by setParam
+        self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=name)  # will be encrypted by setParam
         d = self.params.asyncCreateProfile(name)
         d.addCallback(lambda dummy: self.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name))
         return d
--- a/src/plugins/plugin_misc_account.py	Sun Sep 21 13:06:53 2014 +0200
+++ b/src/plugins/plugin_misc_account.py	Sun Sep 21 13:10:55 2014 +0200
@@ -352,7 +352,7 @@
         @param password (str): the new password
         @param profile (str): %(doc_profile)s
         """
-        session_id, dummy = self._sessions.newSession({'new_password': password}, profile)
+        session_id, dummy = self._sessions.newSession({'new_password': password}, profile=profile)
         form_ui = xml_tools.XMLUI("form", title=D_("Change your password?"), submit_id=self.__change_password_id, session_id=session_id)
         form_ui.addText(D_("Note for advanced users: this will actually change both your SàT profile password AND your XMPP account password."))
         form_ui.addText(D_("Continue with changing the password?"))
--- a/src/plugins/plugin_misc_register_account.py	Sun Sep 21 13:06:53 2014 +0200
+++ b/src/plugins/plugin_misc_register_account.py	Sun Sep 21 13:10:55 2014 +0200
@@ -70,7 +70,7 @@
 
         session_data['user'], host, resource = jid.parse(session_data['JabberID'])
         session_data['server'] = session_data[C.FORCE_SERVER_PARAM] or host
-        session_id, dummy = self._sessions.newSession(session_data, profile)
+        session_id, dummy = self._sessions.newSession(session_data, profile=profile)
         form_ui = xml_tools.XMLUI("form", title=D_("Register new account"), submit_id=self.__register_account_id, session_id=session_id)
         form_ui.addText(D_("Do you want to register a new XMPP account [%(user)s] on server %(server)s ?") % {'user': session_data['user'], 'server': session_data['server']})
         return  {'xmlui': form_ui.toXml()}
--- a/src/stdui/ui_profile_manager.py	Sun Sep 21 13:06:53 2014 +0200
+++ b/src/stdui/ui_profile_manager.py	Sun Sep 21 13:10:55 2014 +0200
@@ -114,7 +114,7 @@
             server = self.host.memory.getParamA(C.FORCE_SERVER_PARAM, "Connection", profile_key=profile)
             if not server:
                 server = jid.parse(self.host.memory.getParamA('JabberID', "Connection", profile_key=profile))[1]
-            session_id, session_data = self._sessions.newSession({'count': 0, 'server': server}, profile)
+            session_id, session_data = self._sessions.newSession({'count': 0, 'server': server}, profile=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'))