Created
September 28, 2015 11:33
-
-
Save eugena/128aa896fcea81af7743 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PasswordSerializer(serializers.ModelSerializer): | |
""" | |
Changes user password | |
""" | |
old_password = serializers.CharField(required=True) | |
new_password = serializers.CharField(required=True) | |
_required_fields = ['old_password', 'new_password'] | |
def validate_old_password(self, value): | |
""" | |
Validates that the old_password field is correct. | |
""" | |
if not self.instance.check_password(value): | |
raise serializers.ValidationError( | |
"Your old password was entered incorrectly. Please enter it again.") | |
return value | |
def validate_new_password(self, value): | |
""" | |
Validates that the old_password field is correct. | |
""" | |
self.instance.set_password(value) | |
return value | |
class Meta(): | |
model = Client | |
fields = ['old_password', 'new_password', ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment