From 07678d775eb7cd40512dd781663ace1695f4ba08 Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Tue, 15 Oct 2024 10:29:23 +0200 Subject: [PATCH 01/26] add de localization for login, put data into component --- frontend/src/lib/components/UserLogin.svelte | 47 +++++++++++++++++-- frontend/src/locales/de.json | 12 +++++ .../routes/userLand/userLogin/+page.svelte | 38 +-------------- 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index 46bdcfa2..93efc36d 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -8,8 +8,9 @@ import NavigationButtons from '$lib/components/Navigation/NavigationButtons.svelte'; import { hash, users, type UserData } from '$lib/stores/userStore'; - import { Card, Heading } from 'flowbite-svelte'; + import { Card, Heading, Input, Select } from 'flowbite-svelte'; import { onDestroy, onMount } from 'svelte'; + import // functionality @@ -53,7 +54,40 @@ } // data and variables - export let data: any[]; + let data = [ + { + component: Input, + value: null, + props: { + label: 'Benutzerkennung', + type: 'text', + placeholder: 'Benutzerkennung', + required: true + } + }, + { + component: Input, + value: null, + props: { + label: 'Passwort', + type: 'password', + placeholder: 'Passwort', + required: true + } + }, + { + component: Select, + value: null, + props: { + label: 'Rolle', + items: ['Beobachter', 'Wissenschaftler', 'Admin'].map((v) => { + return { name: String(v), value: v }; + }), + placeholder: 'Bitte auswählen', + required: true + } + } + ]; const buttons = [ { @@ -125,7 +159,12 @@ > {/if} -
+ { + console.log('event: ', event); + }} + > {#each data as element} Not registered? Create account diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 733000b4..925487e1 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -44,5 +44,17 @@ "help": "Förderhilfen", "image": "Bild", "images": "Bilder" + }, + "login": { + "alreadyLoggedIn": "Sie sind bereits angemeldet. Melden sie sich zuerst ab um den Account zu wechseln.", + "alertMessageTitle": "Fehler", + "label": "Benutzerkennung", + "passwordLabel": "Passwort", + "role": "Rolle", + "observerRole": "Beobachter", + "scientistRole": "Wissenschaftler", + "adminRole": "adminRole", + "selectPlaceholder": "Bitte auswählen", + } } diff --git a/frontend/src/routes/userLand/userLogin/+page.svelte b/frontend/src/routes/userLand/userLogin/+page.svelte index c007e1d8..e14b2ca2 100644 --- a/frontend/src/routes/userLand/userLogin/+page.svelte +++ b/frontend/src/routes/userLand/userLogin/+page.svelte @@ -1,41 +1,5 @@ - + From 66818451e71907f52166ad9849c80e69af15d985 Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Tue, 15 Oct 2024 10:52:02 +0200 Subject: [PATCH 02/26] use localization, remove some mock functions for backend --- frontend/src/lib/components/UserLogin.svelte | 133 +++++-------------- frontend/src/locales/de.json | 13 +- frontend/src/locales/en.json | 15 ++- 3 files changed, 56 insertions(+), 105 deletions(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index 93efc36d..2bb503ed 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -1,57 +1,14 @@ {#if showAlert} { @@ -141,29 +76,29 @@ {#if users.get()['loggedIn'] && users.get()['loggedIn'] !== null} { showAlert = false; }} /> {:else} -
- +
+ {#if heading} {heading} {/if} { console.log('event: ', event); }} + class="m-2 mx-auto w-full flex-col space-y-6" > {#each data as element} {/each} - - + - + + Not registered? diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 89f0f954..aa417d18 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -46,16 +46,19 @@ "images": "Bilder" }, "login": { - "alreadyLoggedIn": "Sie sind bereits angemeldet. Melden sie sich zuerst ab um den Account zu wechseln.", + "heading": "Einloggen", + "alreadyLoggedInMessage": "Sie sind bereits angemeldet. Melden sie sich zuerst ab um den Account zu wechseln.", "alertMessageTitle": "Fehler", - "label": "Benutzerkennung", + "alertMessage": "Eingaben sind falsch", + "usernameLabel": "Benutzerkennung", "passwordLabel": "Passwort", "role": "Rolle", "observerRole": "Beobachter", "scientistRole": "Wissenschaftler", - "adminRole": "adminRole", - "selectPlaceholder": "Bitte auswählen", - + "adminRole": "Admin", + "submitButtonLabel": "Absenden", + "selectPlaceholder": "Bitte auswählen" + }, "forgotPw": { "heading": "Passwort vergessen?", "placeholder": "Bitte geben sie eine E-mail Adresse an um ihr Passwort zu erneuern", diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index da794134..fec7c42e 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -45,7 +45,20 @@ "image": "Image", "images": "Images" }, - "login": {}, + "login": { + "heading": "Sign in", + "alreadyLoggedIn": "You are already logged in. Sign out first to use to another account", + "alertMessageTitle": "Error", + "alertMessage": "Wrong entries", + "usernameLabel": "Username", + "passwordLabel": "Password", + "role": "role", + "observerRole": "observer", + "scientistRole": "scientist", + "adminRole": "admin", + "submitButtonLabel": "Submit", + "selectPlaceholder": "Please select" + }, "forgotPw": { "heading": "Forgot your password?", "placeholder": "Please enter your e-mail adress to get a new password", From 98a5a65f5113979767958d8ae7fa0f9a6045a12b Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Tue, 15 Oct 2024 10:56:09 +0200 Subject: [PATCH 03/26] add button styling --- frontend/src/lib/components/UserLogin.svelte | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index 2bb503ed..ea5a34d2 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -116,7 +116,10 @@ - + From 9e2a73c567bafba5eccd471e7293ea47d8368fce Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Tue, 15 Oct 2024 11:34:41 +0200 Subject: [PATCH 04/26] add new verify logic skeleton --- frontend/src/lib/components/UserLogin.svelte | 138 ++++++++++--------- frontend/src/locales/de.json | 2 +- 2 files changed, 77 insertions(+), 63 deletions(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index ea5a34d2..6e348aa2 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -5,16 +5,44 @@ import AlertMessage from '$lib/components/AlertMessage.svelte'; import DataInput from '$lib/components/DataInput/DataInput.svelte'; - import { users } from '$lib/stores/userStore'; + import { goto } from '$app/navigation'; + import { authCookieLogin } from '$lib/client'; + import { + type AuthCookieLoginData, + type Body_auth_cookie_login_auth_login_post + } from '$lib/client/types.gen'; + import { preventDefault } from '$lib/util'; import { Button, Card, Heading, Input, Select } from 'flowbite-svelte'; - import { onDestroy, onMount } from 'svelte'; import { _ } from 'svelte-i18n'; - // data and variables - let data = [ + // functionality + async function submitData() { + const loginData: Body_auth_cookie_login_auth_login_post = { + username: formData[0].value, + password: formData[1].value + }; + + const data: AuthCookieLoginData = { + body: loginData + }; + + const authReturn = await authCookieLogin(data); + + if (authReturn.error) { + showAlert = true; + for (let element of formData) { + element.value = ''; + } + } else { + goto('/userLand/userLandingpage'); + } + } + + // form data and variables + let formData = [ { component: Input, - value: null, + value: '', props: { label: $_('login.usernameLabel'), type: 'text', @@ -25,7 +53,7 @@ }, { component: Input, - value: null, + value: '', props: { label: $_('login.passwordLabel'), type: 'password', @@ -36,7 +64,7 @@ }, { component: Select, - value: null, + value: '', props: { label: $_('login.role'), items: [$_('login.observerRole'), $_('login.scientistRole'), $_('login.adminRole')].map( @@ -51,22 +79,15 @@ } ]; - let alertMessage = $_('login.alertMessage'); - let userID: string; let remember: boolean = false; let showAlert: boolean = false; - const heading = $_('login.heading'); - - // check if credentials are stored - onMount(async () => {}); - - onDestroy(async () => {}); + $: console.log('remember: ', remember, 'showAlert: ', showAlert); {#if showAlert} { showAlert = false; @@ -74,7 +95,7 @@ /> {/if} -{#if users.get()['loggedIn'] && users.get()['loggedIn'] !== null} + +
+ + {$_('login.heading')} -
{ - console.log('event: ', event); - }} - class="m-2 mx-auto w-full flex-col space-y-6" - > - {#each data as element} - - {/each} + + {#each formData as element} + + {/each} - + - - -
+ + + - Not registered? - - Create account - -
-{/if} + Not registered? + + Create account + +
+ diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index aa417d18..eec7f566 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -49,7 +49,7 @@ "heading": "Einloggen", "alreadyLoggedInMessage": "Sie sind bereits angemeldet. Melden sie sich zuerst ab um den Account zu wechseln.", "alertMessageTitle": "Fehler", - "alertMessage": "Eingaben sind falsch", + "alertMessage": "Einloggen nicht erfolgreich. Eingaben sind falsch", "usernameLabel": "Benutzerkennung", "passwordLabel": "Passwort", "role": "Rolle", From 24c17a26996b2907bf1072399e6bbbcf3897a22d Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Tue, 15 Oct 2024 14:26:23 +0200 Subject: [PATCH 05/26] work on using backend in user registration --- frontend/src/lib/components/UserLogin.svelte | 2 +- .../lib/components/UserRegistration.svelte | 199 +++++++----------- frontend/src/locales/de.json | 20 +- .../userLand/userRegistration/+page.svelte | 55 +---- 4 files changed, 90 insertions(+), 186 deletions(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index 6e348aa2..edf17fa1 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -87,7 +87,7 @@ {#if showAlert} { showAlert = false; diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index c00ab672..5bf5a55e 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -1,134 +1,73 @@ {#if showAlert} { - showAlert = false; - missingValues = []; + showAlert = false; }} /> {/if} @@ -136,30 +75,34 @@
- {#if heading} - {heading} - {/if} + {$_('registration.heading')} + + +
{ + console.log('event: ', e); + })} class="m-2 mx-auto w-full flex-col space-y-6"> - {#each data as element, i} {/each} + + -
diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index c2568957..c2da69b7 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -1,7 +1,4 @@ { - "login": { - "LOGIN_BAD_CREDENTIALS": "Ungültige E-Mail-Adresse oder ungültiges Passwort" - }, "milestone": { "answer0-text": "Noch gar nicht", "answer0-desc": "Das Kind macht noch keine Anstalten bzw. ist noch nicht in der Lage, das Verhalten auszuführen.", @@ -40,11 +37,26 @@ "image": "Bild", "images": "Bilder" }, + "registration": { + "heading": "Als neuer Benutzer registrieren", + "alertMessage": "Bitte füllen Sie alle Felder aus.", + "alertMessageTitle": "Fehler", + "usernameLabel": "Benutzername", + "passwordLabel": "Passwort", + "emailLabel": "e-Mail", + "passwordConfirmLabel": "Passwort wiederholen", + "role": "Rolle", + "observerRole": "Beobachter", + "scientistRole": "Wissenschaftler", + "adminRole": "Admin", + "submitButtonLabel": "Absenden", + "selectPlaceholder": "Bitte auswählen" + }, "login": { "heading": "Einloggen", "alreadyLoggedInMessage": "Sie sind bereits angemeldet. Melden sie sich zuerst ab um den Account zu wechseln.", "alertMessageTitle": "Fehler", - "alertMessage": "Einloggen nicht erfolgreich. Eingaben sind falsch", + "LOGIN_BAD_CREDENTIALS": "Ungültige E-Mail-Adresse oder ungültiges Passwort", "usernameLabel": "Benutzerkennung", "passwordLabel": "Passwort", "role": "Rolle", diff --git a/frontend/src/routes/userLand/userRegistration/+page.svelte b/frontend/src/routes/userLand/userRegistration/+page.svelte index d78aef9f..52c3eade 100644 --- a/frontend/src/routes/userLand/userRegistration/+page.svelte +++ b/frontend/src/routes/userLand/userRegistration/+page.svelte @@ -1,57 +1,6 @@ - + From 5d9240704d928cb6e1533087992ea26a5d63d296 Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Tue, 15 Oct 2024 14:54:30 +0200 Subject: [PATCH 06/26] work on submission of data in userregistration --- .../lib/components/UserRegistration.svelte | 64 ++++++++++++++----- frontend/src/locales/de.json | 5 +- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index 5bf5a55e..87b0a12a 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -1,24 +1,57 @@ {#if showAlert} { @@ -81,10 +114,7 @@ >{$_('registration.heading')} -
{ - console.log('event: ', e); - })} class="m-2 mx-auto w-full flex-col space-y-6"> - + {#each data as element, i} Date: Tue, 15 Oct 2024 15:22:06 +0200 Subject: [PATCH 07/26] add user registration verify and success page --- .../lib/components/UserRegistration.svelte | 53 ++++++++++++------- frontend/src/locales/de.json | 4 +- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index 87b0a12a..f9feca4f 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -6,7 +6,7 @@ import DataInput from '$lib/components/DataInput/DataInput.svelte'; import { preventDefault } from '$lib/util'; import { Button, Card, Heading, Input } from 'flowbite-svelte'; - + import { CheckCircleOutline } from 'flowbite-svelte-icons'; import { _ } from 'svelte-i18n'; @@ -17,21 +17,24 @@ } }; - - function verify() { - return data[1].value !== "" && data[2].value === data[1].value; - } - async function submitData() { - const equalPW = verify(); + const equalPW = data[1].value !== "" && data[2].value === data[1].value; if (equalPW) { userData.body.email = data[0].value userData.body.password = data[1].value - console.log('userData: ', userData); const result = await registerRegister(userData) - console.log(result); + + if (result.error) { + console.log('error: ', result.error); + showAlert = true; + data.map((element)=> {element.value = "";}); + } + else { + console.log('successful transmission: ', result.response.status); + success=true; + } } else { showAlert = true; @@ -89,6 +92,7 @@ ]; let showAlert: boolean = false; + let success: boolean = true; let alertMessage = $_('registration.alertMessageMissing'); @@ -106,14 +110,14 @@ {/if} -
- - {$_('registration.heading')} - + + {$_('registration.heading')} + + {#if success === false} {#each data as element, i} {$_('registration.submitButtonLabel')} - -
+ {:else} +
+ +
+ {$_('registration.successMessage')} +
+
+ + {/if} +
diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 2e1bcbb5..2f480037 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -51,7 +51,9 @@ "scientistRole": "Wissenschaftler", "adminRole": "Admin", "submitButtonLabel": "Absenden", - "selectPlaceholder": "Bitte auswählen" + "selectPlaceholder": "Bitte auswählen", + "successMessage": "Bitte überprüfen sie ihr E-Mail Postfach", + "goHome": "Zur Hauptseite" }, "login": { "heading": "Einloggen", From 93d2b7e4b7e9c2e4d86f2d52a007ab77ad0d7aa3 Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Tue, 15 Oct 2024 15:34:52 +0200 Subject: [PATCH 08/26] remove commented out code --- frontend/src/lib/components/UserRegistration.svelte | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index f9feca4f..21feb3de 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -44,17 +44,6 @@ const data = [ - // { - // component: Input, - // props: { - // label: $_('registration.usernameLabel'), - // type: 'text', - // placeholder: $_('registration.usernameLabel'), - // required: true, - // id: 'username' - // }, - // value: '' - // }, { component: Input, props: { @@ -92,7 +81,7 @@ ]; let showAlert: boolean = false; - let success: boolean = true; + let success: boolean = false; let alertMessage = $_('registration.alertMessageMissing'); From 2b2a4ca60c9f5c68613d4e63e29e3086d129d19f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 15 Oct 2024 13:39:54 +0000 Subject: [PATCH 09/26] update openapi.json & openapi-ts client, run pnpm format --- frontend/src/lib/components/UserLogin.svelte | 4 +- .../lib/components/UserRegistration.svelte | 68 +++++++++---------- frontend/src/locales/de.json | 8 +-- .../userLand/userRegistration/+page.svelte | 1 - 4 files changed, 40 insertions(+), 41 deletions(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index edf17fa1..8be01585 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -131,7 +131,7 @@ @@ -140,7 +140,7 @@ Not registered? Create account diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index 21feb3de..3540adee 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -9,45 +9,42 @@ import { CheckCircleOutline } from 'flowbite-svelte-icons'; import { _ } from 'svelte-i18n'; - const userData: RegisterRegisterData = { body: { - email: "", - password: "" + email: '', + password: '' } }; async function submitData() { - - const equalPW = data[1].value !== "" && data[2].value === data[1].value; + const equalPW = data[1].value !== '' && data[2].value === data[1].value; if (equalPW) { - userData.body.email = data[0].value - userData.body.password = data[1].value - const result = await registerRegister(userData) + userData.body.email = data[0].value; + userData.body.password = data[1].value; + const result = await registerRegister(userData); if (result.error) { - console.log('error: ', result.error); + console.log('error: ', result.error); showAlert = true; - data.map((element)=> {element.value = "";}); - } - else { + data.map((element) => { + element.value = ''; + }); + } else { console.log('successful transmission: ', result.response.status); - success=true; + success = true; } - } - else { - showAlert = true; - alertMessage = $_('registration.alertMessagePasswords') + } else { + showAlert = true; + alertMessage = $_('registration.alertMessagePasswords'); } } - const data = [ { component: Input, props: { - label: $_('registration.emailLabel'), + label: $_('registration.emailLabel'), type: 'email', placeholder: $_('registration.emailLabel'), required: true, @@ -65,7 +62,6 @@ id: 'password' }, value: '' - }, { component: Input, @@ -82,7 +78,7 @@ let showAlert: boolean = false; let success: boolean = false; - let alertMessage = $_('registration.alertMessageMissing'); + let alertMessage = $_('registration.alertMessageMissing'); @@ -93,13 +89,13 @@ infopage="{base}/info" infotitle="Was passiert mit den Daten" onclick={() => { - showAlert = false; + showAlert = false; }} /> {/if} - + {$_('registration.submitButtonLabel')} + type="submit" + 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" + >{$_('registration.submitButtonLabel')} {:else} -
- +
+
- {$_('registration.successMessage')} + {$_('registration.successMessage')}
- {/if} diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 2f480037..15cba320 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -38,8 +38,8 @@ "images": "Bilder" }, "registration": { - "heading": "Als neuer Benutzer registrieren", - "alertMessageMissing": "Bitte füllen Sie alle Felder aus.", + "heading": "Als neuer Benutzer registrieren", + "alertMessageMissing": "Bitte füllen Sie alle Felder aus.", "alertMessagePasswords": "Passwörter stimmen nicht überein", "alertMessageTitle": "Fehler", "usernameLabel": "Benutzername", @@ -51,8 +51,8 @@ "scientistRole": "Wissenschaftler", "adminRole": "Admin", "submitButtonLabel": "Absenden", - "selectPlaceholder": "Bitte auswählen", - "successMessage": "Bitte überprüfen sie ihr E-Mail Postfach", + "selectPlaceholder": "Bitte auswählen", + "successMessage": "Bitte überprüfen sie ihr E-Mail Postfach", "goHome": "Zur Hauptseite" }, "login": { diff --git a/frontend/src/routes/userLand/userRegistration/+page.svelte b/frontend/src/routes/userLand/userRegistration/+page.svelte index 52c3eade..104f34b5 100644 --- a/frontend/src/routes/userLand/userRegistration/+page.svelte +++ b/frontend/src/routes/userLand/userRegistration/+page.svelte @@ -1,6 +1,5 @@ From 32f3aecae42ba3ca82db79cd6883204edb13198b Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Wed, 16 Oct 2024 09:19:54 +0200 Subject: [PATCH 10/26] add role, e-mail to login --- frontend/src/lib/components/UserLogin.svelte | 10 ++--- .../lib/components/UserRegistration.svelte | 42 +++++++++++++++---- frontend/src/locales/de.json | 7 ++-- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index 8be01585..76533572 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -45,7 +45,7 @@ value: '', props: { label: $_('login.usernameLabel'), - type: 'text', + type: 'email', placeholder: $_('login.usernameLabel'), required: true, id: 'username' @@ -67,7 +67,7 @@ value: '', props: { label: $_('login.role'), - items: [$_('login.observerRole'), $_('login.scientistRole'), $_('login.adminRole')].map( + items: [$_('login.observerRole'), $_('login.researcherRole'), $_('login.adminRole')].map( (v) => { return { name: String(v), value: v }; } @@ -87,7 +87,7 @@ {#if showAlert} { showAlert = false; @@ -131,7 +131,7 @@ @@ -140,7 +140,7 @@ Not registered? Create account diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index 3540adee..985db12f 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -5,35 +5,41 @@ import AlertMessage from '$lib/components/AlertMessage.svelte'; import DataInput from '$lib/components/DataInput/DataInput.svelte'; import { preventDefault } from '$lib/util'; - import { Button, Card, Heading, Input } from 'flowbite-svelte'; + import { Button, Card, Heading, Input, Select } from 'flowbite-svelte'; import { CheckCircleOutline } from 'flowbite-svelte-icons'; import { _ } from 'svelte-i18n'; const userData: RegisterRegisterData = { body: { email: '', - password: '' + password: '', + is_superuser: false, + is_researcher: false } }; - async function submitData() { + async function submitData(): Promise { const equalPW = data[1].value !== '' && data[2].value === data[1].value; if (equalPW) { userData.body.email = data[0].value; userData.body.password = data[1].value; + userData.body.is_researcher = data[3].value === $_('registration.researcherRole'); + userData.body.is_superuser = data[3].value === $_('registration.adminRole'); + const result = await registerRegister(userData); if (result.error) { - console.log('error: ', result.error); + console.log('error: ', result.response.status, result.error.detail); + alertMessage = $_('registration.alertMessageError') + ': ' + result.error.detail; showAlert = true; - data.map((element) => { - element.value = ''; - }); } else { console.log('successful transmission: ', result.response.status); success = true; } + data.map((element) => { + element.value = ''; + }); } else { showAlert = true; alertMessage = $_('registration.alertMessagePasswords'); @@ -73,6 +79,24 @@ id: 'passwordConfirm' }, value: '' + }, + { + component: Select, + props: { + label: $_('registration.role'), + type: 'text', + placeholder: $_('registration.selectPlaceholder'), + required: true, + id: 'role', + items: [ + $_('registration.observerRole'), + $_('registration.researcherRole'), + $_('registration.adminRole') + ].map((v) => { + return { name: String(v), value: v }; + }) + }, + value: '' } ]; @@ -120,7 +144,7 @@ @@ -135,7 +159,7 @@
+
+

{userData.email}

+
{:else}
- Willkommen! - + {$_('login.profileTitleDefault')} +
{/if} From e914f4c2385210c3d58d7cc5f897e58b998568c2 Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Wed, 16 Oct 2024 11:52:24 +0200 Subject: [PATCH 13/26] add localizations --- frontend/src/locales/de.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/locales/de.json b/frontend/src/locales/de.json index 612e5481..533c522e 100644 --- a/frontend/src/locales/de.json +++ b/frontend/src/locales/de.json @@ -61,6 +61,8 @@ "alreadyLoggedInMessage": "Sie sind bereits angemeldet. Melden sie sich zuerst ab um den Account zu wechseln.", "alertMessageTitle": "Fehler", "badCredentials": "Ungültige E-Mail-Adresse oder ungültiges Passwort", + "badActiveUser": "Der Benutzer konnte nicht gefunden werden", + "unauthorized": "Zugang verweigert", "usernameLabel": "Benutzerkennung", "passwordLabel": "Passwort", "role": "Rolle", @@ -68,7 +70,10 @@ "researcherRole": "Wissenschaftler", "adminRole": "Admin", "submitButtonLabel": "Absenden", - "selectPlaceholder": "Bitte auswählen" + "selectPlaceholder": "Bitte auswählen", + "profileButtonLabelDefault": "Einloggen oder Registrieren", + "profileButtonLabelLogout": "Logout", + "profileTitleDefault": "Willkommen!" }, "forgotPw": { "heading": "Passwort vergessen?", From f221554a17b72737bebd7cca38db6f6da279b0fa Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 16 Oct 2024 09:57:15 +0000 Subject: [PATCH 14/26] update openapi.json & openapi-ts client, run pnpm format --- frontend/src/lib/components/UserLogin.svelte | 4 ++-- frontend/src/lib/components/UserRegistration.svelte | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index b4d79082..63f57fbd 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -147,7 +147,7 @@ @@ -156,7 +156,7 @@ Not registered? Create account diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index 985db12f..3af851fb 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -144,7 +144,7 @@ @@ -159,7 +159,7 @@
@@ -156,9 +151,8 @@ Not registered? Create account - diff --git a/frontend/src/lib/components/UserProfile.svelte b/frontend/src/lib/components/UserProfile.svelte index 8902385a..05bb301c 100644 --- a/frontend/src/lib/components/UserProfile.svelte +++ b/frontend/src/lib/components/UserProfile.svelte @@ -17,7 +17,6 @@ let alertMessage: string = $_('login.alertMessageError'); const unsubscribe = currentUser.subscribe((data) => { - console.log('data: ', data); userData = data; }); @@ -36,7 +35,7 @@ onDestroy(unsubscribe); - $: console.log('userData: ', userData); + $: console.log('userData in profile: ', userData); From 38c296cd6c35e42b16eebd5c815fbe3bf6865292 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 16 Oct 2024 11:22:23 +0000 Subject: [PATCH 16/26] update openapi.json & openapi-ts client, run pnpm format --- frontend/src/lib/components/UserLogin.svelte | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index c27bfa3d..648a6411 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -142,7 +142,7 @@ @@ -151,7 +151,7 @@ Not registered? Create account From d13f4b446329703aea5baed4450405fbd731db35 Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Wed, 16 Oct 2024 14:41:23 +0200 Subject: [PATCH 17/26] add verified warning page --- .../src/lib/components/UserLandingPage.svelte | 52 +++++++++++-------- frontend/src/lib/components/UserLogin.svelte | 20 ++----- .../lib/components/UserRegistration.svelte | 41 +++++---------- frontend/src/lib/components/UserVerify.svelte | 21 ++++++++ 4 files changed, 69 insertions(+), 65 deletions(-) create mode 100644 frontend/src/lib/components/UserVerify.svelte diff --git a/frontend/src/lib/components/UserLandingPage.svelte b/frontend/src/lib/components/UserLandingPage.svelte index ea57db8b..b15cc09f 100644 --- a/frontend/src/lib/components/UserLandingPage.svelte +++ b/frontend/src/lib/components/UserLandingPage.svelte @@ -1,21 +1,23 @@ -
- - -
- - Persönliche Daten -
- -
- -
- - Kinder -
- -
-
-
+{#if isVerifed === true} +
+ + +
+ + Persönliche Daten +
+ +
+ +
+ + Kinder +
+ +
+
+
+{:else} + +{/if} diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index c27bfa3d..28df05cf 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -10,7 +10,7 @@ import { type AuthCookieLoginData, type UserRead } from '$lib/client/types.gen'; import { currentUser } from '$lib/stores/userStore'; import { preventDefault } from '$lib/util'; - import { Button, Card, Heading, Input, Select } from 'flowbite-svelte'; + import { Button, Card, Heading, Input } from 'flowbite-svelte'; import { _ } from 'svelte-i18n'; async function refresh(): Promise { @@ -21,6 +21,9 @@ return returned.error.detail; } else { console.log('Successfully retrieved active user'); + // TODO: remove this in the final version, this sets verified to true + // to emulate a successful user registration + returned.data.is_verified = true; currentUser.set(returned.data as UserRead); return 'success'; } @@ -82,21 +85,6 @@ required: true, id: 'password' } - }, - { - component: Select, - value: '', - props: { - label: $_('login.role'), - items: [$_('login.observerRole'), $_('login.researcherRole'), $_('login.adminRole')].map( - (v) => { - return { name: String(v), value: v }; - } - ), - placeholder: $_('login.selectPlaceholder'), - required: true, - id: 'role' - } } ]; diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index 3af851fb..af04c244 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -6,26 +6,27 @@ import DataInput from '$lib/components/DataInput/DataInput.svelte'; import { preventDefault } from '$lib/util'; import { Button, Card, Heading, Input, Select } from 'flowbite-svelte'; - import { CheckCircleOutline } from 'flowbite-svelte-icons'; import { _ } from 'svelte-i18n'; - - const userData: RegisterRegisterData = { - body: { - email: '', - password: '', - is_superuser: false, - is_researcher: false - } - }; + import UserVerify from './UserVerify.svelte'; async function submitData(): Promise { const equalPW = data[1].value !== '' && data[2].value === data[1].value; + const userData: RegisterRegisterData = { + body: { + email: '', + password: '', + is_active: false, + is_superuser: false, + is_researcher: false + } + }; if (equalPW) { userData.body.email = data[0].value; userData.body.password = data[1].value; userData.body.is_researcher = data[3].value === $_('registration.researcherRole'); userData.body.is_superuser = data[3].value === $_('registration.adminRole'); + userData.body.is_active = true; const result = await registerRegister(userData); @@ -37,7 +38,7 @@ console.log('successful transmission: ', result.response.status); success = true; } - data.map((element) => { + data.forEach((element) => { element.value = ''; }); } else { @@ -144,25 +145,11 @@ {:else} -
- -
- {$_('registration.successMessage')} -
-
- + {/if} diff --git a/frontend/src/lib/components/UserVerify.svelte b/frontend/src/lib/components/UserVerify.svelte new file mode 100644 index 00000000..5532f773 --- /dev/null +++ b/frontend/src/lib/components/UserVerify.svelte @@ -0,0 +1,21 @@ + + +
+ +
+ {$_('registration.successMessage')} +
+
+ From ebc9bb0c78ac5c6e8132ced291ae5067ca3334e9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 16 Oct 2024 12:42:18 +0000 Subject: [PATCH 18/26] update openapi.json & openapi-ts client, run pnpm format --- frontend/src/lib/components/UserRegistration.svelte | 2 +- frontend/src/lib/components/UserVerify.svelte | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index af04c244..f526ef21 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -145,7 +145,7 @@ diff --git a/frontend/src/lib/components/UserVerify.svelte b/frontend/src/lib/components/UserVerify.svelte index 5532f773..f2d02943 100644 --- a/frontend/src/lib/components/UserVerify.svelte +++ b/frontend/src/lib/components/UserVerify.svelte @@ -14,7 +14,7 @@ @@ -139,7 +133,7 @@ Not registered? Create account diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index ec7008bb..13aa2282 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -29,9 +29,7 @@ userData.body.is_active = true; const result = await registerRegister(userData); - data.forEach((element) => { - element.value = ''; - }); + if (result.error) { console.log('error: ', result.response.status, result.error.detail); alertMessage = $_('registration.alertMessageError') + ': ' + result.error.detail; @@ -99,7 +97,7 @@ return { name: String(v), value: v }; }) }, - value: '' + value: $_('registration.observerRole') } ]; @@ -147,7 +145,7 @@ diff --git a/frontend/src/lib/stores/userStore.ts b/frontend/src/lib/stores/userStore.ts index ae95a900..aab5efb3 100644 --- a/frontend/src/lib/stores/userStore.ts +++ b/frontend/src/lib/stores/userStore.ts @@ -88,6 +88,6 @@ async function hash(input: string): string { return hash; } -const currentUser = writable(null as unknown as UserRead); +const currentUser = writable(null as null | UserRead); export { createDummyUser, currentUser, hash, users, UserStore, type UserData, type UserList }; From 46b1fa09a3d09d29b1ece10546f755cc4be1e969 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 16 Oct 2024 14:56:14 +0000 Subject: [PATCH 21/26] update openapi.json & openapi-ts client, run pnpm format --- frontend/src/lib/components/UserLogin.svelte | 4 ++-- frontend/src/lib/components/UserRegistration.svelte | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index 7ee785dc..08dda067 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -124,7 +124,7 @@ @@ -133,7 +133,7 @@ Not registered? Create account diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index 13aa2282..8a3952e6 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -145,7 +145,7 @@ From 86769956bdbbae4144f57fa09b3547e70e0b2f32 Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Wed, 16 Oct 2024 22:06:01 +0200 Subject: [PATCH 22/26] add database writing to on_after_register --- mondey_backend/src/mondey_backend/users.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mondey_backend/src/mondey_backend/users.py b/mondey_backend/src/mondey_backend/users.py index 91a394df..8112316e 100644 --- a/mondey_backend/src/mondey_backend/users.py +++ b/mondey_backend/src/mondey_backend/users.py @@ -4,6 +4,7 @@ from fastapi import Depends from fastapi import Request +from fastapi import HTTPException from fastapi_users import BaseUserManager from fastapi_users import FastAPIUsers from fastapi_users import IntegerIDMixin @@ -17,6 +18,7 @@ from .databases.users import User from .databases.users import get_access_token_db from .databases.users import get_user_db +from .databases.users import get_async_session from .settings import app_settings @@ -26,6 +28,18 @@ class UserManager(IntegerIDMixin, BaseUserManager[User, int]): async def on_after_register(self, user: User, request: Request | None = None): print(f"User {user.id} has registered.") + + # Fetch the user from the database + async with get_async_session() as session: + db_user = await session.get(User, user.id) + if not db_user: + raise HTTPException(status_code=404, detail="User not found") + + # Update the is_verified attribute + db_user.is_verified = True + session.add(db_user) + await session.commit() + await session.refresh(db_user) async def on_after_forgot_password( self, user: User, token: str, request: Request | None = None From f149b6f4d2f12e0e85ae0f1302769f5ca2e4791d Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Thu, 17 Oct 2024 09:13:18 +0200 Subject: [PATCH 23/26] fix error in database rewriting --- mondey_backend/src/mondey_backend/users.py | 38 +++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/mondey_backend/src/mondey_backend/users.py b/mondey_backend/src/mondey_backend/users.py index 8112316e..44ee0ccc 100644 --- a/mondey_backend/src/mondey_backend/users.py +++ b/mondey_backend/src/mondey_backend/users.py @@ -1,10 +1,12 @@ +# TODO: 17th Oct. 2024: remove the artificial verification set again as soon as +# the email verification server has been implemented. See 'README' block @ line 33ff + from __future__ import annotations from typing import Annotated from fastapi import Depends from fastapi import Request -from fastapi import HTTPException from fastapi_users import BaseUserManager from fastapi_users import FastAPIUsers from fastapi_users import IntegerIDMixin @@ -13,12 +15,13 @@ from fastapi_users.authentication.strategy.db import AccessTokenDatabase from fastapi_users.authentication.strategy.db import DatabaseStrategy from fastapi_users.db import SQLAlchemyUserDatabase +from sqlalchemy.future import select from .databases.users import AccessToken from .databases.users import User from .databases.users import get_access_token_db -from .databases.users import get_user_db from .databases.users import get_async_session +from .databases.users import get_user_db from .settings import app_settings @@ -27,19 +30,24 @@ class UserManager(IntegerIDMixin, BaseUserManager[User, int]): verification_token_secret = app_settings.SECRET async def on_after_register(self, user: User, request: Request | None = None): - print(f"User {user.id} has registered.") - - # Fetch the user from the database - async with get_async_session() as session: - db_user = await session.get(User, user.id) - if not db_user: - raise HTTPException(status_code=404, detail="User not found") - - # Update the is_verified attribute - db_user.is_verified = True - session.add(db_user) - await session.commit() - await session.refresh(db_user) + # README: Sets the verified flag artificially to allow users to work without an + # actual verification process for now. this can go again as soon as we have an email server for verification. + async for session in get_async_session(): + # find user in database + result = await session.execute(select(User).filter(User.id == user.id)) + user_entry = result.scalars().first() + + # set verified artificially and write back + if user_entry: + user_entry.is_verified = True + session.add(user_entry) + await session.commit() + await session.refresh(user_entry) + + print("user object: ", user_entry.__dict__) + print(f"User {user_entry.id} has registered.") + print(f"User is verified? {user_entry.is_verified}") + # end README async def on_after_forgot_password( self, user: User, token: str, request: Request | None = None From 4e43ab767a1cdb0617c8cac73ac22b29cc2ce41d Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Thu, 17 Oct 2024 09:15:39 +0200 Subject: [PATCH 24/26] better comment --- mondey_backend/src/mondey_backend/users.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mondey_backend/src/mondey_backend/users.py b/mondey_backend/src/mondey_backend/users.py index 44ee0ccc..57f659eb 100644 --- a/mondey_backend/src/mondey_backend/users.py +++ b/mondey_backend/src/mondey_backend/users.py @@ -32,6 +32,7 @@ class UserManager(IntegerIDMixin, BaseUserManager[User, int]): async def on_after_register(self, user: User, request: Request | None = None): # README: Sets the verified flag artificially to allow users to work without an # actual verification process for now. this can go again as soon as we have an email server for verification. + # why can´t we use a contextmanager here?: TypeError: 'async_generator' object does not support the [asynchronous] context manager protocol async for session in get_async_session(): # find user in database result = await session.execute(select(User).filter(User.id == user.id)) From ac61c6989da3d0b22a9fbb4b4e03978d925782dd Mon Sep 17 00:00:00 2001 From: Harald Mack Date: Thu, 17 Oct 2024 09:22:58 +0200 Subject: [PATCH 25/26] update comments --- mondey_backend/src/mondey_backend/users.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mondey_backend/src/mondey_backend/users.py b/mondey_backend/src/mondey_backend/users.py index 57f659eb..96ba6d12 100644 --- a/mondey_backend/src/mondey_backend/users.py +++ b/mondey_backend/src/mondey_backend/users.py @@ -1,5 +1,5 @@ -# TODO: 17th Oct. 2024: remove the artificial verification set again as soon as -# the email verification server has been implemented. See 'README' block @ line 33ff +# TODO: 17th Oct. 2024: remove the artificial verification setting again as soon as +# the email verification server has been implemented. See 'README' block @ line 33f from __future__ import annotations From 39cc4b20b2f7f87e7f0a3c5b63f9d9edb6ae2835 Mon Sep 17 00:00:00 2001 From: Liam Keegan Date: Thu, 17 Oct 2024 10:55:29 +0200 Subject: [PATCH 26/26] use async_session_maker and session.get to set user as verified --- mondey_backend/src/mondey_backend/users.py | 24 ++++++++-------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/mondey_backend/src/mondey_backend/users.py b/mondey_backend/src/mondey_backend/users.py index 96ba6d12..da5a0823 100644 --- a/mondey_backend/src/mondey_backend/users.py +++ b/mondey_backend/src/mondey_backend/users.py @@ -15,12 +15,11 @@ from fastapi_users.authentication.strategy.db import AccessTokenDatabase from fastapi_users.authentication.strategy.db import DatabaseStrategy from fastapi_users.db import SQLAlchemyUserDatabase -from sqlalchemy.future import select from .databases.users import AccessToken from .databases.users import User +from .databases.users import async_session_maker from .databases.users import get_access_token_db -from .databases.users import get_async_session from .databases.users import get_user_db from .settings import app_settings @@ -32,22 +31,15 @@ class UserManager(IntegerIDMixin, BaseUserManager[User, int]): async def on_after_register(self, user: User, request: Request | None = None): # README: Sets the verified flag artificially to allow users to work without an # actual verification process for now. this can go again as soon as we have an email server for verification. - # why can´t we use a contextmanager here?: TypeError: 'async_generator' object does not support the [asynchronous] context manager protocol - async for session in get_async_session(): - # find user in database - result = await session.execute(select(User).filter(User.id == user.id)) - user_entry = result.scalars().first() - - # set verified artificially and write back - if user_entry: - user_entry.is_verified = True - session.add(user_entry) + async with async_session_maker() as session: + user_db = await session.get(User, user.id) + if user_db: + user_db.is_verified = True await session.commit() - await session.refresh(user_entry) + await session.refresh(user_db) - print("user object: ", user_entry.__dict__) - print(f"User {user_entry.id} has registered.") - print(f"User is verified? {user_entry.is_verified}") + print(f"User {user_db.id} has registered.") + print(f"User is verified? {user_db.is_verified}") # end README async def on_after_forgot_password(