mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-28 00:49:49 +03:00
added __call__ and __repr__ methods to PasswordValidator class
This commit is contained in:
parent
a2101796ef
commit
87198ed998
|
@ -8,6 +8,7 @@ object creation, and makes it possible to switch between using the implicit
|
||||||
"""
|
"""
|
||||||
from django.db import DataError
|
from django.db import DataError
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.contrib.auth import password_validation
|
||||||
|
|
||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
from rest_framework.utils.representation import smart_repr
|
from rest_framework.utils.representation import smart_repr
|
||||||
|
@ -46,7 +47,21 @@ class PasswordValidator:
|
||||||
self.validators = validators
|
self.validators = validators
|
||||||
self.user = user
|
self.user = user
|
||||||
|
|
||||||
|
def __call__(self, value, serializer_field):
|
||||||
|
try:
|
||||||
|
password_validation.validate_password(
|
||||||
|
password=value,
|
||||||
|
user=self.user,
|
||||||
|
password_validators=self.validators
|
||||||
|
)
|
||||||
|
except ValidationError as e:
|
||||||
|
raise ValidationError(e)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return '<%s(validators=%s)>' % (
|
||||||
|
self.__class__.__name__,
|
||||||
|
self.validators if self.validators else 'AUTH_PASSWORD_VALIDATORS'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UniqueValidator:
|
class UniqueValidator:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user