feat: enable registration toggle and update Navbar to reflect registration status

This commit is contained in:
2026-01-04 11:16:09 -05:00
parent f5de211611
commit 159fcc2a89
4 changed files with 21 additions and 6 deletions
@@ -3,6 +3,7 @@
import { resolve } from '$app/paths';
import { page } from '$app/state';
import { clearTokens } from '$lib/utils/auth';
import type { PageData } from '../../routes/$types';
function logout() {
clearTokens();
@@ -10,6 +11,10 @@
window.location.href = '/';
}
export let data: PageData;
console.log(data);
let currentPath = page.url.pathname;
let returnParam =
currentPath !== '/' && !currentPath.startsWith('/login') && !currentPath.startsWith('/register')
@@ -35,12 +40,18 @@
{:else}
<div class="ml-auto flex items-center space-x-4">
<a
href={resolve(`/login${returnParam}`)}
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Login</a
href={data.options?.registration_enabled ? resolve(`/login${returnParam}`) : '#'}
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800 {data.options
?.registration_enabled
? ''
: 'cursor-not-allowed bg-neutral-800 text-neutral-500!'}">Login</a
>
<a
href={resolve(`/register${returnParam}`)}
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Register</a
href={data.options?.registration_enabled ? resolve(`/register${returnParam}`) : '#'}
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800 {data.options
?.registration_enabled
? ''
: 'cursor-not-allowed bg-neutral-800 text-neutral-500!'}">Register</a
>
</div>
{/if}
+1 -1
View File
@@ -45,5 +45,5 @@
{/if}
</svelte:head>
<Navbar />
<Navbar {data} />
<slot />
@@ -23,6 +23,8 @@ namespace SharpbinV3.Server.Controllers
[Route("register")]
public async Task<IActionResult> Register([FromBody] RegisterRequest request)
{
if (!options.Value.Registration_Enabled)
return BadRequest(new { message = "Registration is disabled." });
if (!await _verification.VerifyAsync(request.Token, Utilities.GetRequestIP(HttpContext)))
return BadRequest(new { message = "Verification failed." });
@@ -106,7 +108,8 @@ namespace SharpbinV3.Server.Controllers
var authSettings = options.Value;
return Ok(new
{
cf_turnstile_site_key = string.IsNullOrEmpty(authSettings.CF_Turnstile_SiteKey) ? null : authSettings.CF_Turnstile_SiteKey
cf_turnstile_site_key = string.IsNullOrEmpty(authSettings.CF_Turnstile_SiteKey) ? null : authSettings.CF_Turnstile_SiteKey,
registration_enabled = authSettings.Registration_Enabled
});
}
@@ -4,5 +4,6 @@
{
public string CF_Turnstile_SiteKey { get; set; } = string.Empty;
public string CF_Turnstile_SecretKey { get; set; } = string.Empty;
public bool Registration_Enabled { get; set; } = true;
}
}