mirror of
https://github.com/Tivix/django-rest-auth.git
synced 2024-12-02 05:43:44 +03:00
Making PasswordChangeSerializer compatible with DRF3
- validate_old_password - works with field value and not with dictionary of all values - validate - should not return None but raise ValidationError
This commit is contained in:
parent
7984cb5f00
commit
59f482fd65
|
@ -138,19 +138,20 @@ class PasswordChangeSerializer(serializers.Serializer):
|
||||||
self.request = self.context.get('request')
|
self.request = self.context.get('request')
|
||||||
self.user = getattr(self.request, 'user', None)
|
self.user = getattr(self.request, 'user', None)
|
||||||
|
|
||||||
def validate_old_password(self, attrs, source):
|
def validate_old_password(self, value):
|
||||||
if self.old_password_field_enabled and self.user and \
|
if self.old_password_field_enabled and self.user and \
|
||||||
not self.user.check_password(attrs.get(source, '')):
|
not self.user.check_password(value):
|
||||||
raise serializers.ValidationError('Invalid password')
|
raise serializers.ValidationError('Invalid password')
|
||||||
return attrs
|
return value
|
||||||
|
|
||||||
def validate(self, attrs):
|
def validate(self, attrs):
|
||||||
self.set_password_form = self.set_password_form_class(user=self.user,
|
self.set_password_form = self.set_password_form_class(user=self.user,
|
||||||
data=attrs)
|
data=attrs)
|
||||||
|
|
||||||
if not self.set_password_form.is_valid():
|
if not self.set_password_form.is_valid():
|
||||||
self._errors = self.set_password_form.errors
|
#self._errors = self.set_password_form.errors
|
||||||
return None
|
#return None
|
||||||
|
raise serializers.ValidationError(self.set_password_form.errors)
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user