update main.py

kaasislekker
This commit is contained in:
ben
2026-08-18 17:03:09 +02:00
parent 825ff19af7
commit fcfa409a09
+9 -48
View File
@@ -222,54 +222,6 @@ def verify_email(token: str):
finally: finally:
conn.close() conn.close()
def send_verification_email(email: str, token: str):
smtp_host = os.getenv("SMTP_HOST")
smtp_port = int(os.getenv("SMTP_PORT", "587"))
smtp_username = os.getenv("SMTP_USERNAME")
smtp_password = os.getenv("SMTP_PASSWORD")
smtp_from = os.getenv("SMTP_FROM")
if not all([
smtp_host,
smtp_username,
smtp_password,
smtp_from,
]):
raise RuntimeError("SMTP configuration is incomplete")
verification_url = (
f"https://ben.de-roo.org/api/verify-email?token={token}"
)
message = EmailMessage()
message["From"] = smtp_from
message["To"] = email
message["Subject"] = "Verify your Calendar email address"
message.set_content(
f"""Hello,
You requested to use this email address for your Calendar account.
Verify your email address using this link:
{verification_url}
This link expires after 24 hours.
If you did not request this, you can ignore this email.
"""
)
with smtplib.SMTP(smtp_host, smtp_port) as smtp:
smtp.starttls()
smtp.login(
smtp_username,
smtp_password,
)
smtp.send_message(message)
def send_password_reset_email(email: str, token: str): def send_password_reset_email(email: str, token: str):
smtp_host = os.getenv("SMTP_HOST") smtp_host = os.getenv("SMTP_HOST")
smtp_port = int(os.getenv("SMTP_PORT", "587")) smtp_port = int(os.getenv("SMTP_PORT", "587"))
@@ -310,13 +262,22 @@ If you did not request this, you can ignore this email.
""" """
) )
print(f"Sending password reset email to {email}")
with smtplib.SMTP(smtp_host, smtp_port) as smtp: with smtplib.SMTP(smtp_host, smtp_port) as smtp:
print("SMTP connected")
smtp.starttls() smtp.starttls()
print("TLS started")
smtp.login( smtp.login(
smtp_username, smtp_username,
smtp_password, smtp_password,
) )
print("SMTP login successful")
smtp.send_message(message) smtp.send_message(message)
print("Password reset email sent")
def create_password_reset(user_id: int): def create_password_reset(user_id: int):
token = secrets.token_urlsafe(32) token = secrets.token_urlsafe(32)