diff --git a/src/memory/memory.py b/src/memory/memory.py index 85dc4db5..625346ca 100644 --- a/src/memory/memory.py +++ b/src/memory/memory.py @@ -459,10 +459,11 @@ class Memory(object): 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 @@ class Memory(object): 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 @@ class Memory(object): 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):