core (memory): asyncCreateProfile fix: a fake session is created to set general password param
This commit is contained in:
parent
1bf3950ce6
commit
fad4200be3
1 changed files with 19 additions and 3 deletions
|
|
@ -459,10 +459,11 @@ class Memory(object):
|
||||||
|
|
||||||
self.memory_data['Profile_default'] = profile
|
self.memory_data['Profile_default'] = profile
|
||||||
|
|
||||||
def asyncCreateProfile(self, name, password=''):
|
def asyncCreateProfile(self, name, password):
|
||||||
"""Create a new profile
|
"""Create a new profile
|
||||||
@param name: profile name
|
@param name (unicode): profile name
|
||||||
@param password: profile password
|
@param password (unicode): profile password
|
||||||
|
Can be empty to disable password
|
||||||
@return: Deferred
|
@return: Deferred
|
||||||
"""
|
"""
|
||||||
if not name:
|
if not name:
|
||||||
|
|
@ -470,6 +471,9 @@ class Memory(object):
|
||||||
if name[0] == '@':
|
if name[0] == '@':
|
||||||
raise ValueError("A profile name can't start with a '@'")
|
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)
|
d = self.params.asyncCreateProfile(name)
|
||||||
|
|
||||||
def initPersonalKey(dummy):
|
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
|
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
|
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(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(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
|
return d
|
||||||
|
|
||||||
def asyncDeleteProfile(self, name, force=False):
|
def asyncDeleteProfile(self, name, force=False):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue