From b002ee3d4b4f516f6c451300bed837d7faf92e39 Mon Sep 17 00:00:00 2001 From: samben Date: Mon, 18 Sep 2017 01:58:51 +0800 Subject: [PATCH] Changed PasswordChangeSerializer to not include old_password when user has no usable password --- rest_auth/serializers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rest_auth/serializers.py b/rest_auth/serializers.py index 723cfca..0fa9687 100644 --- a/rest_auth/serializers.py +++ b/rest_auth/serializers.py @@ -239,12 +239,12 @@ class PasswordChangeSerializer(serializers.Serializer): ) super(PasswordChangeSerializer, self).__init__(*args, **kwargs) - if not self.old_password_field_enabled: - self.fields.pop('old_password') - self.request = self.context.get('request') self.user = getattr(self.request, 'user', None) + if not self.old_password_field_enabled or not self.user.has_usable_password(): + self.fields.pop('old_password') + def validate_old_password(self, value): invalid_password_conditions = ( self.old_password_field_enabled,