From 25195baaca3deee5cae4ddc645ba338b9fffc4a0 Mon Sep 17 00:00:00 2001 From: Liam Keegan Date: Tue, 26 Nov 2024 09:43:15 +0100 Subject: [PATCH 1/4] Add researcher codes - backend - add ResearchGroup model with 6-digit id code for users to use when signing up - add checkdigit dependency to add checksum to code - add full_data_access flag to users if they should have research access to all data - admin frontend users tab - add reseach_group_id & full_data_access to table - add button to add create a research code for a researcher - frontend - add ResearchCodeInput input which checks the entered code checksum is valid - add optional code input to user signup, remove role selection - make url for signup /signup - add optional code e.g. /signup/123451 to allow researchers to send sign-up links to their users with code pre-filled - add cdigit dependency to validate codes - resolves #185 --- frontend/Dockerfile | 4 +- frontend/package.json | 1 + frontend/pnpm-lock.yaml | 17 ++++ frontend/src/lib/client/schemas.gen.ts | 68 +++++++++++++++- frontend/src/lib/client/services.gen.ts | 32 +++++++- frontend/src/lib/client/types.gen.ts | 34 ++++++++ .../src/lib/components/Admin/Users.svelte | 37 ++++++++- .../DataInput/ResearchCodeInput.svelte | 36 +++++++++ .../src/lib/components/FrontPageCard.svelte | 2 +- frontend/src/lib/components/UserLogin.svelte | 2 +- .../lib/components/UserRegistration.svelte | 81 +++++++------------ frontend/src/locales/de.json | 5 +- .../[[code]]}/+page.svelte | 3 +- mondey_backend/openapi.json | 2 +- mondey_backend/pyproject.toml | 1 + .../src/mondey_backend/models/research.py | 8 ++ .../src/mondey_backend/models/users.py | 10 +++ .../routers/admin_routers/users.py | 54 ++++++++++++- mondey_backend/tests/conftest.py | 12 ++- .../routers/admin_routers/test_admin_users.py | 27 +++++++ 20 files changed, 369 insertions(+), 67 deletions(-) create mode 100644 frontend/src/lib/components/DataInput/ResearchCodeInput.svelte rename frontend/src/routes/{userLand/userRegistration => signup/[[code]]}/+page.svelte (53%) create mode 100644 mondey_backend/src/mondey_backend/models/research.py diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 07727750..67294726 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -11,13 +11,15 @@ COPY package.json ./ COPY pnpm-lock.yaml ./ +COPY pnpm-lock.yaml ./ + RUN npm install -g pnpm && pnpm install COPY . . RUN echo "VITE_MONDEY_API_URL=${MONDEY_API_URL}" > .env && pnpm run build -FROM nginx:1.27.1 +FROM nginx:1.27.3 COPY --from=builder /app/build /usr/share/nginx/html diff --git a/frontend/package.json b/frontend/package.json index b2c4164d..ecaa58cc 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -38,6 +38,7 @@ "dependencies": { "@hey-api/client-fetch": "0.4.3", "@unovis/ts": "1.5.0-beta.0", + "cdigit": "^4.0.2", "iso-639-1": "3.1.3", "svelte-dnd-action": "^0.9.52", "svelte-i18n": "^4.0.1" diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml index 6eb37861..3e1ee092 100644 --- a/frontend/pnpm-lock.yaml +++ b/frontend/pnpm-lock.yaml @@ -14,6 +14,9 @@ importers: '@unovis/ts': specifier: 1.5.0-beta.0 version: 1.5.0-beta.0 + cdigit: + specifier: ^4.0.2 + version: 4.0.2 iso-639-1: specifier: 3.1.3 version: 3.1.3 @@ -1183,6 +1186,10 @@ packages: caniuse-lite@1.0.30001680: resolution: {integrity: sha512-rPQy70G6AGUMnbwS1z6Xg+RkHYPAi18ihs47GH0jcxIG7wArmPgY3XbS2sRdBbxJljp3thdT8BIqv9ccCypiPA==} + cdigit@4.0.2: + resolution: {integrity: sha512-GGeU0Khic9vrwipOZ5p9Hg7PRwK9sBM+e2NtnJJPoJVWiWj14FMn61FokgAfaXfwaQoYxm6XENdHy+u3pPUXIg==} + hasBin: true + chai@5.1.2: resolution: {integrity: sha512-aGtmf24DW6MLHHG5gCx4zaI3uBq3KRtxeVs0DjFH6Z0rDNbsvTxFASFvdj79pxjxZ8/5u3PIiN3IwEIQkiiuPw==} engines: {node: '>=12'} @@ -1225,6 +1232,10 @@ packages: resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==} engines: {node: '>= 0.8'} + commander@10.0.1: + resolution: {integrity: sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==} + engines: {node: '>=14'} + commander@12.1.0: resolution: {integrity: sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==} engines: {node: '>=18'} @@ -3931,6 +3942,10 @@ snapshots: caniuse-lite@1.0.30001680: {} + cdigit@4.0.2: + dependencies: + commander: 10.0.1 + chai@5.1.2: dependencies: assertion-error: 2.0.1 @@ -3986,6 +4001,8 @@ snapshots: dependencies: delayed-stream: 1.0.0 + commander@10.0.1: {} + commander@12.1.0: {} commander@2.20.3: {} diff --git a/frontend/src/lib/client/schemas.gen.ts b/frontend/src/lib/client/schemas.gen.ts index b16112d1..0c52f2b5 100644 --- a/frontend/src/lib/client/schemas.gen.ts +++ b/frontend/src/lib/client/schemas.gen.ts @@ -860,6 +860,18 @@ export const QuestionTextPublicSchema = { title: 'QuestionTextPublic' } as const; +export const ResearchGroupSchema = { + properties: { + id: { + type: 'integer', + title: 'Id' + } + }, + type: 'object', + required: ['id'], + title: 'ResearchGroup' +} as const; + export const SubmittedMilestoneImagePublicSchema = { properties: { id: { @@ -965,6 +977,30 @@ export const UserCreateSchema = { ], title: 'Is Researcher', default: false + }, + full_data_access: { + anyOf: [ + { + type: 'boolean' + }, + { + type: 'null' + } + ], + title: 'Full Data Access', + default: false + }, + research_group_id: { + anyOf: [ + { + type: 'integer' + }, + { + type: 'null' + } + ], + title: 'Research Group Id', + default: 0 } }, type: 'object', @@ -1126,10 +1162,18 @@ export const UserReadSchema = { is_researcher: { type: 'boolean', title: 'Is Researcher' + }, + full_data_access: { + type: 'boolean', + title: 'Full Data Access' + }, + research_group_id: { + type: 'integer', + title: 'Research Group Id' } }, type: 'object', - required: ['id', 'email', 'is_researcher'], + required: ['id', 'email', 'is_researcher', 'full_data_access', 'research_group_id'], title: 'UserRead' } as const; @@ -1201,6 +1245,28 @@ export const UserUpdateSchema = { } ], title: 'Is Researcher' + }, + full_data_access: { + anyOf: [ + { + type: 'boolean' + }, + { + type: 'null' + } + ], + title: 'Full Data Access' + }, + research_group_id: { + anyOf: [ + { + type: 'integer' + }, + { + type: 'null' + } + ], + title: 'Research Group Id' } }, type: 'object', diff --git a/frontend/src/lib/client/services.gen.ts b/frontend/src/lib/client/services.gen.ts index 231f1033..db01f166 100644 --- a/frontend/src/lib/client/services.gen.ts +++ b/frontend/src/lib/client/services.gen.ts @@ -1,7 +1,7 @@ // This file is auto-generated by @hey-api/openapi-ts import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-fetch'; -import type { GetLanguagesError, GetLanguagesResponse, GetMilestonesError, GetMilestonesResponse, GetMilestoneData, GetMilestoneError, GetMilestoneResponse, GetMilestoneGroupsData, GetMilestoneGroupsError, GetMilestoneGroupsResponse, SubmitMilestoneImageData, SubmitMilestoneImageError, SubmitMilestoneImageResponse, GetUserQuestionsError, GetUserQuestionsResponse, GetChildQuestionsError, GetChildQuestionsResponse, CreateLanguageData, CreateLanguageError, CreateLanguageResponse, DeleteLanguageData, DeleteLanguageError, DeleteLanguageResponse, UpdateI18NData, UpdateI18NError, UpdateI18NResponse, GetMilestoneGroupsAdminError, GetMilestoneGroupsAdminResponse, CreateMilestoneGroupAdminError, CreateMilestoneGroupAdminResponse, UpdateMilestoneGroupAdminData, UpdateMilestoneGroupAdminError, UpdateMilestoneGroupAdminResponse, DeleteMilestoneGroupAdminData, DeleteMilestoneGroupAdminError, DeleteMilestoneGroupAdminResponse, OrderMilestoneGroupsAdminData, OrderMilestoneGroupsAdminError, OrderMilestoneGroupsAdminResponse, UploadMilestoneGroupImageData, UploadMilestoneGroupImageError, UploadMilestoneGroupImageResponse, CreateMilestoneData, CreateMilestoneError, CreateMilestoneResponse, UpdateMilestoneData, UpdateMilestoneError, UpdateMilestoneResponse, DeleteMilestoneData, DeleteMilestoneError, DeleteMilestoneResponse, OrderMilestonesAdminData, OrderMilestonesAdminError, OrderMilestonesAdminResponse, UploadMilestoneImageData, UploadMilestoneImageError, UploadMilestoneImageResponse, DeleteMilestoneImageData, DeleteMilestoneImageError, DeleteMilestoneImageResponse, GetSubmittedMilestoneImagesError, GetSubmittedMilestoneImagesResponse, ApproveSubmittedMilestoneImageData, ApproveSubmittedMilestoneImageError, ApproveSubmittedMilestoneImageResponse, DeleteSubmittedMilestoneImageData, DeleteSubmittedMilestoneImageError, DeleteSubmittedMilestoneImageResponse, GetMilestoneAgeScoresData, GetMilestoneAgeScoresError, GetMilestoneAgeScoresResponse, GetUserQuestionsAdminError, GetUserQuestionsAdminResponse, UpdateUserQuestionData, UpdateUserQuestionError, UpdateUserQuestionResponse, CreateUserQuestionError, CreateUserQuestionResponse, DeleteUserQuestionData, DeleteUserQuestionError, DeleteUserQuestionResponse, OrderUserQuestionsAdminData, OrderUserQuestionsAdminError, OrderUserQuestionsAdminResponse, GetChildQuestionsAdminError, GetChildQuestionsAdminResponse, UpdateChildQuestionData, UpdateChildQuestionError, UpdateChildQuestionResponse, CreateChildQuestionError, CreateChildQuestionResponse, DeleteChildQuestionData, DeleteChildQuestionError, DeleteChildQuestionResponse, OrderChildQuestionsAdminData, OrderChildQuestionsAdminError, OrderChildQuestionsAdminResponse, GetUsersError, GetUsersResponse, UsersCurrentUserError, UsersCurrentUserResponse, UsersPatchCurrentUserData, UsersPatchCurrentUserError, UsersPatchCurrentUserResponse, UsersUserData, UsersUserError, UsersUserResponse, UsersPatchUserData, UsersPatchUserError, UsersPatchUserResponse, UsersDeleteUserData, UsersDeleteUserError, UsersDeleteUserResponse, GetChildrenError, GetChildrenResponse, UpdateChildData, UpdateChildError, UpdateChildResponse, CreateChildData, CreateChildError, CreateChildResponse, GetChildData, GetChildError, GetChildResponse, DeleteChildData, DeleteChildError, DeleteChildResponse, GetChildImageData, GetChildImageError, GetChildImageResponse, UploadChildImageData, UploadChildImageError, UploadChildImageResponse, DeleteChildImageData, DeleteChildImageError, DeleteChildImageResponse, GetCurrentMilestoneAnswerSessionData, GetCurrentMilestoneAnswerSessionError, GetCurrentMilestoneAnswerSessionResponse, UpdateMilestoneAnswerData, UpdateMilestoneAnswerError, UpdateMilestoneAnswerResponse, GetCurrentUserAnswersError, GetCurrentUserAnswersResponse, UpdateCurrentUserAnswersData, UpdateCurrentUserAnswersError, UpdateCurrentUserAnswersResponse, GetCurrentChildAnswersData, GetCurrentChildAnswersError, GetCurrentChildAnswersResponse, UpdateCurrentChildAnswersData, UpdateCurrentChildAnswersError, UpdateCurrentChildAnswersResponse, GetExpiredMilestoneAnswerSessionsData, GetExpiredMilestoneAnswerSessionsError, GetExpiredMilestoneAnswerSessionsResponse, GetMilestonegroupsForSessionData, GetMilestonegroupsForSessionError, GetMilestonegroupsForSessionResponse, GetSummaryFeedbackForAnswersessionData, GetSummaryFeedbackForAnswersessionError, GetSummaryFeedbackForAnswersessionResponse, GetDetailedFeedbackForAnswersessionData, GetDetailedFeedbackForAnswersessionError, GetDetailedFeedbackForAnswersessionResponse, AuthCookieLoginData, AuthCookieLoginError, AuthCookieLoginResponse, AuthCookieLogoutError, AuthCookieLogoutResponse, RegisterRegisterData, RegisterRegisterError, RegisterRegisterResponse, ResetForgotPasswordData, ResetForgotPasswordError, ResetForgotPasswordResponse, ResetResetPasswordData, ResetResetPasswordError, ResetResetPasswordResponse, VerifyRequestTokenData, VerifyRequestTokenError, VerifyRequestTokenResponse, VerifyVerifyData, VerifyVerifyError, VerifyVerifyResponse, AuthError, AuthResponse } from './types.gen'; +import type { GetLanguagesError, GetLanguagesResponse, GetMilestonesError, GetMilestonesResponse, GetMilestoneData, GetMilestoneError, GetMilestoneResponse, GetMilestoneGroupsData, GetMilestoneGroupsError, GetMilestoneGroupsResponse, SubmitMilestoneImageData, SubmitMilestoneImageError, SubmitMilestoneImageResponse, GetUserQuestionsError, GetUserQuestionsResponse, GetChildQuestionsError, GetChildQuestionsResponse, CreateLanguageData, CreateLanguageError, CreateLanguageResponse, DeleteLanguageData, DeleteLanguageError, DeleteLanguageResponse, UpdateI18NData, UpdateI18NError, UpdateI18NResponse, GetMilestoneGroupsAdminError, GetMilestoneGroupsAdminResponse, CreateMilestoneGroupAdminError, CreateMilestoneGroupAdminResponse, UpdateMilestoneGroupAdminData, UpdateMilestoneGroupAdminError, UpdateMilestoneGroupAdminResponse, DeleteMilestoneGroupAdminData, DeleteMilestoneGroupAdminError, DeleteMilestoneGroupAdminResponse, OrderMilestoneGroupsAdminData, OrderMilestoneGroupsAdminError, OrderMilestoneGroupsAdminResponse, UploadMilestoneGroupImageData, UploadMilestoneGroupImageError, UploadMilestoneGroupImageResponse, CreateMilestoneData, CreateMilestoneError, CreateMilestoneResponse, UpdateMilestoneData, UpdateMilestoneError, UpdateMilestoneResponse, DeleteMilestoneData, DeleteMilestoneError, DeleteMilestoneResponse, OrderMilestonesAdminData, OrderMilestonesAdminError, OrderMilestonesAdminResponse, UploadMilestoneImageData, UploadMilestoneImageError, UploadMilestoneImageResponse, DeleteMilestoneImageData, DeleteMilestoneImageError, DeleteMilestoneImageResponse, GetSubmittedMilestoneImagesError, GetSubmittedMilestoneImagesResponse, ApproveSubmittedMilestoneImageData, ApproveSubmittedMilestoneImageError, ApproveSubmittedMilestoneImageResponse, DeleteSubmittedMilestoneImageData, DeleteSubmittedMilestoneImageError, DeleteSubmittedMilestoneImageResponse, GetMilestoneAgeScoresData, GetMilestoneAgeScoresError, GetMilestoneAgeScoresResponse, GetUserQuestionsAdminError, GetUserQuestionsAdminResponse, UpdateUserQuestionData, UpdateUserQuestionError, UpdateUserQuestionResponse, CreateUserQuestionError, CreateUserQuestionResponse, DeleteUserQuestionData, DeleteUserQuestionError, DeleteUserQuestionResponse, OrderUserQuestionsAdminData, OrderUserQuestionsAdminError, OrderUserQuestionsAdminResponse, GetChildQuestionsAdminError, GetChildQuestionsAdminResponse, UpdateChildQuestionData, UpdateChildQuestionError, UpdateChildQuestionResponse, CreateChildQuestionError, CreateChildQuestionResponse, DeleteChildQuestionData, DeleteChildQuestionError, DeleteChildQuestionResponse, OrderChildQuestionsAdminData, OrderChildQuestionsAdminError, OrderChildQuestionsAdminResponse, GetUsersError, GetUsersResponse, GetResearchGroupsError, GetResearchGroupsResponse, CreateResearchGroupData, CreateResearchGroupError, CreateResearchGroupResponse, DeleteResearchGroupData, DeleteResearchGroupError, DeleteResearchGroupResponse, UsersCurrentUserError, UsersCurrentUserResponse, UsersPatchCurrentUserData, UsersPatchCurrentUserError, UsersPatchCurrentUserResponse, UsersUserData, UsersUserError, UsersUserResponse, UsersPatchUserData, UsersPatchUserError, UsersPatchUserResponse, UsersDeleteUserData, UsersDeleteUserError, UsersDeleteUserResponse, GetChildrenError, GetChildrenResponse, UpdateChildData, UpdateChildError, UpdateChildResponse, CreateChildData, CreateChildError, CreateChildResponse, GetChildData, GetChildError, GetChildResponse, DeleteChildData, DeleteChildError, DeleteChildResponse, GetChildImageData, GetChildImageError, GetChildImageResponse, UploadChildImageData, UploadChildImageError, UploadChildImageResponse, DeleteChildImageData, DeleteChildImageError, DeleteChildImageResponse, GetCurrentMilestoneAnswerSessionData, GetCurrentMilestoneAnswerSessionError, GetCurrentMilestoneAnswerSessionResponse, UpdateMilestoneAnswerData, UpdateMilestoneAnswerError, UpdateMilestoneAnswerResponse, GetCurrentUserAnswersError, GetCurrentUserAnswersResponse, UpdateCurrentUserAnswersData, UpdateCurrentUserAnswersError, UpdateCurrentUserAnswersResponse, GetCurrentChildAnswersData, GetCurrentChildAnswersError, GetCurrentChildAnswersResponse, UpdateCurrentChildAnswersData, UpdateCurrentChildAnswersError, UpdateCurrentChildAnswersResponse, GetExpiredMilestoneAnswerSessionsData, GetExpiredMilestoneAnswerSessionsError, GetExpiredMilestoneAnswerSessionsResponse, GetMilestonegroupsForSessionData, GetMilestonegroupsForSessionError, GetMilestonegroupsForSessionResponse, GetSummaryFeedbackForAnswersessionData, GetSummaryFeedbackForAnswersessionError, GetSummaryFeedbackForAnswersessionResponse, GetDetailedFeedbackForAnswersessionData, GetDetailedFeedbackForAnswersessionError, GetDetailedFeedbackForAnswersessionResponse, AuthCookieLoginData, AuthCookieLoginError, AuthCookieLoginResponse, AuthCookieLogoutError, AuthCookieLogoutResponse, RegisterRegisterData, RegisterRegisterError, RegisterRegisterResponse, ResetForgotPasswordData, ResetForgotPasswordError, ResetForgotPasswordResponse, ResetResetPasswordData, ResetResetPasswordError, ResetResetPasswordResponse, VerifyRequestTokenData, VerifyRequestTokenError, VerifyRequestTokenResponse, VerifyVerifyData, VerifyVerifyError, VerifyVerifyResponse, AuthError, AuthResponse } from './types.gen'; export const client = createClient(createConfig()); @@ -390,6 +390,36 @@ export const getUsers = (options?: Options }); }; +/** + * Get Research Groups + */ +export const getResearchGroups = (options?: Options) => { + return (options?.client ?? client).get({ + ...options, + url: '/admin/research-groups/' + }); +}; + +/** + * Create Research Group + */ +export const createResearchGroup = (options: Options) => { + return (options?.client ?? client).post({ + ...options, + url: '/admin/research-groups/{user_id}' + }); +}; + +/** + * Delete Research Group + */ +export const deleteResearchGroup = (options: Options) => { + return (options?.client ?? client).delete({ + ...options, + url: '/admin/research-groups/{research_group_id}' + }); +}; + /** * Users:Current User */ diff --git a/frontend/src/lib/client/types.gen.ts b/frontend/src/lib/client/types.gen.ts index 9838cc67..21c31396 100644 --- a/frontend/src/lib/client/types.gen.ts +++ b/frontend/src/lib/client/types.gen.ts @@ -221,6 +221,10 @@ export type QuestionTextPublic = { options?: string; }; +export type ResearchGroup = { + id: number; +}; + export type SubmittedMilestoneImagePublic = { id: number; milestone_id: number; @@ -240,6 +244,8 @@ export type UserCreate = { is_superuser?: (boolean | null); is_verified?: (boolean | null); is_researcher?: (boolean | null); + full_data_access?: (boolean | null); + research_group_id?: (number | null); }; export type UserQuestionAdmin = { @@ -279,6 +285,8 @@ export type UserRead = { is_superuser?: boolean; is_verified?: boolean; is_researcher: boolean; + full_data_access: boolean; + research_group_id: number; }; export type UserUpdate = { @@ -288,6 +296,8 @@ export type UserUpdate = { is_superuser?: (boolean | null); is_verified?: (boolean | null); is_researcher?: (boolean | null); + full_data_access?: (boolean | null); + research_group_id?: (number | null); }; export type ValidationError = { @@ -584,6 +594,30 @@ export type GetUsersResponse = (Array); export type GetUsersError = unknown; +export type GetResearchGroupsResponse = (Array); + +export type GetResearchGroupsError = unknown; + +export type CreateResearchGroupData = { + path: { + user_id: number; + }; +}; + +export type CreateResearchGroupResponse = (ResearchGroup); + +export type CreateResearchGroupError = (HTTPValidationError); + +export type DeleteResearchGroupData = { + path: { + research_group_id: number; + }; +}; + +export type DeleteResearchGroupResponse = (unknown); + +export type DeleteResearchGroupError = (HTTPValidationError); + export type UsersCurrentUserResponse = (UserRead); export type UsersCurrentUserError = (unknown); diff --git a/frontend/src/lib/components/Admin/Users.svelte b/frontend/src/lib/components/Admin/Users.svelte index e61a45cc..2e372b85 100644 --- a/frontend/src/lib/components/Admin/Users.svelte +++ b/frontend/src/lib/components/Admin/Users.svelte @@ -3,6 +3,8 @@ + +
+ +
diff --git a/frontend/src/lib/components/FrontPageCard.svelte b/frontend/src/lib/components/FrontPageCard.svelte index 785dfc20..0677a299 100644 --- a/frontend/src/lib/components/FrontPageCard.svelte +++ b/frontend/src/lib/components/FrontPageCard.svelte @@ -10,7 +10,7 @@ import { _ } from "svelte-i18n";

{$_("frontpage.summary")}

{$_("frontpage.toolTip")}
diff --git a/frontend/src/lib/components/UserLogin.svelte b/frontend/src/lib/components/UserLogin.svelte index 4de555ad..c44d27ac 100644 --- a/frontend/src/lib/components/UserLogin.svelte +++ b/frontend/src/lib/components/UserLogin.svelte @@ -129,7 +129,7 @@ let alertMessage: string = $state($_("login.badCredentials")); >{$_("login.notRegistered")} {$_("login.registerNew")} diff --git a/frontend/src/lib/components/UserRegistration.svelte b/frontend/src/lib/components/UserRegistration.svelte index 383358c0..0319200d 100644 --- a/frontend/src/lib/components/UserRegistration.svelte +++ b/frontend/src/lib/components/UserRegistration.svelte @@ -2,51 +2,43 @@ import { registerRegister } from "$lib/client/services.gen"; import { type RegisterRegisterData } from "$lib/client/types.gen"; import AlertMessage from "$lib/components/AlertMessage.svelte"; +import ResearchCodeInput from "$lib/components/DataInput/ResearchCodeInput.svelte"; import UserVerify from "$lib/components/UserVerify.svelte"; import { preventDefault } from "$lib/util"; -import { Button, Card, Heading, Input, Label, Select } from "flowbite-svelte"; +import { Button, Card, Heading, Input, Label } from "flowbite-svelte"; import { _ } from "svelte-i18n"; async function submitData(): Promise { - const equalPW = password !== "" && password === passwordconfirm; - const userData: RegisterRegisterData = { body: { email: email, password: password, is_active: true, - is_superuser: false, - is_researcher: false, + research_group_id: Number(researchCode), }, }; - if (equalPW) { - userData.body.is_researcher = role === $_("registration.researcherRole"); - userData.body.is_superuser = role === $_("registration.adminRole"); - - const result = await registerRegister(userData); + const result = await registerRegister(userData); - if (result.error) { - console.log("error: ", result.response.status, result.error.detail); - alertMessage = `${$_("registration.alertMessageError")}: ${result.error.detail}`; - showAlert = true; - } else { - console.log("successful transmission: ", result.response.status); - success = true; - } - } else { - console.log("passwords not equal: "); + if (result.error) { + console.log("error: ", result.response.status, result.error.detail); + alertMessage = `${$_("registration.alertMessageError")}: ${result.error.detail}`; showAlert = true; - alertMessage = $_("registration.alertMessagePasswords"); + } else { + console.log("successful transmission: ", result.response.status); + success = true; } } -let email = ""; -let password = ""; -let passwordconfirm = ""; -let role: string = $_("registration.observerRole"); -let showAlert = false; -let success = false; -let alertMessage = $_("registration.alertMessageMissing"); +let email = $state(""); +let password = $state(""); +let passwordConfirm = $state(""); +let showAlert = $state(false); +let success = $state(false); +let alertMessage = $state($_("registration.alertMessageMissing")); +let researchCodeValid = $state(false); +let passwordValid = $derived(password !== "" && password === passwordConfirm); + +let { researchCode = "" }: { researchCode?: string } = $props(); @@ -85,6 +77,7 @@ let alertMessage = $_("registration.alertMessageMissing"); required type="email" id="email" + autocomplete="email" placeholder={$_("registration.emailLabel")} /> @@ -100,6 +93,7 @@ let alertMessage = $_("registration.alertMessageMissing"); required type="password" id="password" + autocomplete="new-password" placeholder={$_("registration.passwordLabel")} /> @@ -111,38 +105,23 @@ let alertMessage = $_("registration.alertMessageMissing"); >
- -
-