From 3ac7e6eb8ff7d2cf3dede1b9ae98e6ba32a33cfe Mon Sep 17 00:00:00 2001 From: vickytechkey Date: Sun, 4 Oct 2026 11:37:09 +0530 Subject: [PATCH] feat: implement user authentication, profile management, and WhatsApp OTP verification views --- api/views.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/api/views.py b/api/views.py index b9a5ca0..0393399 100644 --- a/api/views.py +++ b/api/views.py @@ -128,22 +128,26 @@ class SendWhatsAppOTPView(APIView): raw_10 = clean_phone[-10:] if len(clean_phone) >= 10 else clean_phone # Account existence validation - user_exists = False + from django.db.models import Q + user_exists = None try: from orders.models import CustomerProfile - user_exists = User.objects.filter(username__icontains=raw_10).exists() or CustomerProfile.objects.filter(phone__icontains=raw_10).exists() + user_exists = ( + User.objects.filter(Q(username__icontains=raw_10) | Q(email__icontains=raw_10)).exists() + or CustomerProfile.objects.filter(Q(phone__icontains=raw_10) | Q(user__username__icontains=raw_10)).exists() + ) except Exception as db_err: audit_logger.warning(f"DB lookup notice for {mobile_number}: {db_err}") - user_exists = False + user_exists = None - if purpose == 'login' and not user_exists: + if purpose == 'login' and user_exists is False: audit_logger.warning(f"AUDIT - Login attempt for non-existent mobile: '{mobile_number}'") return Response({ "status": "error", "message": "Account not found. Please create a patron account first." }, status=status.HTTP_404_NOT_FOUND) - if purpose == 'register' and user_exists: + if purpose == 'register' and user_exists is True: audit_logger.warning(f"AUDIT - Register attempt for existing mobile: '{mobile_number}'") return Response({ "status": "error",