Mercurial > libervia-backend
comparison src/memory/memory.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 | c585df65828a |
children | faa1129559b8 |
comparison
equal
deleted
inserted
replaced
1262:f8a8434dbac7 | 1263:cfd636203e8f |
---|---|
330 def getProfilesList(self): | 330 def getProfilesList(self): |
331 return self.storage.getProfilesList() | 331 return self.storage.getProfilesList() |
332 | 332 |
333 def getProfileName(self, profile_key, return_profile_keys=False): | 333 def getProfileName(self, profile_key, return_profile_keys=False): |
334 """Return name of profile from keyword | 334 """Return name of profile from keyword |
335 | |
335 @param profile_key: can be the profile name or a keywork (like @DEFAULT@) | 336 @param profile_key: can be the profile name or a keywork (like @DEFAULT@) |
336 @return: profile name or None if it doesn't exist""" | 337 @param return_profile_keys: if True, return unmanaged profile keys (like "@ALL@"). This keys must be managed by the caller |
338 @return: requested profile name or emptry string if it doesn't exist | |
339 """ | |
337 return self.params.getProfileName(profile_key, return_profile_keys) | 340 return self.params.getProfileName(profile_key, return_profile_keys) |
338 | 341 |
339 def asyncCreateProfile(self, name, password=''): | 342 def asyncCreateProfile(self, name, password=''): |
340 """Create a new profile | 343 """Create a new profile |
341 @param name: profile name | 344 @param name: profile name |
342 @param password: profile password | 345 @param password: profile password |
343 @return: Deferred | 346 @return: Deferred |
344 """ | 347 """ |
348 if not name: | |
349 raise ValueError("Empty profile name") | |
350 if name[0] == '@': | |
351 raise ValueError("A profile name can't start with a '@'") | |
345 personal_key = BlockCipher.getRandomKey(base64=True) # generated once for all and saved in a PersistentDict | 352 personal_key = BlockCipher.getRandomKey(base64=True) # generated once for all and saved in a PersistentDict |
346 self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=name) # will be encrypted by setParam | 353 self.auth_sessions.newSession({C.MEMORY_CRYPTO_KEY: personal_key}, profile=name) # will be encrypted by setParam |
347 d = self.params.asyncCreateProfile(name) | 354 d = self.params.asyncCreateProfile(name) |
348 d.addCallback(lambda dummy: self.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name)) | 355 d.addCallback(lambda dummy: self.setParam(C.PROFILE_PASS_PATH[1], password, C.PROFILE_PASS_PATH[0], profile_key=name)) |
349 return d | 356 return d |
577 | 584 |
578 for entity in to_delete: | 585 for entity in to_delete: |
579 try: | 586 try: |
580 del self._entities_cache[profile][entity] | 587 del self._entities_cache[profile][entity] |
581 except KeyError: | 588 except KeyError: |
582 log.debug("Can't delete entity [%s]: not in cache" % entity.full()) | 589 log.warning(_("Can't delete entity [{}]: not in cache").format(entity.full())) |
583 | 590 |
584 def encryptValue(self, value, profile): | 591 def encryptValue(self, value, profile): |
585 """Encrypt a value for the given profile. The personal key must be loaded | 592 """Encrypt a value for the given profile. The personal key must be loaded |
586 already in the profile session, that should be the case if the profile is | 593 already in the profile session, that should be the case if the profile is |
587 already authenticated. | 594 already authenticated. |