mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: add registration status check and disable form elements when registration is disabled
This commit is contained in:
@@ -28,7 +28,11 @@
|
|||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const render = () => {
|
const render = () => {
|
||||||
if (window.turnstile && data.options?.cf_turnstile_site_key) {
|
if (
|
||||||
|
window.turnstile &&
|
||||||
|
data.options?.cf_turnstile_site_key &&
|
||||||
|
data.options?.registration_enabled
|
||||||
|
) {
|
||||||
window.turnstile.render('.cf-turnstile', {
|
window.turnstile.render('.cf-turnstile', {
|
||||||
sitekey: data.options.cf_turnstile_site_key,
|
sitekey: data.options.cf_turnstile_site_key,
|
||||||
theme: 'dark'
|
theme: 'dark'
|
||||||
@@ -103,6 +107,13 @@
|
|||||||
>
|
>
|
||||||
<div class="w-full max-w-md rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
<div class="w-full max-w-md rounded border-2 border-neutral-800 bg-neutral-900 p-6">
|
||||||
<h1 class="mb-6 text-center text-3xl font-bold">Register</h1>
|
<h1 class="mb-6 text-center text-3xl font-bold">Register</h1>
|
||||||
|
{#if data.options?.registration_enabled === false}
|
||||||
|
<div
|
||||||
|
class="mb-4 rounded border border-yellow-600/80 bg-yellow-600/40 p-2 text-sm text-yellow-200"
|
||||||
|
>
|
||||||
|
Registration is currently disabled.
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
<form on:submit|preventDefault={register} class="space-y-4">
|
<form on:submit|preventDefault={register} class="space-y-4">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
@@ -110,6 +121,7 @@
|
|||||||
bind:value={username}
|
bind:value={username}
|
||||||
autocomplete="username"
|
autocomplete="username"
|
||||||
required
|
required
|
||||||
|
disabled={loading || !data.options?.registration_enabled}
|
||||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||||
/>
|
/>
|
||||||
<div>
|
<div>
|
||||||
@@ -118,6 +130,7 @@
|
|||||||
placeholder="Email (optional)"
|
placeholder="Email (optional)"
|
||||||
bind:value={email}
|
bind:value={email}
|
||||||
autocomplete="email"
|
autocomplete="email"
|
||||||
|
disabled={loading || !data.options?.registration_enabled}
|
||||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -127,6 +140,7 @@
|
|||||||
placeholder="Display Name (optional)"
|
placeholder="Display Name (optional)"
|
||||||
bind:value={displayName}
|
bind:value={displayName}
|
||||||
autocomplete="name"
|
autocomplete="name"
|
||||||
|
disabled={loading || !data.options?.registration_enabled}
|
||||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -138,9 +152,10 @@
|
|||||||
on:focus={() => (passwordFocused = true)}
|
on:focus={() => (passwordFocused = true)}
|
||||||
on:blur={() => (passwordFocused = false)}
|
on:blur={() => (passwordFocused = false)}
|
||||||
autocomplete="new-password"
|
autocomplete="new-password"
|
||||||
|
disabled={loading || !data.options?.registration_enabled}
|
||||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||||
/>
|
/>
|
||||||
{#if passwordFocused}
|
{#if passwordFocused && !data.options?.registration_enabled}
|
||||||
<ul
|
<ul
|
||||||
transition:slide
|
transition:slide
|
||||||
class="space-y-2 rounded border border-neutral-700 bg-neutral-800 p-3 text-sm"
|
class="space-y-2 rounded border border-neutral-700 bg-neutral-800 p-3 text-sm"
|
||||||
@@ -201,6 +216,7 @@
|
|||||||
bind:value={confirmPassword}
|
bind:value={confirmPassword}
|
||||||
required
|
required
|
||||||
autocomplete="new-password"
|
autocomplete="new-password"
|
||||||
|
disabled={loading || !data.options?.registration_enabled}
|
||||||
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
class="focus:bg-neutral-750 w-full rounded border border-neutral-700 bg-neutral-800 p-2 placeholder-neutral-500 transition-colors duration-200 focus:border-neutral-600"
|
||||||
/>
|
/>
|
||||||
{#if confirmPassword && password !== confirmPassword}
|
{#if confirmPassword && password !== confirmPassword}
|
||||||
@@ -211,15 +227,18 @@
|
|||||||
Passwords do not match.
|
Passwords do not match.
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if data.options?.cf_turnstile_site_key}
|
{#if data.options?.cf_turnstile_site_key && data.options?.registration_enabled}
|
||||||
<div class="flex w-full justify-center">
|
<div class="flex w-full justify-center">
|
||||||
<div class="cf-turnstile"></div>
|
<div class="cf-turnstile"></div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
disabled={!passwordValid || password !== confirmPassword || loading}
|
disabled={!passwordValid ||
|
||||||
class="w-full cursor-pointer rounded bg-neutral-700 px-4 py-2 font-semibold text-white transition-colors duration-200 hover:bg-neutral-800 active:bg-neutral-900 disabled:cursor-not-allowed disabled:bg-neutral-800 disabled:text-neutral-500"
|
password !== confirmPassword ||
|
||||||
|
loading ||
|
||||||
|
!data.options?.registration_enabled}
|
||||||
|
class="w-full cursor-pointer rounded bg-neutral-700 px-4 py-2 font-semibold text-white transition-colors duration-200 hover:bg-neutral-800 active:bg-neutral-900"
|
||||||
>
|
>
|
||||||
{loading ? 'Registering...' : 'Register'}
|
{loading ? 'Registering...' : 'Register'}
|
||||||
</button>
|
</button>
|
||||||
@@ -237,3 +256,15 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
*:disabled {
|
||||||
|
cursor: not-allowed;
|
||||||
|
background-color: var(--color-neutral-800);
|
||||||
|
color: var(--color-neutral-600) !important;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
*:disabled::placeholder {
|
||||||
|
color: var(--color-neutral-600) !important;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
Reference in New Issue
Block a user