fix(frontend/auth): fixed change password form
LocationBasedServices/smartguide/pipeline/head This commit looks good

This commit is contained in:
Mats Paul Tončik
2026-07-07 10:58:10 +02:00
parent 1c6dbb540f
commit d26ddb8cb4
3 changed files with 40 additions and 15 deletions
@@ -63,7 +63,13 @@
[formField]="changePasswordForm.showPasswords"
>Passwörter anzeigen</mat-slide-toggle
>
<button mat-raised-button color="primary" type="submit">
<button
mat-raised-button
color="primary"
type="submit"
[disabled]="
changePasswordForm().invalid() || changePasswordForm().submitting()
">
Passwort ändern
</button>
</form>
@@ -28,6 +28,7 @@ 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';
import { Router } from '@angular/router';
interface ChangePasswordForm {
oldPassword: string;
@@ -62,6 +63,7 @@ export class AccountComponent {
private readonly _credentialService = inject(CredentialService);
private readonly _snackBar = inject(MatSnackBar);
private readonly _router = inject(Router);
roles: UserRole[] = [];
@@ -143,21 +145,36 @@ export class AccountComponent {
const newPassword = field.newPassword().value().trim();
if (!oldPassword || !newPassword) {
return;
}
try {
await this._credentialService.changePassword(
oldPassword,
newPassword,
);
} catch (error) {
console.error('Error changing password:', error);
this._snackBar.open(
'Fehler beim Ändern des Passworts. Bitte versuchen Sie es erneut.',
'OK',
{ duration: 7000 },
);
return {} as any;
}
this._credentialService
.changePassword(oldPassword, newPassword)
.subscribe({
next: () => {
this._credentialService.refreshAccessToken().subscribe({
next: () => {
this._router.navigate(['/dashboard']);
},
error: (error) => {
this._snackBar.open(
'Fehler beim Aktualisieren des Zugriffstokens. Bitte melden Sie sich erneut an.',
'OK',
{ duration: 7000 },
);
},
});
},
error: (error) => {
console.error('Error changing password:', error);
this._snackBar.open(
'Fehler beim Ändern des Passworts. Bitte versuchen Sie es erneut.',
'OK',
{ duration: 7000 },
);
},
});
return {} as any;
},
},
},
@@ -11,6 +11,8 @@ export class StatusPipe implements PipeTransform {
return 'Aktiv';
case 'INACTIVE':
return 'Inaktiv';
case 'DELETED':
return 'Gelöscht';
default:
return value;
}