Skip to content
This repository was archived by the owner on Jun 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 155 additions & 2 deletions app/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,85 @@
tags=["user"],
)

style = """<style>
body {
background-color: #f8f9fa;
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 0;
color: #212121;
}
.container {
max-width: 600px;
margin: 2rem auto;
background: #fff;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0,0,0,0.08);
padding: 2rem;
}
.header {
text-align: center;
margin-bottom: 1rem;
}
.title {
font-size: 1.5rem;
font-weight: 500;
}
.content {
margin: 1rem 0;
line-height: 1.6;
}
.password-box {
background-color: #e3f2fd;
padding: 1rem;
font-size: 1.25rem;
font-weight: bold;
border-radius: 6px;
text-align: center;
color: #0d47a1;
letter-spacing: 0.5px;
}
.btn {
display: inline-block;
background-color: #1976d2;
color: #fff !important;
padding: 0.75rem 1.5rem;
text-decoration: none;
border-radius: 24px;
font-weight: 500;
transition: background 0.3s ease;
}
.btn:hover {
background-color: #1565c0;
}
.footer {
text-align: center;
font-size: 0.875rem;
margin-top: 2rem;
color: #666;
}
.icon-links {
margin-top: 1rem;
text-align: center;
}
.icon-links a {
margin: 0 0.5rem;
display: inline-block;
text-decoration: none;
}
.icon-links img {
width: 24px;
height: 24px;
vertical-align: middle;
filter: grayscale(100%);
transition: filter 0.3s;
}
.icon-links img:hover {
filter: grayscale(0%);
}
</style>
"""

SECRET_KEY_JWT = os.getenv("SECRET_KEY_JWT") or "$2b$12$zqt9Rgv1PzORjG5ghJSb6OSdYrt7f7cLc38a21DgX/DMyqt80AUCi"
ALGORITHM = "HS256"

Expand Down Expand Up @@ -84,7 +163,44 @@ async def register_user(
await EmailService().send_email(
to=[user_data.email],
subject=f"[Suppl-AI] Registrazione utente",
body=f"Benvenuto in Suppl-AI!\nEcco la tua password temporanea\n\n{password}\n\n Accedi e cambiala subito!",
body=f"""
Copy link

Copilot AI May 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The HTML bodies for registration and reset are nearly identical apart from some text. Consider extracting a shared template or helper function to avoid duplication.

Copilot uses AI. Check for mistakes.
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Registrazione utente</title>
{style}
</head>
<body>
<div class="container">
<div class="header">
<div class="title" style="font-size: 2rem; font-weight: 700; color: #1976d2;">SUPPL-AI</div>
</div>
<div class="content">
<p><strong>Benvenuto in Suppl-AI!</strong></p>
<p>Ecco la tua password temporanea:</p>
<div class="password-box">{password}</div>
<p>Accedi e cambiala subito!</p>
</div>

<div class="icon-links">
<a href="https://codehex16.github.io/" title="Sito Web">
<img src="https://img.icons8.com/ios-filled/50/000000/domain.png" alt="Sito">
</a>
<a href="https://github.com/codehex16" title="GitHub">
<img src="https://img.icons8.com/ios-filled/50/000000/github.png" alt="GitHub">
</a>
</div>

<div class="footer">
Questo progetto &egrave; realizzato da <strong>CodeHex16</strong>, gruppo 16 del Progetto di SWE dell'Universit&agrave; degli Studi di Padova.
</div>
</div>
</body>
</html>
"""
# body=f"Benvenuto in Suppl-AI!\nEcco la tua password temporanea\n\n{password}\n\n Accedi e cambiala subito!",
)
except Exception as e:
raise HTTPException(
Expand Down Expand Up @@ -362,7 +478,44 @@ async def reset_password(
await EmailService().send_email(
to=[user.get("_id")],
subject="[Suppl-AI] Password Reset",
body=f"Ciao {user.get('name')},\n\nEcco la tua nuova password temporanea:\n\n{password}\n\nAccedi e cambiala subito!",
body=f"""
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Password Reset</title>
{style}
</head>
<body>
<div class="container">
<div class="header">
<div class="title" style="font-size: 2rem; font-weight: 700; color: #1976d2;">SUPPL-AI</div>
<div class="title">Ciao {html.escape(user.get('name'))},</div>
</div>
<div class="content">
Ecco la tua nuova password temporanea:
<div class="password-box">{password}</div>
<p>Accedi e cambiala subito per mantenere il tuo account sicuro.</p>
</div>

<div class="icon-links">
<a href="https://codehex16.github.io/" title="Sito Web">
<img src="https://img.icons8.com/ios-filled/50/000000/domain.png" alt="Sito">
</a>
<a href="https://github.com/codehex16" title="GitHub">
<img src="https://img.icons8.com/ios-filled/50/000000/github.png" alt="GitHub">
</a>
</div>

<div class="footer">
Questo progetto &egrave; realizzato da <strong>CodeHex16</strong>, gruppo 16 del Progetto di SWE dell'Universit&agrave; degli Studi di Padova.
</div>
</div>
</body>
</html>
"""
# body=f"Ciao {user.get('name')},\n\nEcco la tua nuova password temporanea:\n\n{password}\n\nAccedi e cambiala subito!",
)
except Exception as e:
# raise HTTPException(
Expand Down
2 changes: 1 addition & 1 deletion app/service/email_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def send_email(self, to: List[EmailStr], subject: str, body: str):
raise ValueError("Email configuration is not valid. Please check your environment variables.")
else:
message = MessageSchema(
subject=subject, recipients=to, body=body, subtype=MessageType.plain #or MessageType.html
subject=subject, recipients=to, body=body, subtype=MessageType.html #or MessageType.plain
)
await self.mail.send_message(message)

Expand Down