Initial commit: Craft2Prints with Stages 1-3

This commit is contained in:
Andymick
2026-07-15 18:09:59 +01:00
commit 41937ffc15
158 changed files with 16054 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
'use server';
import { headers } from 'next/headers';
import { prisma } from '@/lib/prisma';
import { upsertMailingListEntry } from '@/lib/mailingList';
import { verifyTurnstileToken } from '@/lib/turnstile';
import { getClientIp } from '@/lib/rateLimit';
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
export async function subscribeToNewsletter(email: string, turnstileToken: string) {
const trimmed = email.trim().toLowerCase();
if (!EMAIL_RE.test(trimmed)) {
return { ok: false, message: 'Enter a valid email address.' };
}
const ip = getClientIp(headers());
const { success } = await verifyTurnstileToken(turnstileToken, ip);
if (!success) {
return { ok: false, message: 'CAPTCHA verification failed — please try again.' };
}
await prisma.newsletterSubscriber.upsert({
where: { email: trimmed },
create: { email: trimmed },
update: {},
});
await upsertMailingListEntry({ email: trimmed, source: 'NEWSLETTER' });
return { ok: true, message: "Thanks — you're on the list." };
}