From bfa8b61449bd3c342f07814071eca09ac016ec0d Mon Sep 17 00:00:00 2001 From: Chneemann Date: Wed, 7 Aug 2024 04:36:19 +0200 Subject: [PATCH] error when the email does not exist & clean code error service --- backend/videoflix/auth/views.py | 8 +++---- .../forgot-password.component.html | 6 +++++ .../forgot-password.component.ts | 23 ++++--------------- .../components/auth/login/login.component.ts | 15 +----------- .../auth/register/register.component.html | 9 +++++--- .../auth/register/register.component.ts | 6 +---- frontend/src/app/services/error.service.ts | 14 +++++++++++ 7 files changed, 37 insertions(+), 44 deletions(-) diff --git a/backend/videoflix/auth/views.py b/backend/videoflix/auth/views.py index 78a448d..cc533d2 100644 --- a/backend/videoflix/auth/views.py +++ b/backend/videoflix/auth/views.py @@ -40,7 +40,7 @@ class RegisterView(APIView): email = request.data.get('email') password = request.data.get('password') if CustomUser.objects.filter(email=email).exists(): - return Response({'detail': 'A user with this email already exists.'}, status=status.HTTP_400_BAD_REQUEST) + return Response({'mail': 'A user with this email already exists.'}, status=status.HTTP_400_BAD_REQUEST) serialized = UserSerializer(data=request.data) if serialized.is_valid(): @@ -81,7 +81,7 @@ class VerifyEmailView(APIView): user = CustomUser.objects.filter(Q(email=email) & Q(verify_email_token=token)).first() if user: if user.is_active: - return Response({"error": "User has already been activated"}, status=status.HTTP_409_CONFLICT) + return Response({"error": "User has already been activated."}, status=status.HTTP_409_CONFLICT) user.is_active = True user.save() @@ -93,7 +93,7 @@ class ForgotPasswordView(APIView): def post(self, request): email = request.data.get('email') if not email: - return Response({"error": "Email required."}, status=status.HTTP_400_BAD_REQUEST) + return Response({"mail": "Email required."}, status=status.HTTP_400_BAD_REQUEST) try: user = CustomUser.objects.get(email=email) @@ -101,7 +101,7 @@ class ForgotPasswordView(APIView): user.save() self.send_email(user) except CustomUser.DoesNotExist: - pass + return Response({"mail": "This email does not exist."}, status=status.HTTP_400_BAD_REQUEST) return Response(status=status.HTTP_200_OK) def send_email(self, user): diff --git a/frontend/src/app/components/auth/forgot-password/forgot-password.component.html b/frontend/src/app/components/auth/forgot-password/forgot-password.component.html index 0d2d0e1..6bbe597 100644 --- a/frontend/src/app/components/auth/forgot-password/forgot-password.component.html +++ b/frontend/src/app/components/auth/forgot-password/forgot-password.component.html @@ -25,6 +25,7 @@ !isUserEmailValid(authData.mail.toLowerCase()) && authData.mail.length > 0) " + (click)="this.errorService.clearError()" required />
@@ -34,6 +35,11 @@ !isUserEmailValid(authData.mail.toLowerCase())) {

This is not a valid email format

}} +
+
+

{{ errors["mail"] }}

+
+
0 && !isUserEmailValid(authData.mail.toLowerCase())) {

This is not a valid email format

- }} @if ((errorService.error$ | async)) { -

{{ errorService.error$ | async }}

- } + }} +
+
+

{{ errors["mail"] }}

+
+