добавил еще исключения в обновление пароля
This commit is contained in:
parent
81fbcba642
commit
288622318c
|
|
@ -10,7 +10,7 @@ from conf import settings
|
||||||
from account.serializers import MyUserSerializer, MyTokenObtainPairSerializer
|
from account.serializers import MyUserSerializer, MyTokenObtainPairSerializer
|
||||||
from account.models import MyUser
|
from account.models import MyUser
|
||||||
from .schemas import UpdateUserSchema
|
from .schemas import UpdateUserSchema
|
||||||
|
from conf.settings.base import MIN_LEN_PASSWORD
|
||||||
|
|
||||||
PermissionClass = IsAuthenticated if not settings.DEBUG else AllowAny
|
PermissionClass = IsAuthenticated if not settings.DEBUG else AllowAny
|
||||||
|
|
||||||
|
|
@ -60,6 +60,21 @@ class MyUserViewSet(ViewSet):
|
||||||
def update_user(self, request):
|
def update_user(self, request):
|
||||||
password = request.user.password
|
password = request.user.password
|
||||||
|
|
||||||
|
if request.data['password'] == request.data['email']:
|
||||||
|
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 check_password(request.data['old_password'], password):
|
||||||
if 'email' in request.data:
|
if 'email' in request.data:
|
||||||
del request.data['email']
|
del request.data['email']
|
||||||
|
|
@ -70,7 +85,10 @@ class MyUserViewSet(ViewSet):
|
||||||
serializer.save()
|
serializer.save()
|
||||||
return Response(serializer.data)
|
return Response(serializer.data)
|
||||||
else:
|
else:
|
||||||
return Response({'error':'Неверный старый пароль'}, status=status.HTTP_400_BAD_REQUEST)
|
return Response(
|
||||||
|
{'detail': 'Неверный старый пароль', 'error': {'email': 'Неверный старый пароль'}},
|
||||||
|
status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
@action(detail=False, methods=['post'])
|
@action(detail=False, methods=['post'])
|
||||||
def password_reset_user(self, request):
|
def password_reset_user(self, request):
|
||||||
|
|
|
||||||
Binary file not shown.
|
|
@ -160,3 +160,4 @@ CORS_ALLOW_CREDENTIALS = True
|
||||||
CORS_ALLOWED_ORIGINS = [
|
CORS_ALLOWED_ORIGINS = [
|
||||||
'http://localhost:5173',
|
'http://localhost:5173',
|
||||||
]
|
]
|
||||||
|
MIN_LEN_PASSWORD = 8
|
||||||
Loading…
Reference in New Issue