comparison src/memory/params.py @ 1042:59de0c7a28ec

memory (params): fixes bugs in setParam: - symbol 'd' was accessed without having been initialized when setting the empty value to a password which is not the profile password - the method was actually returning without waiting for the parameter to be set
author souliane <souliane@mailoo.org>
date Wed, 21 May 2014 21:14:40 +0200
parents 902c764a0d2b
children 85c110c0be86
comparison
equal deleted inserted replaced
1041:9095263011b6 1042:59de0c7a28ec
754 754
755 d_list = [] 755 d_list = []
756 if type_ == "button": 756 if type_ == "button":
757 log.debug("Clicked param button %s" % node.toxml()) 757 log.debug("Clicked param button %s" % node.toxml())
758 return defer.succeed(None) 758 return defer.succeed(None)
759 elif type_ == "password": 759 d = defer.succeed(value)
760 if type_ == "password":
760 try: 761 try:
761 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] 762 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY]
762 except TypeError: 763 except TypeError:
763 raise exceptions.InternalError(_('Trying to encrypt a password while the personal key is undefined!')) 764 raise exceptions.InternalError(_('Trying to encrypt a password while the personal key is undefined!'))
764 if (category, name) == C.PROFILE_PASS_PATH: 765 if (category, name) == C.PROFILE_PASS_PATH:
768 crypto_key=value, 769 crypto_key=value,
769 profile=profile)) 770 profile=profile))
770 d = PasswordHasher.hash(value) # profile password is hashed (empty value stays empty) 771 d = PasswordHasher.hash(value) # profile password is hashed (empty value stays empty)
771 elif value: # other non empty passwords are encrypted with the personal key 772 elif value: # other non empty passwords are encrypted with the personal key
772 d = BlockCipher.encrypt(personal_key, value) 773 d = BlockCipher.encrypt(personal_key, value)
773 else:
774 d = defer.succeed(value)
775 774
776 def gotFinalValue(value): 775 def gotFinalValue(value):
777 if self.host.isConnected(profile): # key can not exists if profile is not connected 776 if self.host.isConnected(profile): # key can not exists if profile is not connected
778 self.params[profile][(category, name)] = value 777 self.params[profile][(category, name)] = value
779 self.host.bridge.paramUpdate(name, value, category, profile) 778 self.host.bridge.paramUpdate(name, value, category, profile)
780 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) 779 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile)
781 d_list.append(self.storage.setIndParam(category, name, value, profile)) 780 return self.storage.setIndParam(category, name, value, profile)
782 781
783 d.addCallback(gotFinalValue) 782 d.addCallback(gotFinalValue)
783 d_list.append(d)
784 return defer.DeferredList(d_list).addCallback(lambda dummy: None) 784 return defer.DeferredList(d_list).addCallback(lambda dummy: None)
785 785
786 def _getNodesOfTypes(self, attr_type, node_type="@ALL@"): 786 def _getNodesOfTypes(self, attr_type, node_type="@ALL@"):
787 """Return all the nodes matching the given types. 787 """Return all the nodes matching the given types.
788 788