diff options
| author | secondl1ght <[email protected]> | 2022-07-27 00:04:37 -0600 |
|---|---|---|
| committer | secondl1ght <[email protected]> | 2022-07-27 00:04:37 -0600 |
| commit | 1387dc5e4e69682749446f2e9b8717f96947328c (patch) | |
| tree | 5bd966261283f7cffd3926609b1174c74be8c8b6 /src/components | |
| parent | 80cf7e9b77dcc4cbcf7711eb63a218c3aec07ec6 (diff) | |
| parent | 059613490db9be904791686c49851ec1cc095774 (diff) | |
| download | coinos-ui-1387dc5e4e69682749446f2e9b8717f96947328c.tar.gz coinos-ui-1387dc5e4e69682749446f2e9b8717f96947328c.zip | |
Merge branch 'master' of github.com:coinos/coinos-ui-v2
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/RegisterOrLogin.svelte | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/src/components/RegisterOrLogin.svelte b/src/components/RegisterOrLogin.svelte index 77c1d76f..12d7b8b7 100644 --- a/src/components/RegisterOrLogin.svelte +++ b/src/components/RegisterOrLogin.svelte @@ -1,9 +1,28 @@ <script> import { Icon } from '$comp'; + import { post } from '$lib/utils'; + import { token } from '$lib/store'; + import { auth } from '$lib/socket'; + import { goto } from '$app/navigation'; export let page; + let username, password; + let revealPassword = false; + + let url = { + Register: '/register', + 'Sign in': '/login' + }[page]; + + let submit = async () => { + let r = await post(url, { username, password }); + if (!r.token) r = await post('/login', { username, password }); + $token = r.token; + auth(); + goto('/receive'); + }; </script> <div class="pt-10"> @@ -15,19 +34,34 @@ <div class="shadow-xl rounded-3xl p-10 pb-12 space-y-5 w-full mx-5 md:mx-0 md:w-[400px]"> <h1 class="text-2xl font-bold text-center">{page}</h1> - <form class="space-y-5"> + <form class="space-y-5" on:submit|preventDefault={submit}> <div> <label for="username" class="font-semibold">Username</label> - <input type="text" required class="bg-primary p-4 rounded-2xl w-full" /> + <input + type="text" + required + class="bg-primary p-4 rounded-2xl w-full" + bind:value={username} + /> </div> <div class="relative"> <label for="password" class="block font-semibold">Password</label> - <input - type={revealPassword ? 'text' : 'password'} - required - class="block bg-primary p-4 rounded-2xl w-full" - /> + {#if revealPassword} + <input + type="text" + required + class="block bg-primary p-4 rounded-2xl w-full" + bind:value={password} + /> + {:else} + <input + type="password" + required + class="block bg-primary p-4 rounded-2xl w-full" + bind:value={password} + /> + {/if} <button type="button" on:click={() => (revealPassword = !revealPassword)} |
