Skip to content

Commit

Permalink
Merge pull request #104 from ssciwr/add-forgot-password-component
Browse files Browse the repository at this point in the history
- Add forgot password component
- make use of localization 
- add backend connection
  • Loading branch information
MaHaWo authored Oct 15, 2024
2 parents d4ea8f8 + e7e098b commit 1fbb03d
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 5 deletions.
1 change: 0 additions & 1 deletion frontend/src/lib/components/ChildrenRegistration.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
{
label: 'Abschließen',
onclick: async () => {
console.log('build shit');
const childData = buildDataToSend(data);
const required = buildRequired(data);
const verified = await verifyInput(childData, required);
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/lib/components/DataDisplay/GalleryDisplay.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
const index = data.indexOf(item);
return componentProps[index];
});
$: console.log('data in gallery: ', data);
</script>

<div class="mx-auto p-4">
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/DataInput/DataInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// variables
export let component: any;
export let value: any;
export let label: string;
export let label: string | null = null;
export let componentClass: string = '';
export let textTrigger: string = 'noAdditionalText';
export let showTextField: boolean = false;
Expand Down Expand Up @@ -56,7 +56,7 @@
</script>

{#if label}
<Label class="font-semibold text-gray-700 dark:text-gray-400">{label}</Label>
<Label for={properties.id} class="font-semibold text-gray-700 dark:text-gray-400">{label}</Label>
{/if}

<div class="space-y-4">
Expand Down
95 changes: 95 additions & 0 deletions frontend/src/lib/components/UserForgotPassword.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { base } from '$app/paths';
import { type ResetForgotPasswordData } from '$lib/client';
import { resetForgotPassword } from '$lib/client/services.gen';
import { preventDefault } from '$lib/util';
import AlertMessage from '$lib/components/AlertMessage.svelte';
import DataInput from '$lib/components/DataInput/DataInput.svelte';
import { Button, Card, Heading, Input } from 'flowbite-svelte';
import { _ } from 'svelte-i18n';
const maildata = {
component: Input,
type: 'email',
value: '',
props: {
placeholder: $_('forgotPw.placeholder'),
id: 'email',
required: true
}
};
let alertMessage: string = $_('forgotPw.formatError');
let showAlert: boolean;
let showSuccess: boolean = false;
async function submitData(): Promise<void> {
const data: ResetForgotPasswordData = {
body: {
email: maildata.value
}
};
const result = await resetForgotPassword(data);
if (result.error) {
console.log('error: ', result.error);
showAlert = true;
alertMessage = $_('forgotPw.sendError');
} else {
console.log('successful transmission, response status: ', result.response.status);
showSuccess = true;
}
}
</script>

{#if showAlert}
<AlertMessage
title={$_('forgotPw.alertTitle')}
message={alertMessage}
lastpage={`${base}/userLand/lostPassword`}
onclick={() => {
showAlert = false;
}}
/>
{/if}

<Card class="container m-2 mx-auto w-full max-w-xl items-center justify-center p-2">
<Heading
tag="h3"
class="m-2 p-2 text-center font-bold tracking-tight text-gray-700 dark:text-gray-400"
>{$_('forgotPw.heading')}</Heading
>
{#if showSuccess === false}
<form onsubmit={preventDefault(submitData)}>
<div class="m-2 mx-auto w-full flex-col space-y-6 p-2">
<DataInput
component={maildata.component}
bind:value={maildata.value}
properties={maildata.props}
/>
</div>

<div class="m-2 flex w-full items-center justify-center p-2">
<Button size="md" type="submit">{$_('forgotPw.pending')}</Button>
</div>
</form>
{:else}
<div class="m-2 flex w-full items-center justify-center p-2">
<p>{$_('forgotPw.mailSentMessage')}</p>
</div>
<div class="m-2 flex w-full items-center justify-center p-2">
<Button
class="dark:bg-primay-700 w-full bg-primary-700 text-center text-sm text-white hover:bg-primary-800 hover:text-white dark:hover:bg-primary-800"
size="md"
type="button"
on:click={(event) => {
goto(`/${base}`);
}}>{$_('forgotPw.success')}</Button
>
</div>
{/if}
</Card>
11 changes: 11 additions & 0 deletions frontend/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,16 @@
"help": "Förderhilfen",
"image": "Bild",
"images": "Bilder"
},
"login": {},
"forgotPw": {
"heading": "Passwort vergessen?",
"placeholder": "Bitte geben sie eine E-mail Adresse an um ihr Passwort zu erneuern",
"success": "Zurück zur Startseite",
"pending": "Absenden",
"alertTitle": "Fehler",
"formatError": "Die angegebene email Adresse hat ein falsches Format",
"mailSentMessage": "Bitte überprüfen sie ihr E-Mail Postfach",
"sendError": "Beim Senden der Daten ist ein Fehler aufgetreten. Bitte versuchen sie es erneut"
}
}
11 changes: 11 additions & 0 deletions frontend/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,16 @@
"help": "More information",
"image": "Image",
"images": "Images"
},
"login": {},
"forgotPw": {
"heading": "Forgot your password?",
"placeholder": "Please enter your e-mail adress to get a new password",
"success": "Back to home",
"pending": "Send",
"alertTitle": "Error",
"formatError": "The given e-mail adress has a wrong format.",
"mailSentMessage": "Please check your e-mail inbox",
"sendError": "An error occured while sending the data. Please try again."
}
}
5 changes: 5 additions & 0 deletions frontend/src/routes/userLand/lostPassword/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
import UserForgotPassword from '$lib/components/UserForgotPassword.svelte';
</script>

<UserForgotPassword />

0 comments on commit 1fbb03d

Please sign in to comment.