From b4ed9b5f44ca4a555e5bd16bafaa94b0a7ea469e Mon Sep 17 00:00:00 2001 From: ante Date: Sat, 3 Jan 2015 16:49:27 +0100 Subject: [PATCH] Making PasswordResetSerializer & PasswordResetConfirmSerializer compatible with DRF3 - validate_email - works with field value and not with dictionary of all values - raise exception or return serialized value --- rest_auth/serializers.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rest_auth/serializers.py b/rest_auth/serializers.py index 58c1809..d498565 100644 --- a/rest_auth/serializers.py +++ b/rest_auth/serializers.py @@ -58,12 +58,12 @@ class PasswordResetSerializer(serializers.Serializer): password_reset_form_class = PasswordResetForm - def validate_email(self, attrs, source): + def validate_email(self, value): # Create PasswordResetForm with the serializer - self.reset_form = self.password_reset_form_class(data=attrs) + self.reset_form = self.password_reset_form_class(data={'email': value}) if not self.reset_form.is_valid(): raise serializers.ValidationError('Error') - return attrs + return value def save(self): request = self.context.get('request') @@ -103,6 +103,7 @@ class PasswordResetConfirmSerializer(serializers.Serializer): self.user = UserModel._default_manager.get(pk=uid) except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist): self._errors['uid'] = ['Invalid value'] + raise serializers.ValidationError('Invalid UID') self.custom_validation(attrs) @@ -115,6 +116,8 @@ class PasswordResetConfirmSerializer(serializers.Serializer): if not default_token_generator.check_token(self.user, attrs['token']): self._errors['token'] = ['Invalid value'] + return attrs + def save(self): self.set_password_form.save()