From e351ffdd2adf39c9ba11bbfcda7835da20acba5f Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Thu, 17 Nov 2022 13:53:22 +0700 Subject: fix: WIP use new api structure --- .../lib/api/account/models/CreateAccountPayload.ts | 4 - .../(main)/(public)/reset-password/+page.svelte | 51 +++++----- .../routes/(main)/(public)/sign-in/+page.svelte | 106 ++++++++++----------- 3 files changed, 81 insertions(+), 80 deletions(-) delete mode 100644 code/app/src/lib/api/account/models/CreateAccountPayload.ts (limited to 'code/app') diff --git a/code/app/src/lib/api/account/models/CreateAccountPayload.ts b/code/app/src/lib/api/account/models/CreateAccountPayload.ts deleted file mode 100644 index d116308..0000000 --- a/code/app/src/lib/api/account/models/CreateAccountPayload.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface CreateAccountPayload { - username: string, - password: string -} diff --git a/code/app/src/routes/(main)/(public)/reset-password/+page.svelte b/code/app/src/routes/(main)/(public)/reset-password/+page.svelte index 32d4e21..3bdba80 100644 --- a/code/app/src/routes/(main)/(public)/reset-password/+page.svelte +++ b/code/app/src/routes/(main)/(public)/reset-password/+page.svelte @@ -1,38 +1,48 @@ @@ -52,12 +62,7 @@
- + - import { goto } from "$app/navigation"; - import { login } from "$lib/api/account"; - import { Button, Checkbox, Input, Alert } from "$lib/components"; + import {goto} from "$app/navigation"; + import {http_account} from "$lib/api/account"; + import {Button, Checkbox, Input, Alert} from "$lib/components"; import LL from "$lib/i18n/i18n-svelte"; - import type { ErrorResult } from "$lib/models/internal/ErrorResult"; - import type { LoginPayload } from "$lib/api/account/models/LoginPayload"; import pwKey from "$actions/pwKey"; - import { onMount } from "svelte"; - import { messageQueryKey, signInPageTestKeys, type Message } from "."; + import {isOk} from "rustic"; + import {onMount} from "svelte"; + import {signInPageMessageQueryKey, signInPageTestKeys, type SignInPageMessage} from "."; let loading = false; - let messageType: Message | undefined = undefined; + let messageType: SignInPageMessage | undefined = undefined; const data = { username: "", @@ -26,25 +25,23 @@ onMount(() => { const searcher = new URLSearchParams(window.location.search); - if (searcher.get(messageQueryKey)) { - messageType = searcher.get(messageQueryKey) as Message; - searcher.delete(messageQueryKey); + if (searcher.get(signInPageMessageQueryKey)) { + messageType = searcher.get(signInPageMessageQueryKey) as SignInPageMessage; + searcher.delete(signInPageMessageQueryKey); history.replaceState(null, "", window.location.origin + window.location.pathname); } }); async function submitFormAsync() { - errorData = { text: "", title: "" }; + errorData = {text: "", title: ""}; loading = true; data.persist = !data.persist; - const loginResponse = await login(data); - console.log(loginResponse.data); - - if (loginResponse.ok) { + const loginResponse = await http_account.login_async(data); + if (isOk(loginResponse)) { await goto("/home"); } else { errorData.title = loginResponse.data.title; - errorData.text = loginResponse.data.text; + errorData.text = loginResponse.data.subtitle; if (!errorData.text && !errorData.title) { errorData.text = $LL.tryAgainSoon(); errorData.title = $LL.unexpectedError(); @@ -59,24 +56,24 @@
{#if messageType === "after-password-reset"} {:else if messageType === "user-disabled"} {:else if messageType === "user-inactivity"} {/if}
@@ -87,43 +84,46 @@

{$LL.or().toLowerCase()} - {$LL.createANewAccount().toLowerCase()} + {$LL.createANewAccount().toLowerCase()}

{#if showErrorAlert} - + {/if} - + -
-- cgit v1.3