доделал всю валидацию
This commit is contained in:
parent
3949be7303
commit
33a082dfb3
|
|
@ -11,9 +11,15 @@ from account.serializers import MyUserSerializer, MyTokenObtainPairSerializer
|
|||
from account.models import MyUser
|
||||
from .schemas import UpdateUserSchema
|
||||
from conf.settings.base import MIN_LEN_PASSWORD
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import validate_email
|
||||
|
||||
PermissionClass = IsAuthenticated if not settings.DEBUG else AllowAny
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class MyTokenObtainPairView(TokenObtainPairView):
|
||||
permission_classes = [AllowAny]
|
||||
serializer_class = MyTokenObtainPairSerializer
|
||||
|
|
@ -60,23 +66,29 @@ class MyUserViewSet(ViewSet):
|
|||
def update_user(self, request):
|
||||
password = request.user.password
|
||||
|
||||
if request.data['password'] == request.data['email']:
|
||||
if check_password(request.data['old_password'], password):
|
||||
try:
|
||||
validate_email(request.data['password'])
|
||||
except ValidationError as e:
|
||||
pass
|
||||
else:
|
||||
return Response(
|
||||
{'detail': 'Почта не может являться паролем', 'error': {'email': 'Почта не может являться паролем'}},
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
if len(request.data['password']) < MIN_LEN_PASSWORD:
|
||||
return Response(
|
||||
{'detail': 'Минимальная длина - 8 символов', 'error': {'email': 'Минимальная длина - 8 символов'}},
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
if check_password(request.data['password'], password):
|
||||
return Response(
|
||||
{'detail': 'Пароли одинаковые', 'error': {'email': 'Пароли одинаковые'}},
|
||||
|
||||
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
if check_password(request.data['old_password'], password):
|
||||
|
||||
if 'email' in request.data:
|
||||
del request.data['email']
|
||||
if 'password' in request.data:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
from .local import *
|
||||
|
||||
|
||||
|
|
|
|||
Binary file not shown.
Loading…
Reference in New Issue