Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions backend/src/handlers/auth/custom-message-trigger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import type { CustomMessageTriggerEvent } from 'aws-lambda';
import { renderEmailLayout } from '../../services/email-layout';

function codeBadgeHtml(code: string): string {
return `<div style="margin:20px 0;padding:16px 24px;background-color:#F7F5F0;border-radius:10px;text-align:center;">
<span style="font-family:'Courier New',monospace;font-size:28px;font-weight:700;letter-spacing:0.3em;color:#0A4267;">${code}</span>
</div>`;
}

/**
* Cognito Custom Message trigger: replaces the default bare-text
* verification/reset emails with the same branded HTML shell the
* notification dispatcher uses for everything else (see
* services/email-layout.ts). Cognito still does the actual sending —
* this only supplies the subject/body it sends.
*/
export const handler = async (event: CustomMessageTriggerEvent): Promise<CustomMessageTriggerEvent> => {
const code = event.request.codeParameter;

if (event.triggerSource === 'CustomMessage_SignUp' || event.triggerSource === 'CustomMessage_ResendCode') {
const { html } = renderEmailLayout({
eyebrow: 'Verify your email',
heading: 'Confirm your Muster account',
bodyHtml: `<p>Thanks for signing up. Enter this code to verify your email address:</p>${codeBadgeHtml(code)}<p>If you didn't create a Muster account, you can safely ignore this email.</p>`,
bodyText: `Enter this code to verify your email address: ${code}\n\nIf you didn't create a Muster account, you can safely ignore this email.`,
});
event.response.emailSubject = 'Verify your Muster account';
event.response.emailMessage = html;
return event;
}

if (event.triggerSource === 'CustomMessage_ForgotPassword') {
const { html } = renderEmailLayout({
eyebrow: 'Password reset',
heading: 'Reset your Muster password',
bodyHtml: `<p>Use this code to choose a new password:</p>${codeBadgeHtml(code)}<p>If you didn't request a password reset, you can safely ignore this email.</p>`,
bodyText: `Use this code to choose a new password: ${code}\n\nIf you didn't request a password reset, you can safely ignore this email.`,
});
event.response.emailSubject = 'Reset your Muster password';
event.response.emailMessage = html;
return event;
}

return event;
};
15 changes: 15 additions & 0 deletions backend/src/lib/date-format.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const formatter = new Intl.DateTimeFormat('en-US', {
weekday: 'short',
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
timeZone: 'UTC',
timeZoneName: 'short',
});

/** Renders an ISO date string for email copy, e.g. "Tue, Sep 1, 2026, 9:00 AM UTC". */
export function formatEmailDate(iso: string): string {
return formatter.format(new Date(iso));
}
1 change: 1 addition & 0 deletions backend/src/lib/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const createEventSchema = z
endDate: isoDateSchema,
capacity: z.number().int().min(0).max(1_000_000),
ticketLink: urlSchema,
imageUrl: urlSchema,
})
.refine((data) => Date.parse(data.endDate) >= Date.parse(data.startDate), {
message: 'endDate must be on or after startDate.',
Expand Down
1 change: 1 addition & 0 deletions backend/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface EventRecord {
capacity: number;
registeredCount: number;
ticketLink: string;
imageUrl?: string;
status: EventStatus;
rejectionReason?: string;
createdAt: string;
Expand Down
83 changes: 83 additions & 0 deletions backend/src/services/email-layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Shared HTML shell for outbound email. Table-based markup with inline
* styles only — the notification dispatcher Lambda sends this straight
* through SES with no further processing, and inboxes (Outlook's Word
* rendering engine especially) don't reliably support <style> blocks or
* modern layout CSS.
*
* Colors are pulled from the marketing site's hero gradient
* (#010A17 -> #0A4267 -> #20658E -> #6BADC4) so an email and the page a
* recipient lands on afterward feel like the same product.
*/
export interface EmailLayoutInput {
/** Short line shown above the heading, e.g. "Event update". */
eyebrow: string;
heading: string;
/** Pre-escaped HTML paragraphs/lists making up the message body. */
bodyHtml: string;
/** Plain-text mirror of bodyHtml, for the text/plain alternative part. */
bodyText: string;
cta?: { label: string; href: string };
}

const YEAR = new Date().getFullYear();

export function renderEmailLayout({ eyebrow, heading, bodyHtml, bodyText, cta }: EmailLayoutInput): {
html: string;
text: string;
} {
const ctaHtml = cta
? `<table role="presentation" cellpadding="0" cellspacing="0" style="margin-top:28px;">
<tr>
<td style="border-radius:8px;background-color:#2C7DA6;">
<a href="${cta.href}" style="display:inline-block;padding:12px 28px;font-family:Arial,Helvetica,sans-serif;font-size:14px;font-weight:600;color:#ffffff;text-decoration:none;letter-spacing:0.02em;">
${cta.label}
</a>
</td>
</tr>
</table>`
: '';
const ctaText = cta ? `\n${cta.label}: ${cta.href}\n` : '';

const html = `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>${heading}</title>
</head>
<body style="margin:0;padding:0;background-color:#0A0608;">
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" style="background-color:#0A0608;padding:32px 16px;">
<tr>
<td align="center">
<table role="presentation" width="480" cellpadding="0" cellspacing="0" style="width:100%;max-width:480px;background-color:#ffffff;border-radius:16px;overflow:hidden;">
<tr>
<td style="background-color:#0A4267;background-image:linear-gradient(135deg,#0A4267,#20658E);padding:28px 32px;">
<span style="font-family:Georgia,'Times New Roman',serif;font-style:italic;font-size:26px;color:#ffffff;">Muster</span>
</td>
</tr>
<tr>
<td style="padding:36px 32px 32px;font-family:Arial,Helvetica,sans-serif;color:#0A0608;">
<p style="margin:0 0 8px;font-size:11px;font-weight:700;letter-spacing:0.12em;text-transform:uppercase;color:#2C7DA6;">${eyebrow}</p>
<h1 style="margin:0 0 18px;font-size:22px;line-height:1.3;font-weight:700;color:#0A0608;">${heading}</h1>
<div style="font-size:14px;line-height:1.7;color:#3a3a3d;">${bodyHtml}</div>
${ctaHtml}
</td>
</tr>
<tr>
<td style="padding:20px 32px;background-color:#F7F5F0;font-family:Arial,Helvetica,sans-serif;font-size:12px;color:#8a8a86;">
© ${YEAR} Muster · Event registration &amp; ticketing<br />
This is an automated message — please don't reply directly to this email.
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>`;

const text = `${eyebrow.toUpperCase()}\n${heading}\n\n${bodyText}\n${ctaText}\n— Muster · Event registration & ticketing`;

return { html, text };
}
75 changes: 52 additions & 23 deletions backend/src/services/email-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { escapeHtml } from '../lib/html';
import { env } from '../lib/env';
import { NotificationType } from '../models/enums';
import { NotificationMessage } from '../models/types';
import { renderEmailLayout } from './email-layout';
import { formatEmailDate } from '../lib/date-format';

export interface EmailContent {
to: string;
Expand All @@ -19,45 +21,72 @@ export function renderEmail(message: NotificationMessage): EmailContent {
const subject = approved
? `Your event "${message.eventTitle}" was approved`
: `Your event "${message.eventTitle}" was not approved`;
const reasonLine =
!approved && message.reason ? `<p><strong>Reason:</strong> ${escapeHtml(message.reason)}</p>` : '';
const reasonText = !approved && message.reason ? `Reason: ${message.reason}\n` : '';
return {
to: message.organizerEmail,
subject,
html: `<p>Hello,</p><p>Your event <strong>${title}</strong> has been <strong>${message.decision}</strong> by an administrator.</p>${reasonLine}<p>— Event Registration & Ticketing System</p>`,
text: `Hello,\n\nYour event "${message.eventTitle}" has been ${message.decision} by an administrator.\n${reasonText}\n— Event Registration & Ticketing System`,
};

const reasonHtml =
!approved && message.reason
? `<p style="margin:16px 0 0;padding:12px 14px;background-color:#F7F5F0;border-radius:8px;"><strong>Reason:</strong> ${escapeHtml(message.reason)}</p>`
: '';
const reasonText = !approved && message.reason ? `\nReason: ${message.reason}` : '';

const { html, text } = renderEmailLayout({
eyebrow: 'Event update',
heading: approved ? 'Your event is live 🎉' : 'Your event needs changes',
bodyHtml: approved
? `<p>Good news — <strong>${title}</strong> has been reviewed and approved by a Muster admin. It's now visible to everyone browsing events.</p>`
: `<p><strong>${title}</strong> was reviewed and was not approved this time. You can update the listing and resubmit it for review.</p>${reasonHtml}`,
bodyText: approved
? `Good news — "${message.eventTitle}" has been reviewed and approved by a Muster admin. It's now visible to everyone browsing events.`
: `"${message.eventTitle}" was reviewed and was not approved this time. You can update the listing and resubmit it for review.${reasonText}`,
});

return { to: message.organizerEmail, subject, html, text };
}
case NotificationType.REGISTRATION_CONFIRMED: {
const title = escapeHtml(message.eventTitle);
const link = escapeHtml(message.ticketLink);
return {
to: message.userEmail,
subject: `You're registered for ${message.eventTitle}`,
html: `<p>Hello,</p><p>You are confirmed for <strong>${title}</strong> on ${escapeHtml(message.eventStartDate)}.</p><p>Your ticket: <a href="${link}">${link}</a></p><p>— Event Registration & Ticketing System</p>`,
text: `Hello,\n\nYou are confirmed for "${message.eventTitle}" on ${message.eventStartDate}.\nYour ticket: ${message.ticketLink}\n\n— Event Registration & Ticketing System`,
};
const when = formatEmailDate(message.eventStartDate);

const { html, text } = renderEmailLayout({
eyebrow: "You're registered",
heading: `See you at ${title}`,
bodyHtml: `<p>Your spot for <strong>${title}</strong> is confirmed for <strong>${escapeHtml(when)}</strong>.</p><p>Bring the ticket link below — you'll need it to check in.</p>`,
bodyText: `Your spot for "${message.eventTitle}" is confirmed for ${when}.\nBring the ticket link below — you'll need it to check in.`,
cta: { label: 'View your ticket', href: link },
});

return { to: message.userEmail, subject: `You're registered for ${message.eventTitle}`, html, text };
}
case NotificationType.REGISTRATION_CANCELLED: {
const title = escapeHtml(message.eventTitle);
return {
to: message.userEmail,
subject: `Your registration for ${message.eventTitle} was cancelled`,
html: `<p>Hello,</p><p>Your registration for <strong>${title}</strong> has been cancelled.</p><p>— Event Registration & Ticketing System</p>`,
text: `Hello,\n\nYour registration for "${message.eventTitle}" has been cancelled.\n\n— Event Registration & Ticketing System`,
};

const { html, text } = renderEmailLayout({
eyebrow: 'Registration cancelled',
heading: 'Your registration was cancelled',
bodyHtml: `<p>Your registration for <strong>${title}</strong> has been cancelled and your spot released back to the event.</p><p>Change of mind? You can register again any time, capacity permitting.</p>`,
bodyText: `Your registration for "${message.eventTitle}" has been cancelled and your spot released back to the event.\nChange of mind? You can register again any time, capacity permitting.`,
});

return { to: message.userEmail, subject: `Your registration for ${message.eventTitle} was cancelled`, html, text };
}
case NotificationType.CONTACT_MESSAGE_RECEIVED: {
const name = escapeHtml(message.name);
const email = escapeHtml(message.email);
const body = escapeHtml(message.message).replaceAll('\n', '<br />');

const { html, text } = renderEmailLayout({
eyebrow: 'Contact form',
heading: `New message from ${name}`,
bodyHtml: `<p><strong>${name}</strong> (${email}) sent this via the Muster contact form:</p><p style="margin-top:12px;padding:12px 14px;background-color:#F7F5F0;border-radius:8px;">${body}</p>`,
bodyText: `${message.name} (${message.email}) sent this via the Muster contact form:\n\n${message.message}`,
cta: { label: `Reply to ${name}`, href: `mailto:${email}` },
});

return {
to: env.senderEmail,
replyTo: message.email,
subject: `New contact message from ${message.name}`,
html: `<p><strong>${name}</strong> (${email}) sent a message via the Muster contact form:</p><p>${body}</p>`,
text: `${message.name} (${message.email}) sent a message via the Muster contact form:\n\n${message.message}`,
html,
text,
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions backend/src/services/event-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const EventService = {
capacity: input.capacity,
registeredCount: 0,
ticketLink: input.ticketLink,
imageUrl: input.imageUrl,
status: EventStatus.PENDING_REVIEW,
createdAt: now,
updatedAt: now,
Expand Down Expand Up @@ -80,6 +81,7 @@ export const EventService = {
endDate: input.endDate,
capacity: input.capacity,
ticketLink: input.ticketLink,
imageUrl: input.imageUrl,
status: EventStatus.PENDING_REVIEW,
rejectionReason: undefined,
updatedAt: now,
Expand Down
1 change: 1 addition & 0 deletions backend/tests/unit/lib/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('createEventSchema', () => {
endDate: '2026-09-01T17:00:00.000Z',
capacity: 100,
ticketLink: 'https://example.com/tickets',
imageUrl: 'https://example.com/image.jpg',
};

it('accepts a valid payload', () => {
Expand Down
1 change: 1 addition & 0 deletions backend/tests/unit/services/event-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const createInput = {
endDate: '2030-01-01T02:00:00.000Z',
capacity: 50,
ticketLink: 'https://example.com/ticket',
imageUrl: 'https://example.com/image.jpg',
};

describe('EventService.createEvent', () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Geist:wght@300;400;500;600;700&display=swap"
href="https://fonts.googleapis.com/css2?family=Dancing+Script:wght@400;500;600;700&family=Instrument+Serif:ital@0;1&family=Inter:wght@300;400;500;600;700;800;900&display=swap"
rel="stylesheet"
/>
<title>Muster — Event registration &amp; ticketing</title>
Expand Down
Loading
Loading