fixed small bug
This commit is contained in:
@@ -238,7 +238,7 @@ def send_verification_email(email: str, token: str):
|
||||
raise RuntimeError("SMTP configuration is incomplete")
|
||||
|
||||
verification_url = (
|
||||
f"https://ben.de-roo.org/verify-email?token={token}"
|
||||
f"https://ben.de-roo.org/api/verify-email?token={token}"
|
||||
)
|
||||
|
||||
message = EmailMessage()
|
||||
|
||||
+75
-14
@@ -12,6 +12,7 @@ from fastapi import Query
|
||||
|
||||
from database import fetch_one, execute
|
||||
from email_service import hash_token
|
||||
from fastapi.responses import PlainTextResponse, HTMLResponse
|
||||
|
||||
from database import get_table_names
|
||||
|
||||
@@ -1006,7 +1007,10 @@ def api_update_email(
|
||||
data.email,
|
||||
)
|
||||
|
||||
@app.get("/verify-email")
|
||||
@app.get(
|
||||
"/verify-email",
|
||||
response_class=HTMLResponse,
|
||||
)
|
||||
def verify_email(token: str = Query(...)):
|
||||
token_hash = hash_token(token)
|
||||
|
||||
@@ -1020,12 +1024,23 @@ def verify_email(token: str = Query(...)):
|
||||
)
|
||||
|
||||
if not verification:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Invalid verification token"
|
||||
)
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Email verification</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Verification failed</h1>
|
||||
<p>This verification link is invalid.</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
expires_at = datetime.fromisoformat(verification["expires_at"])
|
||||
expires_at = datetime.fromisoformat(
|
||||
verification["expires_at"]
|
||||
)
|
||||
|
||||
if expires_at < datetime.now(timezone.utc):
|
||||
execute(
|
||||
@@ -1036,10 +1051,19 @@ def verify_email(token: str = Query(...)):
|
||||
(verification["id"],)
|
||||
)
|
||||
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Verification token has expired"
|
||||
)
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Email verification</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Verification expired</h1>
|
||||
<p>This verification link has expired.</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
execute(
|
||||
"""
|
||||
@@ -1058,10 +1082,47 @@ def verify_email(token: str = Query(...)):
|
||||
(verification["id"],)
|
||||
)
|
||||
|
||||
return {
|
||||
"status": "verified",
|
||||
"message": "Email address successfully verified"
|
||||
}
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Email verified</title>
|
||||
<style>
|
||||
body {
|
||||
background: #111;
|
||||
color: #eee;
|
||||
font-family: system-ui, sans-serif;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
min-height: 100vh;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.box {
|
||||
text-align: center;
|
||||
padding: 40px;
|
||||
border: 1px solid #333;
|
||||
border-radius: 12px;
|
||||
max-width: 450px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="box">
|
||||
<h1>Email verified</h1>
|
||||
<p>Your email address has been successfully verified.</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
# easter egg
|
||||
|
||||
|
||||
Reference in New Issue
Block a user