aboutsummaryrefslogtreecommitdiffstats
path: root/code/app/src/routes/(main)/(public)/reset-password
diff options
context:
space:
mode:
Diffstat (limited to 'code/app/src/routes/(main)/(public)/reset-password')
-rw-r--r--code/app/src/routes/(main)/(public)/reset-password/+page.svelte26
-rw-r--r--code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte30
2 files changed, 28 insertions, 28 deletions
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 4d0288f..8bda3dc 100644
--- a/code/app/src/routes/(main)/(public)/reset-password/+page.svelte
+++ b/code/app/src/routes/(main)/(public)/reset-password/+page.svelte
@@ -1,13 +1,12 @@
<script lang="ts">
import { Alert, Input, Button } from "$lib/components";
- import X from "$lib/components/icons/x.svelte";
import LL from "$lib/i18n/i18n-svelte";
import { PasswordResetService } from "$lib/services/password-reset-service";
const formData = {
email: {
value: "",
- error: "",
+ errors: [],
},
};
@@ -20,27 +19,31 @@
},
};
- const service = new PasswordResetService();
+ const resetRequests = new PasswordResetService();
let loading = false;
let showSuccessAlert = false;
- $: showErrorAlert = formError.title || (formError.subtitle && !showSuccessAlert);
+ $: showErrorAlert = (formError.title !== "" || formError.subtitle !== "") && !showSuccessAlert;
async function submitFormAsync() {
formError.set();
showSuccessAlert = false;
loading = true;
- const response = await service.create_request_async(formData.email.value);
+ const response = await resetRequests.create_request_async(formData.email.value);
loading = false;
if (response.isCreated) {
showSuccessAlert = true;
- return;
- }
- if (response.knownProblem) {
+ } else if (response.knownProblem) {
if (response.knownProblem.title) formError.title = response.knownProblem.title;
if (response.knownProblem.subtitle) formError.subtitle = response.knownProblem.subtitle;
- for (const error of response.knownProblem.errors) {
+ for (const error of Object.entries(response.knownProblem.errors)) {
+ if (error[0] === "email") {
+ error[1].forEach(formData.email.errors.push);
+ }
}
+ } else {
+ formError.title = $LL.unexpectedError();
+ formError.subtitle = $LL.tryAgainSoon();
}
}
</script>
@@ -61,7 +64,7 @@
<div class="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
<div class="bg-white py-8 px-4 shadow sm:rounded-lg sm:px-10">
<form class="space-y-6" on:submit|preventDefault={submitFormAsync}>
- <Alert title={errorData.title} message={errorData.text} type="error" visible={showErrorAlert} />
+ <Alert title={formError.title} message={formError.subtitle} type="error" visible={showErrorAlert} />
<Alert
type="success"
@@ -75,8 +78,9 @@
name="email"
type="email"
autocomplete="email"
+ errors={formData.email.errors}
required
- bind:value={formData.email}
+ bind:value={formData.email.value}
label={$LL.emailAddress()}
/>
<Button text={$LL.submit()} type="submit" {loading} fullWidth />
diff --git a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte
index 3710290..2026764 100644
--- a/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte
+++ b/code/app/src/routes/(main)/(public)/reset-password/[id]/+page.svelte
@@ -1,26 +1,22 @@
<script lang="ts">
- import { check_forgot_password_request, fulfill_forgot_password_request } from "$lib/api/account";
import { onMount } from "svelte";
import LL from "$lib/i18n/i18n-svelte";
import { Alert, Input, Button } from "$lib/components";
import type { PageServerData } from "./$types";
- import type { ErrorResult } from "$lib/models/internal/ErrorResult";
import { goto } from "$app/navigation";
- import { Message, messageQueryKey } from "$routes/(main)/(public)/sign-in";
+ import { SignInPageMessage, signInPageMessageQueryKey } from "$routes/(main)/(public)/sign-in";
+ import { PasswordResetService } from "$lib/services/password-reset-service";
export let data: PageServerData;
-
+ const service = new PasswordResetService();
const formData = {
- newPassword: "",
+ newPassword: {
+ value: "",
+ errors: [],
+ },
};
- const errorData = {
- text: "",
- title: "",
- } as ErrorResult;
-
let errorState: undefined | "expired" | "404" | "unknown";
-
let finishedPreliminaryLoading = false;
let loading = false;
let canSubmit = true;
@@ -28,18 +24,18 @@
async function submitFormAsync() {
if (!canSubmit) return;
loading = true;
- const request = await fulfill_forgot_password_request(data.resetRequestId, formData.newPassword);
- if (request.ok) {
- goto("/sign-in?" + messageQueryKey + "=" + Message.AFTER_PASSWORD_RESET);
+ const request = await service.fulfill_request_async(data.resetRequestId, formData.newPassword.value);
+ if (request.isFulfilled) {
+ goto("/sign-in?" + signInPageMessageQueryKey + "=" + SignInPageMessage.AFTER_PASSWORD_RESET);
+ } else if (request.knownProblem) {
}
-
loading = false;
}
onMount(async () => {
errorState = undefined;
- const isValidRequest = await check_forgot_password_request(data.resetRequestId);
- if (!isValidRequest.ok && isValidRequest.status !== 404) {
+ const isValidRequest = await service.request_is_valid_async(data.resetRequestId);
+ if (!isValidRequest.isValid) {
errorState = "unknown";
canSubmit = false;
}