From 01f98753cc84f2552cc24b32c1a627ad3d4b9da1 Mon Sep 17 00:00:00 2001 From: Chneemann Date: Wed, 7 Aug 2024 04:48:22 +0200 Subject: [PATCH] check email duplicates on the server before registration --- backend/videoflix/auth/views.py | 8 +++++- .../app/components/auth/auth.component.html | 5 ++++ .../src/app/components/auth/auth.component.ts | 28 +++++++++++++++---- frontend/src/app/services/auth.service.ts | 4 +++ 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/backend/videoflix/auth/views.py b/backend/videoflix/auth/views.py index cc533d2..c112b1b 100644 --- a/backend/videoflix/auth/views.py +++ b/backend/videoflix/auth/views.py @@ -144,4 +144,10 @@ class AuthView(ObtainAuthToken): def get(self, request): if request.user.is_authenticated: return Response(request.user.id, status=status.HTTP_200_OK) - return Response({"error": "User is not logged in"}, status=status.HTTP_401_UNAUTHORIZED) \ No newline at end of file + return Response({"error": "User is not logged in"}, status=status.HTTP_401_UNAUTHORIZED) + + def post(self, request): + email = request.data.get('email') + if CustomUser.objects.filter(email=email).exists(): + return Response({'mail': 'A user with this email already exists.'}, status=status.HTTP_400_BAD_REQUEST) + return Response(status=status.HTTP_200_OK) \ No newline at end of file diff --git a/frontend/src/app/components/auth/auth.component.html b/frontend/src/app/components/auth/auth.component.html index 82c7710..5a77ea9 100644 --- a/frontend/src/app/components/auth/auth.component.html +++ b/frontend/src/app/components/auth/auth.component.html @@ -33,6 +33,11 @@ !isUserEmailValid(authData.mail.toLowerCase())) {

This is not a valid email format

}} +
+
+

{{ errors["mail"] }}

+
+