Merge pull request #17 from javaxman/fix/newsletter-confirm-unsubscribe-link
Link disiscrizione sulla pagina di conferma newsletter
This commit is contained in:
@ -79,5 +79,8 @@ export const GET: APIRoute = async ({ request, locals, url }) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response.redirect(new URL(okPath, request.url).toString(), 303);
|
return Response.redirect(
|
||||||
|
new URL(`${okPath}?unsub=${encodeURIComponent(row.unsubscribe_token)}`, request.url).toString(),
|
||||||
|
303,
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -18,7 +18,11 @@ import {
|
|||||||
|
|
||||||
export const prerender = false;
|
export const prerender = false;
|
||||||
|
|
||||||
function confirmEmailCopy(locale: string, confirmUrl: string): { subject: string; text: string } {
|
function confirmEmailCopy(
|
||||||
|
locale: string,
|
||||||
|
confirmUrl: string,
|
||||||
|
unsubscribeUrl: string,
|
||||||
|
): { subject: string; text: string } {
|
||||||
if (locale === 'en') {
|
if (locale === 'en') {
|
||||||
return {
|
return {
|
||||||
subject: 'Confirm your NexStudio newsletter subscription',
|
subject: 'Confirm your NexStudio newsletter subscription',
|
||||||
@ -29,6 +33,9 @@ function confirmEmailCopy(locale: string, confirmUrl: string): { subject: string
|
|||||||
confirmUrl,
|
confirmUrl,
|
||||||
'',
|
'',
|
||||||
'If you did not request this, you can ignore this message.',
|
'If you did not request this, you can ignore this message.',
|
||||||
|
'',
|
||||||
|
'Unsubscribe:',
|
||||||
|
unsubscribeUrl,
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -42,6 +49,9 @@ function confirmEmailCopy(locale: string, confirmUrl: string): { subject: string
|
|||||||
confirmUrl,
|
confirmUrl,
|
||||||
'',
|
'',
|
||||||
'หากคุณไม่ได้ขอสมัคร สามารถเพิกเฉยต่อข้อความนี้ได้',
|
'หากคุณไม่ได้ขอสมัคร สามารถเพิกเฉยต่อข้อความนี้ได้',
|
||||||
|
'',
|
||||||
|
'ยกเลิกการสมัคร:',
|
||||||
|
unsubscribeUrl,
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -54,6 +64,9 @@ function confirmEmailCopy(locale: string, confirmUrl: string): { subject: string
|
|||||||
confirmUrl,
|
confirmUrl,
|
||||||
'',
|
'',
|
||||||
'Se non hai richiesto l’iscrizione, puoi ignorare questo messaggio.',
|
'Se non hai richiesto l’iscrizione, puoi ignorare questo messaggio.',
|
||||||
|
'',
|
||||||
|
'Per disiscriverti:',
|
||||||
|
unsubscribeUrl,
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -102,6 +115,10 @@ export const POST: APIRoute = async ({ request, locals, url }) => {
|
|||||||
const unsubscribeToken = createToken();
|
const unsubscribeToken = createToken();
|
||||||
const origin = siteOrigin(url, runtimeEnv);
|
const origin = siteOrigin(url, runtimeEnv);
|
||||||
const confirmUrl = absoluteUrl(origin, `/api/newsletter/confirm?token=${confirmToken}`);
|
const confirmUrl = absoluteUrl(origin, `/api/newsletter/confirm?token=${confirmToken}`);
|
||||||
|
const unsubscribeUrl = absoluteUrl(
|
||||||
|
origin,
|
||||||
|
`/api/newsletter/unsubscribe?token=${unsubscribeToken}`,
|
||||||
|
);
|
||||||
|
|
||||||
if (mode !== 'live') {
|
if (mode !== 'live') {
|
||||||
console.info('[newsletter:dev] Subscription request', {
|
console.info('[newsletter:dev] Subscription request', {
|
||||||
@ -170,7 +187,7 @@ export const POST: APIRoute = async ({ request, locals, url }) => {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
const copy = confirmEmailCopy(locale, confirmUrl);
|
const copy = confirmEmailCopy(locale, confirmUrl, unsubscribeUrl);
|
||||||
try {
|
try {
|
||||||
await sendCloudflareEmail(emailBinding, {
|
await sendCloudflareEmail(emailBinding, {
|
||||||
fromEmail,
|
fromEmail,
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
---
|
---
|
||||||
import SubpageLayout from '../../layouts/SubpageLayout.astro';
|
import SubpageLayout from '../../layouts/SubpageLayout.astro';
|
||||||
|
|
||||||
|
const unsubToken = Astro.url.searchParams.get('unsub')?.trim() ?? '';
|
||||||
|
const unsubHref = unsubToken
|
||||||
|
? `/api/newsletter/unsubscribe?token=${encodeURIComponent(unsubToken)}`
|
||||||
|
: '';
|
||||||
---
|
---
|
||||||
|
|
||||||
<SubpageLayout
|
<SubpageLayout
|
||||||
@ -10,8 +15,19 @@ import SubpageLayout from '../../layouts/SubpageLayout.astro';
|
|||||||
>
|
>
|
||||||
<p>
|
<p>
|
||||||
Puoi disiscriverti in qualsiasi momento dal link presente in fondo a ogni
|
Puoi disiscriverti in qualsiasi momento dal link presente in fondo a ogni
|
||||||
messaggio.
|
messaggio della newsletter.
|
||||||
</p>
|
</p>
|
||||||
|
{
|
||||||
|
unsubHref ? (
|
||||||
|
<p>
|
||||||
|
Oppure disiscriviti subito:{' '}
|
||||||
|
<a class="text-sky-400/90 hover:text-sky-300" href={unsubHref}>
|
||||||
|
Annulla iscrizione
|
||||||
|
</a>
|
||||||
|
.
|
||||||
|
</p>
|
||||||
|
) : null
|
||||||
|
}
|
||||||
<p>
|
<p>
|
||||||
<a class="text-sky-400/90 hover:text-sky-300" href="/">Torna alla home</a>
|
<a class="text-sky-400/90 hover:text-sky-300" href="/">Torna alla home</a>
|
||||||
</p>
|
</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user