FEAT: Changed email to take in email to send to, added follow user function

This commit is contained in:
Oscar
2025-02-05 14:54:20 +00:00
parent 2c65606efe
commit 0a92f00c69
3 changed files with 36 additions and 39 deletions

View File

@@ -1,6 +1,3 @@
from flask import Blueprint, session
from database.database import Database
import smtplib
from email.mime.text import MIMEText
@@ -10,9 +7,7 @@ from dotenv import load_dotenv
load_dotenv()
email_bp = Blueprint("email", __name__)
def send_email(username) -> None:
def send_email(email) -> None:
"""
Send a verification email to the user.
"""
@@ -23,8 +18,6 @@ def send_email(username) -> None:
SMTP_EMAIL = getenv("EMAIL")
SMTP_PASSWORD = getenv("EMAIL_PASSWORD")
user_email = get_user_email(username)
# Setup up the receiver details
login_code = randrange(100000, 1000000)
body = f"""
@@ -39,7 +32,7 @@ def send_email(username) -> None:
msg = MIMEText(body, "html")
msg["Subject"] = "Reset Gander Login"
msg["From"] = SMTP_EMAIL
msg["To"] = user_email
msg["To"] = email
# Send the email using smtplib
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as smtp:
@@ -53,20 +46,4 @@ def send_email(username) -> None:
print("Server timed out")
except Exception as e:
print("Error: ", e)
def get_user_email(username):
"""
Get the users email address.
"""
db = Database()
db.create_connection()
user_email = db.fetchone("""SELECT email
FROM users
WHERE username = ?;""",
(username,))
email = user_email["email"]
db.close_connection()
return email
print("Error: ", e)