diff --git a/services/api/app/auth/security.py b/services/api/app/auth/security.py index 6e88f46..b13305f 100644 --- a/services/api/app/auth/security.py +++ b/services/api/app/auth/security.py @@ -98,35 +98,22 @@ async def forgot_password( frontend_url = os.getenv("FRONTEND_URL", "https://bookkeepro.net") reset_link = f"{frontend_url}/reset-password?token={reset_token}" - # Add email task with error handling - async def send_reset_email_safely(): - try: - await send_email( - to=user.email, - subject="Reset your BookKeepro password", - body=f""" - Hi {user.name},

- Click the button below to reset your password:

- - - Reset Password - -

- This link expires in 15 minutes.

- BookKeepro Team - """ - ) - except Exception as e: - import logging - logger = logging.getLogger(__name__) - logger.error(f"Failed to send reset email to {user.email}: {e}") - - background.add_task(send_reset_email_safely) + reset_body = ( + f"Hi {user.name},

" + f"Click the button below to reset your password:

" + f'' + f"Reset Password

" + f"This link expires in 15 minutes.

" + f"BookKeepro Team" + ) + background.add_task( + send_email, + to=user.email, + subject="Reset your BookKeepro password", + body=reset_body, + ) return {"message": "If the email exists, a reset link has been sent"} @@ -255,29 +242,22 @@ async def signup(request: Request, payload: SignupRequest, background: Backgroun verify_token = create_email_verification_token(user.email) frontend_url = os.getenv("FRONTEND_URL", "https://bookkeepro.net") verify_link = f"{frontend_url}/verify-email?token={verify_token}" - - async def send_verify_email(): - try: - await send_email( - to=user.email, - subject="Verify your BookKeepro email", - body=f""" - Hi {user.name},

- Welcome to BookKeepro! Please verify your email address to activate your account.

- - Verify My Email - -

- This link expires in 24 hours. If you did not sign up, ignore this email.

- BookKeepro Team - """ - ) - except Exception as e: - logger.error(f"Verification email failed for {user.email}: {e}") - - background.add_task(send_verify_email) + verify_body = ( + f"Hi {user.name},

" + f"Welcome to BookKeepro! Please verify your email address to activate your account.

" + f'' + f"Verify My Email

" + f"This link expires in 24 hours. If you did not sign up, ignore this email.

" + f"BookKeepro Team" + ) + background.add_task( + send_email, + to=user.email, + subject="Verify your BookKeepro email", + body=verify_body, + ) return { "access_token": "", # no token until verified @@ -370,28 +350,22 @@ async def resend_verification( frontend_url = os.getenv("FRONTEND_URL", "https://bookkeepro.net") verify_link = f"{frontend_url}/verify-email?token={verify_token}" - async def send_resend_email(): - try: - await send_email( - to=user.email, - subject="Verify your BookKeepro email", - body=f""" - Hi {user.name},

- Here is your new verification link:

- - Verify My Email - -

- This link expires in 24 hours.

- BookKeepro Team - """ - ) - except Exception as e: - logger.error(f"Resend verification email failed for {user.email}: {e}") - - background.add_task(send_resend_email) + resend_body = ( + f"Hi {user.name},

" + f"Here is your new verification link:

" + f'' + f"Verify My Email

" + f"This link expires in 24 hours.

" + f"BookKeepro Team" + ) + background.add_task( + send_email, + to=user.email, + subject="Verify your BookKeepro email", + body=resend_body, + ) return {"message": "If the email exists and is unverified, a new link has been sent"}