# HG changeset patch # User Goffi # Date 1448639534 -3600 # Node ID 5a93f13c1e76618592f332a4ff3d79651bb1d0f8 # Parent 3c608d660f0b6929a41cd185e31f983d1b5bf8f8 core (memory): asyncCreateProfile fix: a fake session is created to set general password param diff -r 3c608d660f0b -r 5a93f13c1e76 src/memory/memory.py --- a/src/memory/memory.py Fri Nov 27 16:50:29 2015 +0100 +++ b/src/memory/memory.py Fri Nov 27 16:52:14 2015 +0100 @@ -459,10 +459,11 @@ self.memory_data['Profile_default'] = profile - def asyncCreateProfile(self, name, password=''): + def asyncCreateProfile(self, name, password): """Create a new profile - @param name: profile name - @param password: profile password + @param name (unicode): profile name + @param password (unicode): profile password + Can be empty to disable password @return: Deferred """ if not name: @@ -470,6 +471,9 @@ if name[0] == '@': raise ValueError("A profile name can't start with a '@'") + if name in self._entities_cache: + raise exceptions.ConflictError(u"A session for this profile exists") + d = self.params.asyncCreateProfile(name) def initPersonalKey(dummy): @@ -477,8 +481,20 @@ 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}, profile=name) # will be encrypted by setParam + def startFakeSession(dummy): + # avoid ProfileNotConnected exception in setParam + self._entities_cache[name] = None + self.params.loadIndParams(name) + + def stopFakeSession(dummy): + del self._entities_cache[name] + self.params.purgeProfile(name) + d.addCallback(initPersonalKey) + d.addCallback(startFakeSession) d.addCallback(lambda dummy: self.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name)) + d.addCallback(stopFakeSession) + d.addCallback(lambda dummy: self.auth_sessions.profileDelUnique(name)) return d def asyncDeleteProfile(self, name, force=False):