feat(auth): added change password functionality in frontend
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/head This commit looks good
This commit is contained in:
@@ -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"}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<KeywordsTopicsResponse>;
|
||||
public vectorSearchTopicsBatch(keywordsTopicsRequest: KeywordsTopicsRequest, searchType?: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpResponse<KeywordsTopicsResponse>>;
|
||||
public vectorSearchTopicsBatch(keywordsTopicsRequest: KeywordsTopicsRequest, searchType?: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<HttpEvent<KeywordsTopicsResponse>>;
|
||||
public vectorSearchTopicsBatch(keywordsTopicsRequest: KeywordsTopicsRequest, searchType?: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable<any> {
|
||||
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,
|
||||
<any>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<KeywordsTopicsResponse>('post', `${basePath}${localVarPath}`,
|
||||
{
|
||||
context: localVarHttpContext,
|
||||
body: keywordsTopicsRequest,
|
||||
params: localVarQueryParameters,
|
||||
responseType: <any>responseType_,
|
||||
...(withCredentials ? { withCredentials } : {}),
|
||||
headers: localVarHeaders,
|
||||
observe: observe,
|
||||
...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}),
|
||||
reportProgress: reportProgress
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<string>;
|
||||
}
|
||||
|
||||
@@ -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<KeywordTopicMatch>;
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -16,5 +16,58 @@
|
||||
<mat-divider />
|
||||
|
||||
<mat-tab-group>
|
||||
<mat-tab label="Einstellungen"></mat-tab>
|
||||
<mat-tab label="Einstellungen">
|
||||
<div class="settings-tab">
|
||||
<h5>Passwort ändern</h5>
|
||||
<form class="change-password-form" [formRoot]="changePasswordForm">
|
||||
<mat-form-field subscriptSizing="dynamic">
|
||||
<mat-label>Altes Passwort</mat-label>
|
||||
<input
|
||||
matInput
|
||||
aria-label="Altes Passwort"
|
||||
[type]="inputFieldType()"
|
||||
[formField]="changePasswordForm.oldPassword" />
|
||||
@if (oldPasswordErrorMessage()) {
|
||||
<mat-error>{{ oldPasswordErrorMessage() }}</mat-error>
|
||||
}
|
||||
</mat-form-field>
|
||||
|
||||
<div class="new-password-fields">
|
||||
<mat-form-field subscriptSizing="dynamic">
|
||||
<mat-label>Neues Passwort</mat-label>
|
||||
<input
|
||||
matInput
|
||||
aria-label="Neues Passwort"
|
||||
[type]="inputFieldType()"
|
||||
[formField]="changePasswordForm.newPassword" />
|
||||
@if (newPasswordErrorMessage()) {
|
||||
<mat-error>{{ newPasswordErrorMessage() }}</mat-error>
|
||||
}
|
||||
</mat-form-field>
|
||||
|
||||
<mat-form-field subscriptSizing="dynamic">
|
||||
<mat-label>Neues Passwort wiederholen</mat-label>
|
||||
<input
|
||||
matInput
|
||||
aria-label="Neues Passwort wiederholen"
|
||||
[type]="inputFieldType()"
|
||||
[formField]="changePasswordForm.newPasswordRepeat" />
|
||||
@if (newPasswordRepeatErrorMessage()) {
|
||||
<mat-error>{{ newPasswordRepeatErrorMessage() }}</mat-error>
|
||||
}
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
<mat-slide-toggle
|
||||
labelPosition="before"
|
||||
[formField]="changePasswordForm.showPasswords"
|
||||
>Passwörter anzeigen</mat-slide-toggle
|
||||
>
|
||||
<button mat-raised-button color="primary" type="submit">
|
||||
Passwort ändern
|
||||
</button>
|
||||
</form>
|
||||
<mat-divider />
|
||||
</div>
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
|
||||
@@ -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%;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<AccountProfile>();
|
||||
|
||||
private readonly _credentialService = inject(CredentialService);
|
||||
private readonly _snackBar = inject(MatSnackBar);
|
||||
|
||||
roles: UserRole[] = [];
|
||||
|
||||
changePasswordModel = signal<ChangePasswordForm>({
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
newPasswordRepeat: '',
|
||||
showPasswords: false,
|
||||
});
|
||||
|
||||
oldPasswordErrorMessage = computed<string | null>(() => {
|
||||
const errors = this.changePasswordForm.oldPassword().errors();
|
||||
return errors.length > 0 && errors[0].message ? errors[0].message : null;
|
||||
});
|
||||
|
||||
newPasswordErrorMessage = computed<string | null>(() => {
|
||||
const errors = this.changePasswordForm.newPassword().errors();
|
||||
return errors.length > 0 && errors[0].message ? errors[0].message : null;
|
||||
});
|
||||
|
||||
newPasswordRepeatErrorMessage = computed<string | null>(() => {
|
||||
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];
|
||||
|
||||
@@ -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<UnauthorizedRecoveryResult> {
|
||||
@@ -260,8 +262,13 @@ export class CredentialService {
|
||||
{ withCredentials: true },
|
||||
)
|
||||
.pipe(
|
||||
tap(() => this.clearLocalAuthState()),
|
||||
tap(() => {
|
||||
this.clearLocalAuthState();
|
||||
}),
|
||||
map(() => undefined),
|
||||
catchError((err) => {
|
||||
throw err;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user