diff options
| author | Adam Soltys <[email protected]> | 2024-11-26 20:54:49 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2024-11-26 20:54:49 -0800 |
| commit | 872aa0b3b0b9a847b8afcdee7f1ad53c524ce4f0 (patch) | |
| tree | 4d505c5b7c3f137b56c84cfaca12ed486aa4972c /src/routes/(static) | |
| parent | f9300236a3c0227e0eec58326fa322e58613bc2d (diff) | |
| download | coinos-ui-872aa0b3b0b9a847b8afcdee7f1ad53c524ce4f0.tar.gz coinos-ui-872aa0b3b0b9a847b8afcdee7f1ad53c524ce4f0.zip | |
warnings
Diffstat (limited to 'src/routes/(static)')
| -rw-r--r-- | src/routes/(static)/register/+page.server.ts | 13 | ||||
| -rw-r--r-- | src/routes/(static)/register/+page.svelte | 86 |
2 files changed, 50 insertions, 49 deletions
diff --git a/src/routes/(static)/register/+page.server.ts b/src/routes/(static)/register/+page.server.ts index 2dffef01..1781602f 100644 --- a/src/routes/(static)/register/+page.server.ts +++ b/src/routes/(static)/register/+page.server.ts @@ -1,5 +1,5 @@ +import { fd, login, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; -import { fd, post, login } from "$lib/utils"; export const load = async ({ parent }) => { const { user } = await parent(); @@ -24,18 +24,19 @@ export const actions = { try { await post("/register", { user }, { "cf-connecting-ip": ip }); - } catch (e: any) { - error = e.message; + } catch (e) { + ({ message: error } = e as Error); } try { await login(user, cookies, ip); error = null; - } catch (e: any) { - error ||= e.message; + } catch (e) { + const { message } = e as Error; + error ||= message; } if (error) return fail(400, { error }); - redirect(307, loginRedirect || `/${user.username}`); + redirect(303, loginRedirect || `/${user.username}`); }, }; diff --git a/src/routes/(static)/register/+page.svelte b/src/routes/(static)/register/+page.svelte index c179552c..8a2a5015 100644 --- a/src/routes/(static)/register/+page.svelte +++ b/src/routes/(static)/register/+page.svelte @@ -1,6 +1,4 @@ <script> - import { run, preventDefault } from 'svelte/legacy'; - import punks from "$lib/punks"; import { upload } from "$lib/upload"; import { afterNavigate, invalidateAll } from "$app/navigation"; @@ -40,7 +38,8 @@ } }; - let refresh = async () => { + let refresh = async (e) => { + e.preventDefault(); username = uniqueNamesGenerator({ dictionaries: [animals, NumberDictionary.generate({ min: 10, max: 99 })], length: 2, @@ -64,27 +63,27 @@ } }); - let token = $state(), formElement; + let token = $state(), + formElement; let code = []; let redirect; let cancel = () => (need2fa = false); - let email, btn = $state(); - - let update = (form) => form && ({ username, password: $password } = form); - + let email, + btn = $state(); let revealPassword = $state(); let loading = $state(); async function handleSubmit(e) { + e.preventDefault(); + loading = true; let data = new FormData(this); let user = Object.fromEntries(data); - console.log("USER", JSON.stringify(user)); await generate(user); for (let k in user) { @@ -144,26 +143,17 @@ reader.readAsDataURL(file); }; - run(() => { - data && ($avatar = undefined); - }); - let need2fa; - run(() => { - need2fa = form?.message === "2fa"; - }); - run(() => { - if (form?.message === "2fa" && form.token === token) token = ""; - }); - run(() => { - update(form); + + let need2fa = $derived(form?.message === "2fa"); + let src = $derived(`/api/public/${punks[index]}.webp`); + + $effect(() => { + if (need2fa && form.token === token) token = ""; }); - run(() => { + + $effect(() => { token && token?.length === 6 && tick().then(() => btn.click()); }); - let src; - run(() => { - src = `/api/public/${punks[index]}.webp`; - }); </script> {#if need2fa} @@ -185,11 +175,12 @@ <button class="absolute w-8 h-12 left-12 bg-base-100 rounded top-12" onclick={decr} + aria-label="Previous" > <iconify-icon icon="ph:caret-left-bold" width="32"></iconify-icon> </button> - <div class="block relative w-32 mx-auto" onclick={selectAvatar}> - <button + <button class="block relative w-32 mx-auto" onclick={selectAvatar}> + <div class="w-32 h-32 rounded-full border-4 border-white overflow-hidden flex mx-auto relative" > <img @@ -197,16 +188,17 @@ class="w-full h-full object-cover object-center overflow-hidden" alt={username} /> - </button> - <button + </div> + <div class="absolute bg-base-100 rounded-full p-2 mx-auto right-0 bottom-0 z-10 w-12" > <iconify-icon icon="ph:upload-simple-bold" width="24"></iconify-icon> - </button> - </div> + </div> + </button> <button class="absolute w-8 h-12 right-12 bg-base-100 rounded top-12" onclick={incr} + aria-label="Next" > <iconify-icon icon="ph:caret-right-bold" width="32"></iconify-icon> </button> @@ -218,7 +210,7 @@ </div> {/if} - <form class="space-y-5" onsubmit={preventDefault(handleSubmit)} method="POST"> + <form class="space-y-5" onsubmit={handleSubmit} method="POST"> <input type="hidden" name="loginRedirect" @@ -241,13 +233,16 @@ autocapitalize="none" placeholder={$t("login.username")} /> - <iconify-icon - class="cursor-pointer" + <button + type="button" tabindex="-1" onclick={refresh} - icon="ph:dice-three-bold" - width="32" -></iconify-icon> + aria-label="Randomize" + class="contents" + > + <iconify-icon icon="ph:dice-three-bold" width="32" + ></iconify-icon></button + > </label> <label @@ -276,13 +271,18 @@ placeholder={$t("login.password")} /> {/if} - <iconify-icon + <button + type="button" tabindex="-1" - class="cursor-pointer" onclick={() => (revealPassword = !revealPassword)} - icon={revealPassword ? "ph:eye-bold" : "ph:eye-slash-bold"} - width="32" -></iconify-icon> + class="contents" + aria-label="Toggle" + > + <iconify-icon + icon={revealPassword ? "ph:eye-bold" : "ph:eye-slash-bold"} + width="32" + ></iconify-icon></button + > </label> <button type="submit" class="btn" disabled={loading} bind:this={btn}> |
