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,