mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-12-03 22:33:43 +03:00
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
This commit is contained in:
parent
4065952f70
commit
b4ed9b5f44
|
@ -58,12 +58,12 @@ class PasswordResetSerializer(serializers.Serializer):
|
||||||
|
|
||||||
password_reset_form_class = PasswordResetForm
|
password_reset_form_class = PasswordResetForm
|
||||||
|
|
||||||
def validate_email(self, attrs, source):
|
def validate_email(self, value):
|
||||||
# Create PasswordResetForm with the serializer
|
# 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():
|
if not self.reset_form.is_valid():
|
||||||
raise serializers.ValidationError('Error')
|
raise serializers.ValidationError('Error')
|
||||||
return attrs
|
return value
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
request = self.context.get('request')
|
request = self.context.get('request')
|
||||||
|
@ -103,6 +103,7 @@ class PasswordResetConfirmSerializer(serializers.Serializer):
|
||||||
self.user = UserModel._default_manager.get(pk=uid)
|
self.user = UserModel._default_manager.get(pk=uid)
|
||||||
except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
|
except (TypeError, ValueError, OverflowError, UserModel.DoesNotExist):
|
||||||
self._errors['uid'] = ['Invalid value']
|
self._errors['uid'] = ['Invalid value']
|
||||||
|
raise serializers.ValidationError('Invalid UID')
|
||||||
|
|
||||||
self.custom_validation(attrs)
|
self.custom_validation(attrs)
|
||||||
|
|
||||||
|
@ -115,6 +116,8 @@ class PasswordResetConfirmSerializer(serializers.Serializer):
|
||||||
if not default_token_generator.check_token(self.user, attrs['token']):
|
if not default_token_generator.check_token(self.user, attrs['token']):
|
||||||
self._errors['token'] = ['Invalid value']
|
self._errors['token'] = ['Invalid value']
|
||||||
|
|
||||||
|
return attrs
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
self.set_password_form.save()
|
self.set_password_form.save()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user