kaas
This commit is contained in:
+23
-81
@@ -20,6 +20,11 @@ from email_service import (
|
||||
update_email
|
||||
)
|
||||
|
||||
from email_service import (
|
||||
update_email,
|
||||
verify_email,
|
||||
)
|
||||
|
||||
from auth import (
|
||||
create_user,
|
||||
verify_user,
|
||||
@@ -1011,25 +1016,31 @@ def api_update_email(
|
||||
"/verify-email",
|
||||
response_class=HTMLResponse,
|
||||
)
|
||||
def verify_email(token: str = Query(...)):
|
||||
token_hash = hash_token(token)
|
||||
def api_verify_email(token: str = Query(...)):
|
||||
result = verify_email(token)
|
||||
|
||||
verification = fetch_one(
|
||||
"""
|
||||
SELECT id, user_id, expires_at
|
||||
FROM email_verifications
|
||||
WHERE token_hash = ?
|
||||
""",
|
||||
(token_hash,)
|
||||
)
|
||||
if result["status"] == "failed":
|
||||
if result["reason"] == "token_expired":
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Verification expired</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Verification expired</h1>
|
||||
<p>This verification link has expired.</p>
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
|
||||
if not verification:
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Email verification</title>
|
||||
<title>Verification failed</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Verification failed</h1>
|
||||
@@ -1038,50 +1049,6 @@ def verify_email(token: str = Query(...)):
|
||||
</html>
|
||||
"""
|
||||
|
||||
expires_at = datetime.fromisoformat(
|
||||
verification["expires_at"]
|
||||
)
|
||||
|
||||
if expires_at < datetime.now(timezone.utc):
|
||||
execute(
|
||||
"""
|
||||
DELETE FROM email_verifications
|
||||
WHERE id = ?
|
||||
""",
|
||||
(verification["id"],)
|
||||
)
|
||||
|
||||
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(
|
||||
"""
|
||||
UPDATE users
|
||||
SET email_verified = 1
|
||||
WHERE id = ?
|
||||
""",
|
||||
(verification["user_id"],)
|
||||
)
|
||||
|
||||
execute(
|
||||
"""
|
||||
DELETE FROM email_verifications
|
||||
WHERE id = ?
|
||||
""",
|
||||
(verification["id"],)
|
||||
)
|
||||
|
||||
return """
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
@@ -1089,30 +1056,6 @@ def verify_email(token: str = Query(...)):
|
||||
<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">
|
||||
@@ -1124,7 +1067,6 @@ def verify_email(token: str = Query(...)):
|
||||
</html>
|
||||
"""
|
||||
|
||||
|
||||
# easter egg
|
||||
|
||||
@app.get(
|
||||
|
||||
Reference in New Issue
Block a user