Refactor VerifyOTPView to check for existing TemporaryUser and return appropriate error messages
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 3m15s

This commit is contained in:
i701 2025-04-18 11:36:48 +05:00
parent 900a87466f
commit ac5675e923
Signed by: i701
GPG Key ID: 54A0DA1E26D8E587

View File

@ -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,