Merge branch 'dev' of nes.uni-due.de:lbs/smartguide into feature/keywords-analysis
LocationBasedServices/smartguide/pipeline/head This commit looks good
LocationBasedServices/smartguide/pipeline/pr-dev Build queued...

This commit is contained in:
2026-07-03 13:54:42 +02:00
7 changed files with 270 additions and 10 deletions
+16
View File
@@ -1071,15 +1071,31 @@ 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.",
)
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
session.add(account)
session.commit()
logger.info("Password changed successfully for account %s", account.id)
return {"status": "ok"}
+1 -1
View File
@@ -365,7 +365,7 @@ async def extract_keywords_stream_enriched(
KeywordsWsEvent(
type="status",
step="enriching",
message=f"Bearbeite keyword'{keyword_text}'",
message=f"Extracting topic for keyword '{keyword_text}'",
).model_dump()
)
task = asyncio.create_task(get_openalex_topic(level, idx, confirmed[level][idx].llm_keyword))
@@ -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,171 @@
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;
});
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: {
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];
@@ -651,18 +651,30 @@ export class KeywordsSearchComponent {
const manualKeywordSet = new Set(
this.manualKeywords().map((k) => this.normalizeKeyword(k)),
);
const validSelected = selected.filter((k) =>
manualKeywordSet.has(this.normalizeKeyword(k)),
const broadKeywordSet = new Set(
this.broadKeywords().map((k) => this.normalizeKeyword(k)),
);
const coarseKeywordSet = new Set(
this.coarseKeywords().map((k) => this.normalizeKeyword(k)),
);
const fineKeywordSet = new Set(
this.fineKeywords().map((k) => this.normalizeKeyword(k)),
);
const validSelected = selected.filter(
(k) =>
manualKeywordSet.has(this.normalizeKeyword(k)) ||
broadKeywordSet.has(this.normalizeKeyword(k)) ||
coarseKeywordSet.has(this.normalizeKeyword(k)) ||
fineKeywordSet.has(this.normalizeKeyword(k)),
);
const selectionWasTrimmed = validSelected.length !== selected.length;
this.selectedKeywords.set(this.uniqueKeywords(validSelected));
this.isRestoringState = false;
if (selectionWasTrimmed) {
this.updateQueryParams();
}
this.isRestoringState = false;
}
updateQueryParams(): void {
@@ -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;
}),
);
}