From a2e6eb2af471efe3d00cc17453c345cfa68e4b53 Mon Sep 17 00:00:00 2001 From: dusk Date: Sat, 9 Nov 2024 22:38:02 +0300 Subject: [PATCH] feat: add anonymous checkbox to redact author on guestbook --- src/routes/guestbook/+page.server.ts | 8 +++++--- src/routes/guestbook/+page.svelte | 6 +++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/routes/guestbook/+page.server.ts b/src/routes/guestbook/+page.server.ts index 5efce40..d69c9fb 100644 --- a/src/routes/guestbook/+page.server.ts +++ b/src/routes/guestbook/+page.server.ts @@ -21,12 +21,13 @@ const postAction = (client: any, scopes: string[]) => { scopedCookies.set("postAuth", client.name) const form = await request.formData() const content = form.get("content")?.toString().substring(0, 512) + const anon = !(form.get("anon") === null) if (content === undefined) { scopedCookies.set("sendError", "content field is missing") redirect(303, auth.callbackUrl) } // save form content in a cookie - const params = new URLSearchParams({ content }) + const params = new URLSearchParams({ content, anon: anon ? "1" : "" }) scopedCookies.set("postData", params.toString()) // get auth url to redirect user to const authUrl = auth.createAuthUrl((state) => client.getAuthUrl(state, scopes), cookies) @@ -80,8 +81,9 @@ export async function load({ url, fetch, cookies }) { let respRaw: Response try { const postData = new URLSearchParams(rawPostData) - // set author to the identified value we got - postData.set('author', author) + const anon = (postData.get('anon') ?? "1").length > 0 + // set author to the identified value we got if not anonymous + postData.set('author', anon ? "[REDACTED]" : author) // return error if content was not set or if empty const content = postData.get('content') if (content === null || content.trim().length === 0) { diff --git a/src/routes/guestbook/+page.svelte b/src/routes/guestbook/+page.svelte index f403150..e79e057 100644 --- a/src/routes/guestbook/+page.svelte +++ b/src/routes/guestbook/+page.svelte @@ -36,7 +36,11 @@ maxlength="512" required /> -

--- posted by ...

+
+ + +

--- posted by ...

+

auth via: