Mercurial > libervia-backend
comparison src/memory/params.py @ 1686:1ed269c5f295
profile (params): fixed password setting: if profile was not connected, set was silently ignored
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Nov 2015 15:47:01 +0100 |
parents | 5c1d6efd6936 |
children | 59a94105b138 |
comparison
equal
deleted
inserted
replaced
1685:43a127b6a4f2 | 1686:1ed269c5f295 |
---|---|
825 min_, max_ = [int(limit) for limit in constraint.split(";")] | 825 min_, max_ = [int(limit) for limit in constraint.split(";")] |
826 except ValueError: | 826 except ValueError: |
827 raise exceptions.InternalError("Invalid integer parameter constraint: %s" % constraint) | 827 raise exceptions.InternalError("Invalid integer parameter constraint: %s" % constraint) |
828 value = str(min(max(int(value), min_), max_)) | 828 value = str(min(max(int(value), min_), max_)) |
829 | 829 |
830 | |
830 log.info(_("Setting parameter (%(category)s, %(name)s) = %(value)s") % | 831 log.info(_("Setting parameter (%(category)s, %(name)s) = %(value)s") % |
831 {'category': category, 'name': name, 'value': value if type_ != 'password' else '********'}) | 832 {'category': category, 'name': name, 'value': value if type_ != 'password' else '********'}) |
832 | 833 |
833 if node[0] == C.GENERAL: | 834 if node[0] == C.GENERAL: |
834 self.params_gen[(category, name)] = value | 835 self.params_gen[(category, name)] = value |
840 return defer.succeed(None) | 841 return defer.succeed(None) |
841 | 842 |
842 assert node[0] == C.INDIVIDUAL | 843 assert node[0] == C.INDIVIDUAL |
843 assert profile_key != C.PROF_KEY_NONE | 844 assert profile_key != C.PROF_KEY_NONE |
844 | 845 |
845 d_list = [] | |
846 if type_ == "button": | 846 if type_ == "button": |
847 log.debug(u"Clicked param button %s" % node.toxml()) | 847 log.debug(u"Clicked param button %s" % node.toxml()) |
848 return defer.succeed(None) | 848 return defer.succeed(None) |
849 d = defer.succeed(value) | 849 elif type_ == "password": |
850 if type_ == "password": | |
851 try: | 850 try: |
852 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] | 851 personal_key = self.host.memory.auth_sessions.profileGetUnique(profile)[C.MEMORY_CRYPTO_KEY] |
853 except TypeError: | 852 except TypeError: |
854 raise exceptions.InternalError(_('Trying to encrypt a password while the personal key is undefined!')) | 853 raise exceptions.InternalError(_('Trying to encrypt a password while the personal key is undefined!')) |
855 if (category, name) == C.PROFILE_PASS_PATH: | 854 if (category, name) == C.PROFILE_PASS_PATH: |
856 # using 'value' as the encryption key to encrypt another encryption key... could be confusing! | 855 # using 'value' as the encryption key to encrypt another encryption key... could be confusing! |
857 d_list.append(self.host.memory.encryptPersonalData(data_key=C.MEMORY_CRYPTO_KEY, | 856 d = self.host.memory.encryptPersonalData(data_key=C.MEMORY_CRYPTO_KEY, |
858 data_value=personal_key, | 857 data_value=personal_key, |
859 crypto_key=value, | 858 crypto_key=value, |
860 profile=profile)) | 859 profile=profile) |
861 d = PasswordHasher.hash(value) # profile password is hashed (empty value stays empty) | 860 d.addCallback(lambda dummy: PasswordHasher.hash(value)) # profile password is hashed (empty value stays empty) |
862 elif value: # other non empty passwords are encrypted with the personal key | 861 elif value: # other non empty passwords are encrypted with the personal key |
863 d = BlockCipher.encrypt(personal_key, value) | 862 d = BlockCipher.encrypt(personal_key, value) |
863 else: | |
864 d = defer.succeed(value) | |
864 | 865 |
865 def gotFinalValue(value): | 866 def gotFinalValue(value): |
866 if self.host.isConnected(profile): # key can not exists if profile is not connected | 867 if self.host.memory.isSessionStarted(profile): |
867 self.params[profile][(category, name)] = value | 868 self.params[profile][(category, name)] = value |
868 self.host.bridge.paramUpdate(name, value, category, profile) | 869 self.host.bridge.paramUpdate(name, value, category, profile) |
869 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) | 870 self.host.trigger.point("paramUpdateTrigger", name, value, category, node[0], profile) |
870 return self.storage.setIndParam(category, name, value, profile) | 871 return self.storage.setIndParam(category, name, value, profile) |
872 else: | |
873 raise exceptions.ProfileNotConnected | |
871 | 874 |
872 d.addCallback(gotFinalValue) | 875 d.addCallback(gotFinalValue) |
873 d_list.append(d) | 876 return d |
874 return defer.DeferredList(d_list).addCallback(lambda dummy: None) | |
875 | 877 |
876 def _getNodesOfTypes(self, attr_type, node_type="@ALL@"): | 878 def _getNodesOfTypes(self, attr_type, node_type="@ALL@"): |
877 """Return all the nodes matching the given types. | 879 """Return all the nodes matching the given types. |
878 | 880 |
879 TODO: using during the dev but not anymore... remove if not needed | 881 TODO: using during the dev but not anymore... remove if not needed |