dbgate/packages/web/src/LoginPage.svelte

123 lines
3.0 KiB
Svelte
Raw Normal View History

2022-11-25 12:36:18 +00:00
<script lang="ts">
import { onMount } from 'svelte';
2022-11-26 10:21:37 +00:00
import { internalRedirectTo } from './clientAuth';
2022-11-25 12:36:18 +00:00
import FormButton from './forms/FormButton.svelte';
import FormPasswordField from './forms/FormPasswordField.svelte';
import FormProvider from './forms/FormProvider.svelte';
import FormSubmit from './forms/FormSubmit.svelte';
import FormTextField from './forms/FormTextField.svelte';
2022-11-25 15:38:17 +00:00
import { apiCall, enableApi } from './utility/api';
2022-11-25 12:36:18 +00:00
2024-07-26 14:30:01 +00:00
export let isAdminPage;
2022-11-25 12:36:18 +00:00
onMount(() => {
const removed = document.getElementById('starting_dbgate_zero');
if (removed) removed.remove();
});
</script>
<div class="root theme-light theme-type-light">
<div class="text">DbGate</div>
<div class="wrap">
<div class="logo">
<img class="img" src="logo192.png" />
</div>
<div class="box">
<div class="heading">Log In</div>
<FormProvider>
2024-07-26 14:30:01 +00:00
{#if !isAdminPage}
<FormTextField label="Username" name="login" autocomplete="username" saveOnInput />
{/if}
2023-01-06 07:34:27 +00:00
<FormPasswordField label="Password" name="password" autocomplete="current-password" saveOnInput />
2022-11-25 12:36:18 +00:00
<div class="submit">
<FormSubmit
2024-07-26 14:30:01 +00:00
value={isAdminPage ? 'Log In as Administrator' : 'Log In'}
2022-11-26 10:21:37 +00:00
on:click={async e => {
2022-11-25 15:38:17 +00:00
enableApi();
2024-07-26 14:40:17 +00:00
const resp = await apiCall('auth/login', {
isAdminPage,
...e.detail,
});
2022-11-26 10:21:37 +00:00
if (resp.error) {
internalRedirectTo(`/?page=not-logged&error=${encodeURIComponent(resp.error)}`);
return;
}
const { accessToken } = resp;
if (accessToken) {
localStorage.setItem('accessToken', accessToken);
internalRedirectTo('/');
return;
}
internalRedirectTo(`/?page=not-logged`);
2022-11-25 12:36:18 +00:00
}}
/>
</div>
</FormProvider>
</div>
</div>
</div>
<style>
.logo {
display: flex;
margin-bottom: 1rem;
align-items: center;
justify-content: center;
}
.img {
width: 80px;
}
.text {
position: fixed;
top: 1rem;
left: 1rem;
2022-11-25 15:38:17 +00:00
font-size: 30pt;
font-family: monospace;
2022-11-25 12:36:18 +00:00
color: var(--theme-bg-2);
2022-11-25 15:38:17 +00:00
text-transform: uppercase;
2022-11-25 12:36:18 +00:00
}
.submit {
margin: var(--dim-large-form-margin);
display: flex;
}
.submit :global(input) {
flex: 1;
font-size: larger;
}
.root {
color: var(--theme-font-1);
display: flex;
justify-content: center;
background-color: var(--theme-bg-1);
align-items: baseline;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.box {
2022-11-25 15:38:17 +00:00
width: 600px;
max-width: 80vw;
/* max-width: 600px;
width: 40vw; */
2022-11-25 12:36:18 +00:00
border: 1px solid var(--theme-border);
border-radius: 4px;
background-color: var(--theme-bg-0);
}
.wrap {
margin-top: 20vh;
}
.heading {
text-align: center;
margin: 1em;
font-size: xx-large;
}
</style>