From 0b9f32504578b43c3d855122f482b2ffca6a45b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Paul=20Ton=C4=8Dik?= Date: Fri, 3 Jul 2026 13:10:16 +0200 Subject: [PATCH 1/2] feat(auth): added change password functionality in frontend --- service/src/main/inse/auth/service.py | 6 + webapp/src/app/api/.openapi-generator/FILES | 3 + webapp/src/app/api/api/topics.service.ts | 75 ++++++++++ webapp/src/app/api/model/keywordTopicMatch.ts | 17 +++ .../app/api/model/keywordsTopicsRequest.ts | 18 +++ .../app/api/model/keywordsTopicsResponse.ts | 19 +++ webapp/src/app/api/model/models.ts | 3 + .../modules/account/account.component.html | 55 ++++++- .../modules/account/account.component.scss | 22 +++ .../app/modules/account/account.component.ts | 139 +++++++++++++++++- .../app/shared/services/credential.service.ts | 11 +- 11 files changed, 363 insertions(+), 5 deletions(-) create mode 100644 webapp/src/app/api/model/keywordTopicMatch.ts create mode 100644 webapp/src/app/api/model/keywordsTopicsRequest.ts create mode 100644 webapp/src/app/api/model/keywordsTopicsResponse.ts diff --git a/service/src/main/inse/auth/service.py b/service/src/main/inse/auth/service.py index 3c24086e..d822d92c 100644 --- a/service/src/main/inse/auth/service.py +++ b/service/src/main/inse/auth/service.py @@ -1071,6 +1071,10 @@ def change_password( account = _get_active_account(session, access_token.effective_account_id) if not _verify_password(current_password, account.password_hash): + logger.warning( + "Password change failed: current password is incorrect for account %s", + account.id, + ) raise HTTPException( status_code=status.HTTP_403_FORBIDDEN, detail="Current password is incorrect.", @@ -1082,4 +1086,6 @@ def change_password( session.add(account) session.commit() + logger.info("Password changed successfully for account %s", account.id) + return {"status": "ok"} diff --git a/webapp/src/app/api/.openapi-generator/FILES b/webapp/src/app/api/.openapi-generator/FILES index b7a3c1d3..f9eb4ffa 100644 --- a/webapp/src/app/api/.openapi-generator/FILES +++ b/webapp/src/app/api/.openapi-generator/FILES @@ -121,7 +121,10 @@ model/institutionNetworkNode.ts model/institutionPage.ts model/institutionsListResponse.ts model/ipcClassification.ts +model/keywordTopicMatch.ts model/keywords.ts +model/keywordsTopicsRequest.ts +model/keywordsTopicsResponse.ts model/latitude.ts model/location.ts model/loginResponse.ts diff --git a/webapp/src/app/api/api/topics.service.ts b/webapp/src/app/api/api/topics.service.ts index 6f17a01e..ef7b0c7f 100644 --- a/webapp/src/app/api/api/topics.service.ts +++ b/webapp/src/app/api/api/topics.service.ts @@ -21,6 +21,10 @@ import { AutocompleteResponse } from '../model/autocompleteResponse'; // @ts-ignore import { HTTPValidationError } from '../model/hTTPValidationError'; // @ts-ignore +import { KeywordsTopicsRequest } from '../model/keywordsTopicsRequest'; +// @ts-ignore +import { KeywordsTopicsResponse } from '../model/keywordsTopicsResponse'; +// @ts-ignore import { TopicsListResponse } from '../model/topicsListResponse'; // @ts-ignore @@ -433,4 +437,75 @@ export class TopicsService extends BaseService { ); } + /** + * Batch semantic / vector search for multiple keywords. + * @endpoint post /api/topics/vector-search/batch + * @param keywordsTopicsRequest + * @param searchType Search approach: \'hybrid\' or \'semantic\'. + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public vectorSearchTopicsBatch(keywordsTopicsRequest: KeywordsTopicsRequest, searchType?: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public vectorSearchTopicsBatch(keywordsTopicsRequest: KeywordsTopicsRequest, searchType?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public vectorSearchTopicsBatch(keywordsTopicsRequest: KeywordsTopicsRequest, searchType?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public vectorSearchTopicsBatch(keywordsTopicsRequest: KeywordsTopicsRequest, searchType?: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + if (keywordsTopicsRequest === null || keywordsTopicsRequest === undefined) { + throw new Error('Required parameter keywordsTopicsRequest was null or undefined when calling vectorSearchTopicsBatch.'); + } + + let localVarQueryParameters = new HttpParams({encoder: this.encoder}); + localVarQueryParameters = this.addToHttpParams(localVarQueryParameters, + searchType, 'searchType'); + + let localVarHeaders = this.defaultHeaders; + + const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ + 'application/json' + ]); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); + + const localVarTransferCache: boolean = options?.transferCache ?? true; + + + // to determine the Content-Type header + const consumes: string[] = [ + 'application/json' + ]; + const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); + if (httpContentTypeSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected); + } + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/api/topics/vector-search/batch`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request('post', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + body: keywordsTopicsRequest, + params: localVarQueryParameters, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), + reportProgress: reportProgress + } + ); + } + } diff --git a/webapp/src/app/api/model/keywordTopicMatch.ts b/webapp/src/app/api/model/keywordTopicMatch.ts new file mode 100644 index 00000000..f9c2ab49 --- /dev/null +++ b/webapp/src/app/api/model/keywordTopicMatch.ts @@ -0,0 +1,17 @@ +/** + * Innovation Search Engine API + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { Topic } from './topic'; + + +export interface KeywordTopicMatch { + keyword: string; + topic?: Topic | null; +} + diff --git a/webapp/src/app/api/model/keywordsTopicsRequest.ts b/webapp/src/app/api/model/keywordsTopicsRequest.ts new file mode 100644 index 00000000..8810bf5f --- /dev/null +++ b/webapp/src/app/api/model/keywordsTopicsRequest.ts @@ -0,0 +1,18 @@ +/** + * Innovation Search Engine API + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface KeywordsTopicsRequest { + /** + * List of keywords/sentences to query by similarity. + */ + keywords: Array; +} + diff --git a/webapp/src/app/api/model/keywordsTopicsResponse.ts b/webapp/src/app/api/model/keywordsTopicsResponse.ts new file mode 100644 index 00000000..4aee622f --- /dev/null +++ b/webapp/src/app/api/model/keywordsTopicsResponse.ts @@ -0,0 +1,19 @@ +/** + * Innovation Search Engine API + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ +import { KeywordTopicMatch } from './keywordTopicMatch'; + + +export interface KeywordsTopicsResponse { + /** + * Top matching topics for each keyword in the requested list. + */ + results: Array; +} + diff --git a/webapp/src/app/api/model/models.ts b/webapp/src/app/api/model/models.ts index e8a70f23..6876bbeb 100644 --- a/webapp/src/app/api/model/models.ts +++ b/webapp/src/app/api/model/models.ts @@ -98,7 +98,10 @@ export * from './institutionNetworkNode'; export * from './institutionPage'; export * from './institutionsListResponse'; export * from './ipcClassification'; +export * from './keywordTopicMatch'; export * from './keywords'; +export * from './keywordsTopicsRequest'; +export * from './keywordsTopicsResponse'; export * from './latitude'; export * from './location'; export * from './loginResponse'; diff --git a/webapp/src/app/modules/account/account.component.html b/webapp/src/app/modules/account/account.component.html index 7590acb3..da753236 100644 --- a/webapp/src/app/modules/account/account.component.html +++ b/webapp/src/app/modules/account/account.component.html @@ -16,5 +16,58 @@ - + +
+
Passwort ändern
+
+ + Altes Passwort + + @if (oldPasswordErrorMessage()) { + {{ oldPasswordErrorMessage() }} + } + + +
+ + Neues Passwort + + @if (newPasswordErrorMessage()) { + {{ newPasswordErrorMessage() }} + } + + + + Neues Passwort wiederholen + + @if (newPasswordRepeatErrorMessage()) { + {{ newPasswordRepeatErrorMessage() }} + } + +
+ + Passwörter anzeigen + +
+ +
+
diff --git a/webapp/src/app/modules/account/account.component.scss b/webapp/src/app/modules/account/account.component.scss index 25c46861..ff03e82e 100644 --- a/webapp/src/app/modules/account/account.component.scss +++ b/webapp/src/app/modules/account/account.component.scss @@ -42,3 +42,25 @@ font-weight: 600; color: var(--sg-text-muted); } + +.settings-tab { + padding: 1rem; + max-width: 50%; + display: flex; + flex-direction: column; + gap: 1rem; +} + +.change-password-form { + display: flex; + flex-direction: column; + gap: 1.5rem; +} + +.new-password-fields { + display: flex; + gap: 1rem; + > mat-form-field { + width: 100%; + } +} diff --git a/webapp/src/app/modules/account/account.component.ts b/webapp/src/app/modules/account/account.component.ts index 7a953dee..d4a9b5aa 100644 --- a/webapp/src/app/modules/account/account.component.ts +++ b/webapp/src/app/modules/account/account.component.ts @@ -1,21 +1,156 @@ -import { Component, effect, input } from '@angular/core'; +import { + Component, + computed, + effect, + inject, + input, + signal, +} from '@angular/core'; import { AccountProfile, UserRole } from '../../api'; import { RolePipe } from '../../shared/pipes/role.pipe'; import { MatChipsModule } from '@angular/material/chips'; import { MatTabsModule } from '@angular/material/tabs'; import { MatDividerModule } from '@angular/material/divider'; +import { MatInputModule } from '@angular/material/input'; +import { FormsModule, ReactiveFormsModule } from '@angular/forms'; +import { + form, + FormField, + maxLength, + minLength, + required, + validate, + FormRoot, +} from '@angular/forms/signals'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatIconModule } from '@angular/material/icon'; +import { MatButtonModule } from '@angular/material/button'; +import { MatSlideToggleModule } from '@angular/material/slide-toggle'; +import { CredentialService } from '../../shared/services/credential.service'; +import { MatSnackBar } from '@angular/material/snack-bar'; + +interface ChangePasswordForm { + oldPassword: string; + newPassword: string; + newPasswordRepeat: string; + showPasswords: boolean; +} @Component({ selector: 'app-account', - imports: [RolePipe, MatChipsModule, MatTabsModule, MatDividerModule], + imports: [ + RolePipe, + MatChipsModule, + MatTabsModule, + MatDividerModule, + MatInputModule, + FormsModule, + ReactiveFormsModule, + MatFormFieldModule, + MatDividerModule, + MatIconModule, + MatButtonModule, + MatSlideToggleModule, + FormField, + FormRoot, + ], templateUrl: './account.component.html', styleUrl: './account.component.scss', }) export class AccountComponent { readonly accountProfile = input.required(); + private readonly _credentialService = inject(CredentialService); + private readonly _snackBar = inject(MatSnackBar); + roles: UserRole[] = []; + changePasswordModel = signal({ + oldPassword: '', + newPassword: '', + newPasswordRepeat: '', + showPasswords: false, + }); + + oldPasswordErrorMessage = computed(() => { + const errors = this.changePasswordForm.oldPassword().errors(); + return errors.length > 0 && errors[0].message ? errors[0].message : null; + }); + + newPasswordErrorMessage = computed(() => { + const errors = this.changePasswordForm.newPassword().errors(); + return errors.length > 0 && errors[0].message ? errors[0].message : null; + }); + + newPasswordRepeatErrorMessage = computed(() => { + const errors = this.changePasswordForm.newPasswordRepeat().errors(); + return errors.length > 0 && errors[0].message ? errors[0].message : null; + }); + + changePasswordForm = form( + this.changePasswordModel, + (schemaPath) => { + required(schemaPath.oldPassword, { + message: 'Altes Passwort ist erforderlich.', + }); + required(schemaPath.newPassword, { + message: 'Neues Passwort ist erforderlich.', + }); + required(schemaPath.newPasswordRepeat, { + message: 'Neues Passwort wiederholen ist erforderlich.', + }); + + minLength(schemaPath.newPassword, 8, { + message: 'Neues Passwort muss mindestens 8 Zeichen lang sein.', + }); + maxLength(schemaPath.newPassword, 64, { + message: 'Neues Passwort darf maximal 64 Zeichen lang sein.', + }); + + validate(schemaPath.newPasswordRepeat, ({ value, valueOf }) => { + const newPassword = valueOf(schemaPath.newPassword).trim(); + const newPasswordRepeat = value().trim(); + + if (newPassword !== newPasswordRepeat) { + return { + kind: 'passwordMismatch', + message: 'Passwörter stimmen nicht überein.', + }; + } + + return null; + }); + }, + { + submission: { + action: async (field) => { + const oldPassword = field.oldPassword().value().trim(); + const newPassword = field.newPassword().value().trim(); + + if (!oldPassword || !newPassword) { + return; + } + this._credentialService + .changePassword(oldPassword, newPassword) + .subscribe({ + error: (error) => { + console.error('Error changing password:', error); + this._snackBar.open( + 'Das alte Passwort ist nicht korrekt. Bitte versuchen Sie es erneut.', + 'OK', + { duration: 7000 }, + ); + }, + }); + }, + }, + }, + ); + + inputFieldType = computed(() => + this.changePasswordModel().showPasswords ? 'text' : 'password', + ); + constructor() { effect(() => { this.roles = [this.accountProfile().role]; diff --git a/webapp/src/app/shared/services/credential.service.ts b/webapp/src/app/shared/services/credential.service.ts index 8e72953f..f276073c 100644 --- a/webapp/src/app/shared/services/credential.service.ts +++ b/webapp/src/app/shared/services/credential.service.ts @@ -18,6 +18,7 @@ import { AccountProfile, } from '../../api'; import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Router } from '@angular/router'; type LogoutResult = 'logged-out' | 'stopped-impersonating'; type UnauthorizedRecoveryResult = @@ -66,7 +67,7 @@ export class CredentialService { private request = 0; - constructor() { + constructor(private readonly router: Router) { const data = localStorage.getItem(CredentialService.KEY_GRANT); const id = data ? (JSON.parse(data) as AccessToken) : undefined; if (id && new Date(id.expires_at).getTime() >= Date.now()) { @@ -212,6 +213,7 @@ export class CredentialService { this.login.next(''); this.email.next(''); this.organizationName.next(''); + this.router.navigate(['/login'], { replaceUrl: true }); } public handleUnauthorized(): Observable { @@ -260,8 +262,13 @@ export class CredentialService { { withCredentials: true }, ) .pipe( - tap(() => this.clearLocalAuthState()), + tap(() => { + this.clearLocalAuthState(); + }), map(() => undefined), + catchError((err) => { + throw err; + }), ); } From cac2d81b5cf9452c798f14b66fe5415a88c4e8a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Paul=20Ton=C4=8Dik?= Date: Fri, 3 Jul 2026 13:14:05 +0200 Subject: [PATCH 2/2] fix(auth): prevention for same old and new password --- service/src/main/inse/auth/service.py | 10 ++++++++++ .../src/app/modules/account/account.component.ts | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/service/src/main/inse/auth/service.py b/service/src/main/inse/auth/service.py index d822d92c..0af15a4b 100644 --- a/service/src/main/inse/auth/service.py +++ b/service/src/main/inse/auth/service.py @@ -1080,6 +1080,16 @@ def change_password( detail="Current password is incorrect.", ) + if current_password == new_password: + logger.warning( + "Password change failed: new password is the same as the current password for account %s", + account.id, + ) + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="New password cannot be the same as the current password.", + ) + account.password_hash = _hash_password(new_password) account.epoch += 1 diff --git a/webapp/src/app/modules/account/account.component.ts b/webapp/src/app/modules/account/account.component.ts index d4a9b5aa..8b3eec70 100644 --- a/webapp/src/app/modules/account/account.component.ts +++ b/webapp/src/app/modules/account/account.component.ts @@ -120,6 +120,21 @@ export class AccountComponent { return null; }); + + validate(schemaPath.newPassword, ({ value }) => { + const oldPassword = this.changePasswordModel().oldPassword.trim(); + const newPassword = value().trim(); + + if (oldPassword && newPassword && oldPassword === newPassword) { + return { + kind: 'passwordSameAsOld', + message: + 'Neues Passwort darf nicht dasselbe wie das alte Passwort sein.', + }; + } + + return null; + }); }, { submission: {