Browse Source

Fixed changed password error key mismatch

pull/14823/head
Maksym Tsymbarov 9 months ago
committed by Vladyslav Prykhodko
parent
commit
590d14ccf0
  1. 2
      ui-ngx/src/app/modules/home/pages/security/security.component.html
  2. 34
      ui-ngx/src/app/modules/home/pages/security/security.component.ts

2
ui-ngx/src/app/modules/home/pages/security/security.component.html

@ -54,7 +54,7 @@
<mat-label translate>profile.current-password</mat-label> <mat-label translate>profile.current-password</mat-label>
<input matInput type="password" name="current-password" formControlName="currentPassword" autocomplete="current-password"/> <input matInput type="password" name="current-password" formControlName="currentPassword" autocomplete="current-password"/>
<tb-toggle-password [class.!hidden]="!changePassword.get('currentPassword').dirty && !changePassword.get('currentPassword').touched" matSuffix></tb-toggle-password> <tb-toggle-password [class.!hidden]="!changePassword.get('currentPassword').dirty && !changePassword.get('currentPassword').touched" matSuffix></tb-toggle-password>
<mat-error *ngIf="changePassword.get('currentPassword').hasError('passwordsNotMatch')"> <mat-error *ngIf="changePassword.get('currentPassword').hasError('differencePassword')">
{{ 'security.password-requirement.incorrect-password-try-again' | translate }} {{ 'security.password-requirement.incorrect-password-try-again' | translate }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>

34
ui-ngx/src/app/modules/home/pages/security/security.component.ts

@ -333,22 +333,24 @@ export class SecurityComponent extends PageComponent implements OnInit, OnDestro
onChangePassword(form: FormGroupDirective): void { onChangePassword(form: FormGroupDirective): void {
if (this.changePassword.valid) { if (this.changePassword.valid) {
this.authService.changePassword(this.changePassword.get('currentPassword').value, this.authService.changePassword(this.changePassword.get('currentPassword').value,
this.changePassword.get('newPassword').value, {ignoreErrors: true}).subscribe(() => { this.changePassword.get('newPassword').value, {ignoreErrors: true}).subscribe({
this.discardChanges(form); next: () => {
}, this.discardChanges(form);
(error) => { },
if (error.status === 400 && error.error.message === 'Current password doesn\'t match!') { error: (error) => {
this.changePassword.get('currentPassword').setErrors({differencePassword: true}); if (error.status === 400 && error.error.message === 'Current password doesn\'t match!') {
} else if (error.status === 400 && error.error.message.startsWith('Password must')) { this.changePassword.get('currentPassword').setErrors({ differencePassword: true });
this.loadPasswordPolicy(); } else if (error.status === 400 && error.error.message.startsWith('Password must')) {
} else if (error.status === 400 && error.error.message.startsWith('Password was already used')) { this.loadPasswordPolicy();
this.changePassword.get('newPassword').setErrors({alreadyUsed: error.error.message}); } else if (error.status === 400 && error.error.message.startsWith('Password was already used')) {
} else { this.changePassword.get('newPassword').setErrors({ alreadyUsed: error.error.message });
this.store.dispatch(new ActionNotificationShow({ } else {
message: error.error.message, this.store.dispatch(new ActionNotificationShow({
type: 'error', message: error.error.message,
target: 'changePassword' type: 'error',
})); target: 'changePassword'
}));
}
} }
}); });
} else { } else {

Loading…
Cancel
Save