register redirects to settings
This commit is contained in:
parent
f68731a9b4
commit
0f83ca30be
2 changed files with 121 additions and 105 deletions
|
|
@ -12,7 +12,7 @@ services:
|
|||
- ./vite.config.ts:/app/vite.config.ts
|
||||
environment:
|
||||
- VITE_API_URL=http://host.docker.internal:8000
|
||||
- PUBLIC_TURNSTILE_SITE_KEY=key
|
||||
- PUBLIC_TURNSTILE_SITE_KEY=1x00000000000000000000AA
|
||||
#- VITE_API_URL=https://fooderapi.domandoman.xyz
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
|
|
|
|||
|
|
@ -1,54 +1,60 @@
|
|||
<script lang="ts">
|
||||
import { register } from '$lib/api/auth';
|
||||
import { goto } from '$app/navigation';
|
||||
import { today } from '$lib/utils/date';
|
||||
import { onMount } from 'svelte';
|
||||
import { PUBLIC_TURNSTILE_SITE_KEY } from '$env/static/public';
|
||||
import { register } from "$lib/api/auth";
|
||||
import { goto } from "$app/navigation";
|
||||
import { today } from "$lib/utils/date";
|
||||
import { onMount } from "svelte";
|
||||
import { PUBLIC_TURNSTILE_SITE_KEY } from "$env/static/public";
|
||||
|
||||
let username = $state('');
|
||||
let password = $state('');
|
||||
let confirm = $state('');
|
||||
let error = $state('');
|
||||
let username = $state("");
|
||||
let password = $state("");
|
||||
let confirm = $state("");
|
||||
let error = $state("");
|
||||
let loading = $state(false);
|
||||
let captchaToken = $state('');
|
||||
let captchaToken = $state("");
|
||||
let captchaContainer = $state<HTMLDivElement | null>(null);
|
||||
|
||||
onMount(() => {
|
||||
const script = document.createElement('script');
|
||||
script.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js';
|
||||
const script = document.createElement("script");
|
||||
script.src = "https://challenges.cloudflare.com/turnstile/v0/api.js";
|
||||
script.async = true;
|
||||
script.defer = true;
|
||||
script.onload = () => {
|
||||
if (captchaContainer) {
|
||||
(window as any).turnstile.render(captchaContainer, {
|
||||
sitekey: PUBLIC_TURNSTILE_SITE_KEY,
|
||||
callback: (token: string) => { captchaToken = token; },
|
||||
'expired-callback': () => { captchaToken = ''; },
|
||||
callback: (token: string) => {
|
||||
captchaToken = token;
|
||||
},
|
||||
"expired-callback": () => {
|
||||
captchaToken = "";
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
document.head.appendChild(script);
|
||||
return () => { document.head.removeChild(script); };
|
||||
return () => {
|
||||
document.head.removeChild(script);
|
||||
};
|
||||
});
|
||||
|
||||
async function handleSubmit(e: SubmitEvent) {
|
||||
e.preventDefault();
|
||||
error = '';
|
||||
error = "";
|
||||
if (password !== confirm) {
|
||||
error = 'Passwords do not match';
|
||||
error = "Passwords do not match";
|
||||
return;
|
||||
}
|
||||
if (!captchaToken) {
|
||||
error = 'Please complete the captcha';
|
||||
error = "Please complete the captcha";
|
||||
return;
|
||||
}
|
||||
loading = true;
|
||||
try {
|
||||
await register(username, password, captchaToken);
|
||||
goto(`/diary/${today()}`);
|
||||
goto(`/settings`);
|
||||
} catch (err: unknown) {
|
||||
const e2 = err as { detail?: { detail?: string } };
|
||||
error = e2.detail?.detail ?? 'Registration failed';
|
||||
error = e2.detail?.detail ?? "Registration failed";
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
|
|
@ -61,7 +67,10 @@
|
|||
|
||||
<form onsubmit={handleSubmit} class="space-y-4">
|
||||
<div>
|
||||
<label for="username" class="block text-sm font-medium text-zinc-400 mb-1">Username</label>
|
||||
<label
|
||||
for="username"
|
||||
class="block text-sm font-medium text-zinc-400 mb-1">Username</label
|
||||
>
|
||||
<input
|
||||
id="username"
|
||||
type="text"
|
||||
|
|
@ -73,7 +82,10 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<label for="password" class="block text-sm font-medium text-zinc-400 mb-1">Password</label>
|
||||
<label
|
||||
for="password"
|
||||
class="block text-sm font-medium text-zinc-400 mb-1">Password</label
|
||||
>
|
||||
<input
|
||||
id="password"
|
||||
type="password"
|
||||
|
|
@ -85,7 +97,11 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<label for="confirm" class="block text-sm font-medium text-zinc-400 mb-1">Confirm password</label>
|
||||
<label
|
||||
for="confirm"
|
||||
class="block text-sm font-medium text-zinc-400 mb-1"
|
||||
>Confirm password</label
|
||||
>
|
||||
<input
|
||||
id="confirm"
|
||||
type="password"
|
||||
|
|
@ -107,7 +123,7 @@
|
|||
disabled={loading || !captchaToken}
|
||||
class="w-full bg-green-600 hover:bg-green-500 disabled:opacity-50 rounded-xl py-3 font-semibold transition-colors"
|
||||
>
|
||||
{loading ? 'Creating account…' : 'Create account'}
|
||||
{loading ? "Creating account…" : "Create account"}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue