mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: enable registration toggle and update Navbar to reflect registration status
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import { resolve } from '$app/paths';
|
import { resolve } from '$app/paths';
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
import { clearTokens } from '$lib/utils/auth';
|
import { clearTokens } from '$lib/utils/auth';
|
||||||
|
import type { PageData } from '../../routes/$types';
|
||||||
|
|
||||||
function logout() {
|
function logout() {
|
||||||
clearTokens();
|
clearTokens();
|
||||||
@@ -10,6 +11,10 @@
|
|||||||
window.location.href = '/';
|
window.location.href = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let data: PageData;
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
let currentPath = page.url.pathname;
|
let currentPath = page.url.pathname;
|
||||||
let returnParam =
|
let returnParam =
|
||||||
currentPath !== '/' && !currentPath.startsWith('/login') && !currentPath.startsWith('/register')
|
currentPath !== '/' && !currentPath.startsWith('/login') && !currentPath.startsWith('/register')
|
||||||
@@ -35,12 +40,18 @@
|
|||||||
{:else}
|
{:else}
|
||||||
<div class="ml-auto flex items-center space-x-4">
|
<div class="ml-auto flex items-center space-x-4">
|
||||||
<a
|
<a
|
||||||
href={resolve(`/login${returnParam}`)}
|
href={data.options?.registration_enabled ? resolve(`/login${returnParam}`) : '#'}
|
||||||
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Login</a
|
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
|
<a
|
||||||
href={resolve(`/register${returnParam}`)}
|
href={data.options?.registration_enabled ? resolve(`/register${returnParam}`) : '#'}
|
||||||
class="rounded bg-neutral-700 px-3 py-1 text-white hover:bg-neutral-800">Register</a
|
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>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
@@ -45,5 +45,5 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</svelte:head>
|
</svelte:head>
|
||||||
|
|
||||||
<Navbar />
|
<Navbar {data} />
|
||||||
<slot />
|
<slot />
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
[Route("register")]
|
[Route("register")]
|
||||||
public async Task<IActionResult> Register([FromBody] RegisterRequest request)
|
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)))
|
if (!await _verification.VerifyAsync(request.Token, Utilities.GetRequestIP(HttpContext)))
|
||||||
return BadRequest(new { message = "Verification failed." });
|
return BadRequest(new { message = "Verification failed." });
|
||||||
|
|
||||||
@@ -106,7 +108,8 @@ namespace SharpbinV3.Server.Controllers
|
|||||||
var authSettings = options.Value;
|
var authSettings = options.Value;
|
||||||
return Ok(new
|
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_SiteKey { get; set; } = string.Empty;
|
||||||
public string CF_Turnstile_SecretKey { get; set; } = string.Empty;
|
public string CF_Turnstile_SecretKey { get; set; } = string.Empty;
|
||||||
|
public bool Registration_Enabled { get; set; } = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user