From b9ec7d394e88052e45072b3de8ba788e72a18009 Mon Sep 17 00:00:00 2001 From: Soham Sen Date: Fri, 29 Mar 2024 17:10:57 +0530 Subject: [PATCH] Add option to disable anonymous pastes --- .env.example | 1 + README.md | 2 + src/routes/(auth)/logout/+page.server.ts | 4 +- src/routes/+page.svelte | 77 +++++++++++++++--------- src/routes/api/paste/+server.ts | 12 ++++ 5 files changed, 65 insertions(+), 31 deletions(-) diff --git a/.env.example b/.env.example index 52936a9..bdb44a2 100644 --- a/.env.example +++ b/.env.example @@ -19,5 +19,6 @@ MAIL_FROM=YABin PUBLIC_REGISTRATION_ENABLED=true PUBLIC_CUSTOM_PATHS_ENABLED=true +PUBLIC_ANONYMOUS_PASTES_ENABLED=true PUBLIC_URL=http://localhost:5173 ORIGIN=http://localhost:5173 diff --git a/README.md b/README.md index 6fdc6d4..542149a 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ You can disable or enable public registration by modifying the `PUBLIC_REGISTRAT You can enable custom paste paths for everyone with the variable `PUBLIC_CUSTOM_PATHS_ENABLED`. If it is `false`, only users who are logged in can use custom paths. +You can disable anonymous pastes by setting `PUBLIC_ANONYMOUS_PASTES_ENABLED` to `false`. + By default, if no e-mail services are configured, all user accounts will be marked as validated. To enable e-mail validation, please configure the `MAIL_*` variables. #### Locally diff --git a/src/routes/(auth)/logout/+page.server.ts b/src/routes/(auth)/logout/+page.server.ts index 515cd0d..e1be2c3 100644 --- a/src/routes/(auth)/logout/+page.server.ts +++ b/src/routes/(auth)/logout/+page.server.ts @@ -2,13 +2,13 @@ import { redirect, type Actions } from '@sveltejs/kit'; import type { PageServerLoad } from './$types'; export const load: PageServerLoad = async ({ cookies }) => { - /* @migration task: add path argument */ cookies.delete('token'); + cookies.delete('token', { path: '/' }); redirect(303, '/'); }; export const actions: Actions = { default({ cookies }) { - cookies.delete('token'); + cookies.delete('token', { path: '/' }); redirect(303, '/'); }, }; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index e25b3e5..06b6897 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -14,6 +14,7 @@ import { env } from '$env/dynamic/public'; import type { PageData } from './$types'; import { DHMToSeconds, secondsToDHM } from '$lib/utils/time'; + import { PUBLIC_ANONYMOUS_PASTES_ENABLED } from '$env/static/public'; export let data: PageData; @@ -195,18 +196,22 @@ spellcheck="false" bind:value={content} bind:this={inputRef} + disabled={env.PUBLIC_ANONYMOUS_PASTES_ENABLED === 'false' && + !data.loggedIn} />

YABin

- + {#if PUBLIC_ANONYMOUS_PASTES_ENABLED === 'false' && !data.loggedIn} + + {:else} + + {/if}
-
- {#if data.loggedIn} - Dashboard -
- + {#if data.loggedIn} + Dashboard -
- {:else} - Login - {#if env.PUBLIC_REGISTRATION_ENABLED == 'true'} +
+ +
+ {:else} RegisterLogin + {#if env.PUBLIC_REGISTRATION_ENABLED == 'true'} + Register + {/if} {/if} - {/if} -
+
+ {/if}