sumit1901 commited on
Commit
02438db
·
1 Parent(s): 3205f71

Trying to fix the forget password bug

Browse files
Files changed (2) hide show
  1. .env +7 -0
  2. src/utils.py +33 -41
.env ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ resend: re_B9J5e2Fh_MUA6Lmw811dYh3MV2FPjgtxZ
2
+
3
+ google scripts deployment id: AKfycbyrMnBzBqcClRJUZ01DRdB_EunfzBx-o3yCIH5UZS2rICnJbXXwrFLjHDwAZvzt3oEsnQ
4
+
5
+ url for google app:
6
+
7
+ https://script.google.com/macros/s/AKfycbyrMnBzBqcClRJUZ01DRdB_EunfzBx-o3yCIH5UZS2rICnJbXXwrFLjHDwAZvzt3oEsnQ/exec
src/utils.py CHANGED
@@ -6,9 +6,7 @@ import time
6
  import sys
7
  import json
8
  import pandas as pd
9
- import smtplib
10
- from email.mime.text import MIMEText
11
- from email.mime.multipart import MIMEMultipart
12
  from functools import wraps
13
  from src.logger import logging
14
 
@@ -228,43 +226,37 @@ def generate_dashboard_data(df, name_map: dict):
228
  # ==========================================
229
 
230
  def send_reset_email(to_email: str, reset_link: str):
231
- """Sends a password reset email using Python's smtplib."""
232
- smtp_server = os.environ.get("SMTP_SERVER", "smtp.gmail.com")
233
- smtp_port = int(os.environ.get("SMTP_PORT", 587))
234
- smtp_username = os.environ.get("SMTP_USERNAME")
235
- smtp_password = os.environ.get("SMTP_PASSWORD")
236
-
237
- if not smtp_username or not smtp_password:
238
- logging.error("SMTP credentials are not set in environment variables.")
239
- raise Exception("Email configuration missing. Please set SMTP_USERNAME and SMTP_PASSWORD.")
240
-
241
- msg = MIMEMultipart()
242
- msg['From'] = smtp_username
243
- msg['To'] = to_email
244
- msg['Subject'] = "Rankmate - Password Reset Request"
245
-
246
- body = f"""Hello,
247
-
248
- You have requested to reset your password for your Rankmate account.
249
- Please click the link below to set a new password:
250
-
251
- {reset_link}
252
-
253
- If you did not request this, please ignore this email.
254
- For your security, this link will expire in 1 hour.
255
-
256
- Best regards,
257
- The Rankmate Team
258
- """
259
- msg.attach(MIMEText(body, 'plain'))
260
 
261
  try:
262
- server = smtplib.SMTP(smtp_server, smtp_port)
263
- server.starttls()
264
- server.login(smtp_username, smtp_password)
265
- server.send_message(msg)
266
- server.quit()
267
- logging.info(f"Password reset email sent successfully to {to_email}")
268
- except Exception as e:
269
- logging.error(f"Error sending email to {to_email}: {e}")
270
- raise
 
6
  import sys
7
  import json
8
  import pandas as pd
9
+ import requests
 
 
10
  from functools import wraps
11
  from src.logger import logging
12
 
 
226
  # ==========================================
227
 
228
  def send_reset_email(to_email: str, reset_link: str):
229
+ """Sends a password reset email using a free custom webhook."""
230
+ webhook_url = os.environ.get("WEBHOOK_EMAIL_URL")
231
+
232
+ if not webhook_url:
233
+ logging.error("WEBHOOK_EMAIL_URL is not set in environment variables.")
234
+ raise Exception("Email configuration missing. Please set WEBHOOK_EMAIL_URL.")
235
+
236
+ body_html = f"""
237
+ <div style="font-family: sans-serif; padding: 20px;">
238
+ <h2>Password Reset Request</h2>
239
+ <p>Hello,</p>
240
+ <p>You have requested to reset your password for your Rankmate account.</p>
241
+ <p>Please click the button below to set a new password:</p>
242
+ <a href="{reset_link}" style="display: inline-block; padding: 10px 20px; background-color: #6366f1; color: #ffffff; text-decoration: none; border-radius: 5px;">Reset Password</a>
243
+ <p style="margin-top: 20px; font-size: 0.9em; color: #666;">If you did not request this, please ignore this email.<br>
244
+ For your security, this link will expire in 1 hour.</p>
245
+ <hr style="border: none; border-top: 1px solid #eaeaea; margin: 20px 0;">
246
+ <p style="font-size: 0.8em; color: #999;">Best regards,<br>The Rankmate Team</p>
247
+ </div>
248
+ """
249
+
250
+ payload = {
251
+ "to": to_email,
252
+ "subject": "Rankmate - Password Reset Request",
253
+ "html": body_html
254
+ }
 
 
 
255
 
256
  try:
257
+ response = requests.post(webhook_url, json=payload)
258
+ response.raise_for_status()
259
+ logging.info(f"Password reset email sent successfully via Webhook to {to_email}")
260
+ except requests.exceptions.RequestException as e:
261
+ logging.error(f"Error sending email via Webhook to {to_email}: {e}")
262
+ raise Exception(f"Failed to send email. Please try again later.")