diff --git a/backend/main.py b/backend/main.py index ae3401d..97db57b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -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 """ + + + + + Verification expired + + +

Verification expired

+

This verification link has expired.

+ + + """ - if not verification: return """ - Email verification + Verification failed

Verification failed

@@ -1038,50 +1049,6 @@ def verify_email(token: str = Query(...)): """ - expires_at = datetime.fromisoformat( - verification["expires_at"] - ) - - if expires_at < datetime.now(timezone.utc): - execute( - """ - DELETE FROM email_verifications - WHERE id = ? - """, - (verification["id"],) - ) - - return """ - - - - - Email verification - - -

Verification expired

-

This verification link has expired.

- - - """ - - execute( - """ - UPDATE users - SET email_verified = 1 - WHERE id = ? - """, - (verification["user_id"],) - ) - - execute( - """ - DELETE FROM email_verifications - WHERE id = ? - """, - (verification["id"],) - ) - return """ @@ -1089,30 +1056,6 @@ def verify_email(token: str = Query(...)): Email verified -
@@ -1124,7 +1067,6 @@ def verify_email(token: str = Query(...)): """ - # easter egg @app.get(