diff --git a/server/main.py b/server/main.py index 1496999..7c79568 100644 --- a/server/main.py +++ b/server/main.py @@ -7,6 +7,7 @@ import os from fastapi import FastAPI +from fastapi.staticfiles import StaticFiles from fastapi.middleware.cors import CORSMiddleware from .routers import health_prediction, authentication, users, admin @@ -26,6 +27,11 @@ ] app = FastAPI() +app.mount( + "/static", + StaticFiles(directory="server/static"), + name="static", +) app.add_middleware( CORSMiddleware, allow_origins=ORIGINS, diff --git a/server/routers/authentication.py b/server/routers/authentication.py index ab4b529..e612e57 100644 --- a/server/routers/authentication.py +++ b/server/routers/authentication.py @@ -199,23 +199,154 @@ async def register(user_reg: UserRegistrationDetails, def _send_validation_email(user: UserAccount, token: str): - """Send an email-validation link to the newly registered user.""" + """Send a branded email-validation link to the newly registered user.""" BACKEND_URL = os.getenv( "BACKEND_URL", "https://shp-backend.onrender.com" ) validation_url = f"{BACKEND_URL}/validate-email?token={token}" - email_subject = "Validate your account" + + logo_url = f"{BACKEND_URL}/static/images/wellai-logo.png" + + email_subject = "Verify your WellAI account" + email_content = f""" - -

Welcome to Smart Health Predictive!

-

Please click the link below to validate your email address:

- {validation_url} + +
+ + +
+ WellAI +
+ + +
+

+ Verify your WellAI account +

+ +

+ Registration successful! +

+ +

+ Thank you for creating your WellAI account. + Please verify your email address to complete + your account setup. +

+ + +
+ + Verify my email + +
+ +

+ If you did not create a WellAI account, + you can safely ignore this email. +

+ +

+ For your security, please do not forward this + email or share your verification link. +

+
+ + +
+

+ Please do not reply to this email. +

+ +

+ + Privacy Notice + +

+ +

+ © 2026 WellAI Sdn. Bhd. All rights reserved. +

+
+ +
""" + send_email( recipient=user.Email, subject=email_subject, @@ -227,10 +358,152 @@ def _send_validation_email(user: UserAccount, token: str): @router.get("/validate-email") async def validate_email_address(token: str, db_conn: Session = Depends(get_db)): """Validate a user's email address via a signed token sent by email.""" - validation_failure_exception = HTTPException( - status_code=status.HTTP_400_BAD_REQUEST, - detail="Invalid or expired validation token." - ) + def validation_error_response(): + html_content = """ + + + + + + Verification Link Invalid - WellAI + + + + +
+ +
+
WellAI
+
Love Yourself
+
+ +
+
!
+ +

Verification Link Invalid

+ +

+ This email verification link is no longer valid. + It may have expired or already been used. +

+ +

+ Please request a new verification email to continue + setting up your WellAI account. +

+
+ + + +
+ + + """ + + return HTMLResponse( + content=html_content, + status_code=status.HTTP_400_BAD_REQUEST + ) # Find the token in the database validation_token_entry = db_conn.query( @@ -238,18 +511,18 @@ async def validate_email_address(token: str, db_conn: Session = Depends(get_db)) # Check if the token exists if not validation_token_entry: - raise validation_failure_exception + return validation_error_response() # Check if the token has expired if validation_token_entry.ExpiresAt < datetime.utcnow(): - raise validation_failure_exception + return validation_error_response() # Get the user associated with the token user = db_conn.query(UserAccount).filter_by( UserID=validation_token_entry.UserID).first() if not user: # This should not happen if database integrity is maintained - raise validation_failure_exception + return validation_error_response() # Update the user's validation status user.IsValidated = True @@ -266,21 +539,161 @@ async def validate_email_address(token: str, db_conn: Session = Depends(get_db)) description=f"Email successfully validated.") html_content = """ - - - Email Validation - - - -
-

Email Validated Successfully!

-

Your email has been successfully validated. You can now close this window and log in to your account.

+ + + + + + Email Verified - WellAI + + + + +
+ +
+
WellAI
+
Love Yourself
- + +
+
+ +

Email Verified Successfully!

+ +

+ Your email address has been successfully verified. +

+ +

+ Your WellAI account is now ready. You can close this window + and return to the WellAI application to log in. +

+
+ + + +
+ """ return HTMLResponse(content=html_content) diff --git a/server/static/images/wellai-logo.png b/server/static/images/wellai-logo.png new file mode 100644 index 0000000..2b51fb2 Binary files /dev/null and b/server/static/images/wellai-logo.png differ