CineDev commited on
Commit
8853418
·
1 Parent(s): 23d9df5

Remove OTP email verification and auto-verify user profiles by default

Browse files
Files changed (2) hide show
  1. users/models.py +1 -1
  2. users/views.py +17 -81
users/models.py CHANGED
@@ -20,7 +20,7 @@ class FinancialProfile(models.Model):
20
  credit_limit = models.DecimalField(max_digits=15, decimal_places=2, default=0.00)
21
 
22
  # Verification Data (Mobile removed)
23
- is_email_verified = models.BooleanField(default=False)
24
  email_otp = models.CharField(max_length=6, blank=True, null=True)
25
 
26
  # Onboarding status
 
20
  credit_limit = models.DecimalField(max_digits=15, decimal_places=2, default=0.00)
21
 
22
  # Verification Data (Mobile removed)
23
+ is_email_verified = models.BooleanField(default=True)
24
  email_otp = models.CharField(max_length=6, blank=True, null=True)
25
 
26
  # Onboarding status
users/views.py CHANGED
@@ -37,7 +37,7 @@ class UserProfileView(APIView):
37
  def generate_otp():
38
  return str(random.randint(100000, 999999))
39
 
40
- # --- 3. Send Email OTP View ---
41
  class SendEmailOTPView(APIView):
42
  permission_classes = [IsAuthenticated]
43
 
@@ -47,96 +47,32 @@ class SendEmailOTPView(APIView):
47
  if not hasattr(user, 'profile'):
48
  FinancialProfile.objects.create(user=user)
49
 
50
- otp = generate_otp()
51
- user.profile.email_otp = otp
52
  user.profile.save()
53
 
54
- try:
55
- subject = 'Aureon - Verify Your Identity'
56
- user_name = user.email.split('@')[0]
57
-
58
- # OTP HTML Template
59
- html_message = f"""
60
- <!DOCTYPE html>
61
- <html lang="en">
62
- <head>
63
- <meta charset="UTF-8">
64
- <style>
65
- body {{ margin: 0; padding: 0; font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; background-color: #0f172a; color: #e2e8f0; }}
66
- .email-wrapper {{ width: 100%; background-color: #0f172a; padding: 40px 0; }}
67
- .email-content {{ max-width: 500px; margin: 0 auto; background-color: #1e293b; border-radius: 12px; overflow: hidden; border: 1px solid #334155; }}
68
- .header {{ background-color: #1e293b; padding: 30px 0; text-align: center; border-bottom: 1px solid #334155; }}
69
- .logo-text {{ font-size: 24px; font-weight: 700; color: #10b981; letter-spacing: 2px; text-transform: uppercase; text-decoration: none; }}
70
- .body-content {{ padding: 40px 30px; text-align: center; }}
71
- .greeting {{ font-size: 18px; color: #f8fafc; margin-bottom: 16px; }}
72
- .otp-box {{ background-color: #0f172a; border: 1px dashed #10b981; border-radius: 8px; padding: 20px; margin: 0 auto 30px; max-width: 200px; }}
73
- .otp-code {{ font-family: 'Courier New', monospace; font-size: 32px; font-weight: 700; letter-spacing: 6px; color: #10b981; margin: 0; }}
74
- .footer {{ padding: 24px; background-color: #0f172a; text-align: center; font-size: 12px; color: #64748b; border-top: 1px solid #334155; }}
75
- </style>
76
- </head>
77
- <body>
78
- <div class="email-wrapper">
79
- <div class="email-content">
80
- <div class="header"><div class="logo-text">AUREON</div></div>
81
- <div class="body-content">
82
- <h2 class="greeting">Verify your email</h2>
83
- <p style="color: #94a3b8; margin-bottom: 30px;">Hello <strong>{user_name}</strong>,<br>Use the code below to complete your sign-in.</p>
84
- <div class="otp-box"><div class="otp-code">{otp}</div></div>
85
- <p style="font-size: 13px; color: #ef4444;">⏳ This code expires in 10 minutes.</p>
86
- </div>
87
- <div class="footer"><p>&copy; 2025 Aureon Financial.</p></div>
88
- </div>
89
- </div>
90
- </body>
91
- </html>
92
- """
93
-
94
- send_mail(
95
- subject=subject,
96
- message=f"Your Aureon verification code is: {otp}",
97
- html_message=html_message,
98
- from_email=settings.DEFAULT_FROM_EMAIL,
99
- recipient_list=[user.email],
100
- fail_silently=False,
101
- )
102
-
103
- return Response({'message': 'OTP sent successfully', 'email': user.email})
104
-
105
- except Exception as e:
106
- return Response({'error': str(e)}, status=500)
107
 
108
- # --- 4. Verify Email OTP View (Updated with Welcome Email) ---
109
  class VerifyEmailOTPView(APIView):
110
  permission_classes = [IsAuthenticated]
111
 
112
  def post(self, request):
113
- otp = request.data.get('otp')
114
-
115
- if not otp:
116
- return Response({'error': 'OTP is required'}, status=400)
117
-
118
  user = request.user
119
  profile = user.profile
120
 
121
- if profile.email_otp == otp:
122
- # Check if this is the FIRST time they are verifying
123
- is_first_verification = not profile.is_email_verified
124
-
125
- # Mark email as verified
126
- profile.is_email_verified = True
127
- profile.email_otp = None
128
- profile.save()
129
-
130
- # --- SEND WELCOME EMAIL IF FIRST TIME ---
131
- if is_first_verification:
132
- self.send_welcome_email(user)
133
-
134
- return Response({
135
- 'message': 'Email verified successfully',
136
- 'is_email_verified': True
137
- })
138
- else:
139
- return Response({'error': 'Invalid OTP'}, status=400)
140
 
141
  def send_welcome_email(self, user):
142
  """Helper to send the welcome email"""
 
37
  def generate_otp():
38
  return str(random.randint(100000, 999999))
39
 
40
+ # --- 3. Send Email OTP View (Bypassed) ---
41
  class SendEmailOTPView(APIView):
42
  permission_classes = [IsAuthenticated]
43
 
 
47
  if not hasattr(user, 'profile'):
48
  FinancialProfile.objects.create(user=user)
49
 
50
+ # Auto-verify email
51
+ user.profile.is_email_verified = True
52
  user.profile.save()
53
 
54
+ return Response({
55
+ 'message': 'Email verification bypassed. Auto-verified.',
56
+ 'email': user.email,
57
+ 'is_email_verified': True
58
+ })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
+ # --- 4. Verify Email OTP View (Bypassed) ---
61
  class VerifyEmailOTPView(APIView):
62
  permission_classes = [IsAuthenticated]
63
 
64
  def post(self, request):
 
 
 
 
 
65
  user = request.user
66
  profile = user.profile
67
 
68
+ profile.is_email_verified = True
69
+ profile.email_otp = None
70
+ profile.save()
71
+
72
+ return Response({
73
+ 'message': 'Email verified successfully (bypassed)',
74
+ 'is_email_verified': True
75
+ })
 
 
 
 
 
 
 
 
 
 
 
76
 
77
  def send_welcome_email(self, user):
78
  """Helper to send the welcome email"""