linkylinky-dashboard/src/routes/login.svelte

69 lines
2.1 KiB
Svelte
Raw Normal View History

2021-08-18 14:39:44 +00:00
<script>
2021-08-18 14:50:46 +00:00
import Apiclient from '$lib/Apiclient';
2021-08-18 14:39:44 +00:00
import UserStore from '$lib/UserStore';
2021-08-18 14:50:46 +00:00
$: username = "";
$: password = "";
2021-08-18 15:11:20 +00:00
$: error = "";
2021-08-18 14:50:46 +00:00
async function login() {
2021-08-18 15:28:53 +00:00
try {
const login = await Apiclient.login(username, password);
2021-08-18 14:50:46 +00:00
UserStore.login(login);
2021-08-21 07:22:01 +00:00
location.replace("./");
2021-08-18 15:28:53 +00:00
} catch (error) {
2021-08-18 14:50:46 +00:00
}
}
2021-08-21 18:04:47 +00:00
function handleKeydown(e) {
if (e.keyCode === 13) {
login();
}
}
2021-08-18 14:39:44 +00:00
</script>
<div class="w-full max-w-sm mx-auto overflow-hidden bg-white rounded-lg shadow-md dark:bg-gray-800">
<div class="px-6 py-4">
<h2 class="text-3xl font-bold text-center text-gray-700 dark:text-white">LinkyLinky</h2>
<h3 class="mt-1 text-xl font-medium text-center text-gray-600 dark:text-gray-200">
Welcome Back
</h3>
<p class="mt-1 text-center text-gray-500 dark:text-gray-400">Please login</p>
<div class="w-full mt-4">
<input
2021-08-21 18:04:47 +00:00
class="block w-full px-4 py-2 mt-2 text-gray-700 dark:text-gray-200 placeholder-gray-500 bg-white border border-gray-300 rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-blue-500 dark:focus:border-blue-500 focus:outline-none focus:ring"
2021-08-18 14:39:44 +00:00
type="text"
placeholder="Username"
aria-label="Username"
2021-08-18 15:11:20 +00:00
bind:value={username}
2021-08-21 18:04:47 +00:00
on:keydown={handleKeydown}
2021-08-18 14:39:44 +00:00
/>
</div>
<div class="w-full mt-4">
<input
2021-08-21 18:04:47 +00:00
class="block w-full px-4 py-2 mt-2 text-gray-700 dark:text-gray-200 placeholder-gray-500 bg-white border border-gray-300 rounded-md dark:bg-gray-800 dark:border-gray-600 dark:placeholder-gray-400 focus:border-blue-500 dark:focus:border-blue-500 focus:outline-none focus:ring"
2021-08-18 14:39:44 +00:00
type="password"
placeholder="Password"
aria-label="Password"
2021-08-18 15:11:20 +00:00
bind:value={password}
2021-08-21 18:04:47 +00:00
on:keydown={handleKeydown}
2021-08-18 14:39:44 +00:00
/>
</div>
<div class="flex items-center justify-between mt-4">
2021-08-18 14:50:46 +00:00
<button on:click={login}
2021-08-18 14:39:44 +00:00
class="px-4 py-2 leading-5 text-white transition-colors duration-200 transform bg-gray-700 rounded hover:bg-gray-600 focus:outline-none"
type="button"
>
Login
</button>
</div>
</div>
</div>