kaas
This commit is contained in:
+22
-80
@@ -20,6 +20,11 @@ from email_service import (
|
|||||||
update_email
|
update_email
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from email_service import (
|
||||||
|
update_email,
|
||||||
|
verify_email,
|
||||||
|
)
|
||||||
|
|
||||||
from auth import (
|
from auth import (
|
||||||
create_user,
|
create_user,
|
||||||
verify_user,
|
verify_user,
|
||||||
@@ -1011,52 +1016,17 @@ def api_update_email(
|
|||||||
"/verify-email",
|
"/verify-email",
|
||||||
response_class=HTMLResponse,
|
response_class=HTMLResponse,
|
||||||
)
|
)
|
||||||
def verify_email(token: str = Query(...)):
|
def api_verify_email(token: str = Query(...)):
|
||||||
token_hash = hash_token(token)
|
result = verify_email(token)
|
||||||
|
|
||||||
verification = fetch_one(
|
if result["status"] == "failed":
|
||||||
"""
|
if result["reason"] == "token_expired":
|
||||||
SELECT id, user_id, expires_at
|
|
||||||
FROM email_verifications
|
|
||||||
WHERE token_hash = ?
|
|
||||||
""",
|
|
||||||
(token_hash,)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not verification:
|
|
||||||
return """
|
return """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Email verification</title>
|
<title>Verification expired</title>
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h1>Verification failed</h1>
|
|
||||||
<p>This verification link is invalid.</p>
|
|
||||||
</body>
|
|
||||||
</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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Verification expired</h1>
|
<h1>Verification expired</h1>
|
||||||
@@ -1065,22 +1035,19 @@ def verify_email(token: str = Query(...)):
|
|||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
execute(
|
return """
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Verification failed</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Verification failed</h1>
|
||||||
|
<p>This verification link is invalid.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
"""
|
"""
|
||||||
UPDATE users
|
|
||||||
SET email_verified = 1
|
|
||||||
WHERE id = ?
|
|
||||||
""",
|
|
||||||
(verification["user_id"],)
|
|
||||||
)
|
|
||||||
|
|
||||||
execute(
|
|
||||||
"""
|
|
||||||
DELETE FROM email_verifications
|
|
||||||
WHERE id = ?
|
|
||||||
""",
|
|
||||||
(verification["id"],)
|
|
||||||
)
|
|
||||||
|
|
||||||
return """
|
return """
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
@@ -1089,30 +1056,6 @@ def verify_email(token: str = Query(...)):
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Email verified</title>
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="box">
|
<div class="box">
|
||||||
@@ -1124,7 +1067,6 @@ def verify_email(token: str = Query(...)):
|
|||||||
</html>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# easter egg
|
# easter egg
|
||||||
|
|
||||||
@app.get(
|
@app.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user