Trying to fix the forget password bug
Browse files- .env +7 -0
- 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
|
| 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
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
The Rankmate Team
|
| 258 |
-
"""
|
| 259 |
-
msg.attach(MIMEText(body, 'plain'))
|
| 260 |
|
| 261 |
try:
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 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.")
|
|
|
|
|
|
|
|
|