diff --git a/padelnomics/src/padelnomics/worker.py b/padelnomics/src/padelnomics/worker.py index 2cceb31..b86a64b 100644 --- a/padelnomics/src/padelnomics/worker.py +++ b/padelnomics/src/padelnomics/worker.py @@ -12,6 +12,46 @@ from .core import config, execute, fetch_all, init_db, send_email HANDLERS: dict[str, callable] = {} +def _email_wrap(body: str) -> str: + """Wrap email body in a branded layout with inline CSS.""" + return f"""\ + + + + + + +
+ + + + + + + +
+ {config.APP_NAME} +
+ {body} +
+ © {config.APP_NAME} · You received this because you have an account. +
+
+ +""" + + +def _email_button(url: str, label: str) -> str: + """Render a branded CTA button for email.""" + return ( + f'' + f'
' + f'' + f'{label}
' + ) + + def task(name: str): """Decorator to register a task handler.""" def decorator(f): @@ -105,35 +145,37 @@ async def handle_send_email(payload: dict) -> None: async def handle_send_magic_link(payload: dict) -> None: """Send magic link email.""" link = f"{config.BASE_URL}/auth/verify?token={payload['token']}" - - html = f""" -

Sign in to {config.APP_NAME}

-

Click the link below to sign in:

-

{link}

-

This link expires in {config.MAGIC_LINK_EXPIRY_MINUTES} minutes.

-

If you didn't request this, you can safely ignore this email.

- """ - + + body = ( + f'

Sign in to {config.APP_NAME}

' + f"

Click the button below to sign in. This link expires in " + f"{config.MAGIC_LINK_EXPIRY_MINUTES} minutes.

" + f"{_email_button(link, 'Sign In')}" + f'

If the button doesn\'t work, copy and paste this URL into your browser:

' + f'

{link}

' + f'

If you didn\'t request this, you can safely ignore this email.

' + ) + await send_email( to=payload["email"], subject=f"Sign in to {config.APP_NAME}", - html=html, + html=_email_wrap(body), ) @task("send_welcome") async def handle_send_welcome(payload: dict) -> None: """Send welcome email to new user.""" - html = f""" -

Welcome to {config.APP_NAME}!

-

Thanks for signing up. We're excited to have you.

-

Go to your dashboard

- """ - + body = ( + f'

Welcome to {config.APP_NAME}!

' + f"

Thanks for signing up. You're all set to start planning your padel business.

" + f'{_email_button(f"{config.BASE_URL}/dashboard", "Go to Dashboard")}' + ) + await send_email( to=payload["email"], subject=f"Welcome to {config.APP_NAME}", - html=html, + html=_email_wrap(body), )