From ac5675e9238a6ab38a4d2c7b870da92f1f38900b Mon Sep 17 00:00:00 2001 From: i701 Date: Fri, 18 Apr 2025 11:36:48 +0500 Subject: [PATCH] Refactor VerifyOTPView to check for existing TemporaryUser and return appropriate error messages --- api/views.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/views.py b/api/views.py index b4982a7..3c05b63 100644 --- a/api/views.py +++ b/api/views.py @@ -18,6 +18,7 @@ from api.serializers import ( OTPVerificationSerializer, TemporaryUserSerializer, ) +from django.shortcuts import get_object_or_404 # knox imports from knox.views import LoginView as KnoxLoginView @@ -207,11 +208,11 @@ class VerifyOTPView(generics.GenericAPIView): serializer.is_valid(raise_exception=True) data = request.data mobile = data.get("mobile") + t_user = get_object_or_404(TemporaryUser, t_mobile=mobile) + if not t_user: + return Response({"message": "User not found."}, status=404) - if ( - User.objects.filter(mobile=mobile).exists() - or TemporaryUser.objects.filter(t_mobile=mobile).exists() - ): + if User.objects.filter(username=t_user.t_username).exists(): return Response( {"message": "User with this mobile number already registered."}, status=400,