diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-10-01 10:44:31 +0200 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-10-01 10:44:31 +0200 |
| commit | 7a5ba5ea4aec0704070cfe8d63ba504a07d88cc6 (patch) | |
| tree | 683a6a121e02b4413774dcc36522c5d3817c9867 /apps/kit/src/routes/(main)/(public)/sign-in | |
| parent | 33b5c5a72974af5bd8745298772fe7cc71b87b76 (diff) | |
| download | greatoffice-7a5ba5ea4aec0704070cfe8d63ba504a07d88cc6.tar.xz greatoffice-7a5ba5ea4aec0704070cfe8d63ba504a07d88cc6.zip | |
feat: Functionality complete public sites
Diffstat (limited to 'apps/kit/src/routes/(main)/(public)/sign-in')
| -rw-r--r-- | apps/kit/src/routes/(main)/(public)/sign-in/+page.svelte | 79 |
1 files changed, 60 insertions, 19 deletions
diff --git a/apps/kit/src/routes/(main)/(public)/sign-in/+page.svelte b/apps/kit/src/routes/(main)/(public)/sign-in/+page.svelte index c431e0d..07ed0e0 100644 --- a/apps/kit/src/routes/(main)/(public)/sign-in/+page.svelte +++ b/apps/kit/src/routes/(main)/(public)/sign-in/+page.svelte @@ -1,25 +1,28 @@ <script context="module" lang="ts"> - export type Message = - | "after-password-reset" - | "user-inactivity" - | "user-disabled"; + export enum Message { + AFTER_PASSWORD_RESET = "after-password-reset", + USER_INACTIVITY = "user-inactivity", + USER_DISABLED = "user-disabled", + } + export const messageQueryKey = "m"; </script> <script lang="ts"> import { goto } from "$app/navigation"; import { login } from "$lib/api/user"; - import Button from "$lib/components/button.svelte"; - import Checkbox from "$lib/components/checkbox.svelte"; - import Input from "$lib/components/input.svelte"; + import { Button, Checkbox, Input, Alert } from "$lib/components"; import LL from "$lib/i18n/i18n-svelte"; import type { ErrorResult } from "$lib/models/ErrorResult"; import type { LoginPayload } from "$lib/models/LoginPayload"; + import { onMount } from "svelte"; let loading = false; + let messageType: Message | undefined = undefined; const data = { username: "", password: "", + persist: true, } as LoginPayload; let error = { @@ -27,9 +30,23 @@ title: "", } as ErrorResult; + onMount(() => { + const searcher = new URLSearchParams(window.location.search); + if (searcher.get(messageQueryKey)) { + messageType = searcher.get(messageQueryKey) as Message; + searcher.delete(messageQueryKey); + history.replaceState( + null, + "", + window.location.origin + window.location.pathname + ); + } + }); + async function submitFormAsync() { error = { text: "", title: "" }; loading = true; + data.persist = !data.persist; const loginResponse = await login(data); if (loginResponse.ok) { await goto("/home"); @@ -42,15 +59,38 @@ </script> <div class="min-h-full flex flex-col justify-center py-12 sm:px-6 lg:px-8"> - <div class="sm:mx-auto sm:w-full sm:max-w-md"> - <h2 - class="mt-6 text-center text-3xl tracking-tight font-bold text-gray-900" - > - {$LL.signIn()} + {#if messageType} + <div class="sm:max-w-md sm:mx-auto sm:w-full"> + {#if messageType === "after-password-reset"} + <Alert + title={$LL.signInPage.yourNewPasswordIsApplied()} + message={$LL.signInPage.signInBelow()} + closeable + /> + {:else if messageType === "user-disabled"} + <Alert + title={$LL.signInPage.yourAccountIsDisabled()} + message={$LL.signInPage.contactYourAdminIfDisabled()} + closeable + /> + {:else if messageType === "user-inactivity"} + <Alert + title={$LL.signInPage.youHaveReachedInactivityLimit()} + message={$LL.signInPage.feelFreeToSignInAgain()} + closeable + /> + {/if} + </div> + {/if} + <div class="sm:mx-auto sm:w-full p-2 sm:p-0 sm:max-w-md"> + <h2 class="mt-6 text-3xl tracking-tight font-bold text-gray-900"> + {$LL.signInPage.signIn()} </h2> - <p class="mt-2 text-center text-sm text-gray-600"> + <p class="mt-2 text-sm text-gray-600"> {$LL.or().toLowerCase()} - <a href="/sign-up" class="link">{$LL.createANewAccount()}</a> + <a href="/sign-up" class="link" + >{$LL.createANewAccount().toLowerCase()}</a + > </p> </div> <div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md"> @@ -76,7 +116,7 @@ type="email" label={$LL.emailAddress()} required - value={data.username} + bind:value={data.username} /> <Input @@ -86,23 +126,24 @@ label={$LL.password()} autocomplete="current-password" required - value={data.password} + bind:value={data.password} /> <div class="flex items-center justify-between"> <Checkbox id="remember-me" name="remember-me" - label={$LL.notMyComputer()} + bind:checked={data.persist} + label={$LL.signInPage.notMyComputer()} /> <div class="text-sm"> <a href="/reset-password" class="link"> - {$LL.resetPassword()} + {$LL.signInPage.resetPassword()} </a> </div> </div> - <Button text={$LL.signIn()} fullWidth type="submit" {loading} /> + <Button text={$LL.submit()} fullWidth type="submit" {loading} /> </form> </div> </div> |
