From acb7614c6ea275cca84f24afda4887c505117b93 Mon Sep 17 00:00:00 2001 From: Bastian Rihm Date: Fri, 1 Dec 2023 15:33:08 +0100 Subject: [PATCH] Display password change errors (#3056) --- .../gateways/error-mapping/error-map-utils.ts | 7 +++++-- .../account-dialog.component.ts | 20 +++++++++++++++---- .../reset-password-confirm.component.ts | 8 +++++++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/client/src/app/gateways/error-mapping/error-map-utils.ts b/client/src/app/gateways/error-mapping/error-map-utils.ts index c733e51b3b..381f39cf2e 100644 --- a/client/src/app/gateways/error-mapping/error-map-utils.ts +++ b/client/src/app/gateways/error-mapping/error-map-utils.ts @@ -2,6 +2,7 @@ import { marker as _ } from '@colsen1991/ngx-translate-extract-marker'; import { MeetingAction } from '../repositories/meetings'; import { MotionAction } from '../repositories/motions'; +import { UserAction } from '../repositories/users/user-action'; export class MapError { public constructor(private message: string) {} @@ -39,7 +40,7 @@ const VoteServiceErrorMap: ErrorMap = new ErrorMap([ [/is not allowed to vote/, _(`You do not have the permission to vote.`)] ]); -const MotionCreateForwardErrorMap: ErrorMap = new ErrorMap([[/(.*)/, input => new MapError(input)]]); +const MatchAllErrorMap: ErrorMap = new ErrorMap([[/(.*)/, input => new MapError(input)]]); const MeetingCreateErrorMap: ErrorMap = new ErrorMap([ [ /Only one of start_time and end_time is not allowed./, @@ -57,7 +58,9 @@ const getActionErrorMap: (data: any) => ErrorMap | null = data => { case MeetingAction.CREATE: return MeetingCreateErrorMap; case MotionAction.CREATE_FORWARDED: - return MotionCreateForwardErrorMap; + case UserAction.FORGET_PASSWORD_CONFIRM: + case UserAction.SET_PASSWORD_SELF: + return MatchAllErrorMap; default: return null; } diff --git a/client/src/app/site/modules/global-headbar/components/account-dialog/account-dialog.component.ts b/client/src/app/site/modules/global-headbar/components/account-dialog/account-dialog.component.ts index b07212fa53..ba9e7ef4bd 100644 --- a/client/src/app/site/modules/global-headbar/components/account-dialog/account-dialog.component.ts +++ b/client/src/app/site/modules/global-headbar/components/account-dialog/account-dialog.component.ts @@ -150,10 +150,22 @@ export class AccountDialogComponent extends BaseUiComponent implements OnInit { public async changePassword(): Promise { const { oldPassword, newPassword }: PasswordForm = this.userPasswordForm; - this.repo.setPasswordSelf(this.self!, oldPassword, newPassword).then(() => { - this.snackbar.open(this.translate.instant(`Password changed successfully!`), `Ok`); - this.changePasswordComponent.reset(); - }); + + this.repo + .setPasswordSelf(this.self!, oldPassword, newPassword) + .then(() => { + this.snackbar.open(this.translate.instant(`Password changed successfully!`), `Ok`); + this.changePasswordComponent.reset(); + }) + .catch(e => { + if (e?.message) { + this.snackbar.open(this.translate.instant(e.message), this.translate.instant(`OK`), { + duration: 0 + }); + } + + console.log(e); + }); } public async saveUserChanges(): Promise { diff --git a/client/src/app/site/pages/login/pages/reset-password-confirm/components/reset-password-confirm/reset-password-confirm.component.ts b/client/src/app/site/pages/login/pages/reset-password-confirm/components/reset-password-confirm/reset-password-confirm.component.ts index ba54412663..89c00f1686 100644 --- a/client/src/app/site/pages/login/pages/reset-password-confirm/components/reset-password-confirm/reset-password-confirm.component.ts +++ b/client/src/app/site/pages/login/pages/reset-password-confirm/components/reset-password-confirm/reset-password-confirm.component.ts @@ -85,7 +85,7 @@ export class ResetPasswordConfirmComponent extends BaseComponent implements OnIn authorization_token: this.token, new_password: this.newPasswordForm.get(`password`)!.value }); - // TODO: Does we get a response for displaying? + this.matSnackBar.open( this.translate.instant(`Your password has been reset successfully!`), this.translate.instant(`OK`), @@ -95,6 +95,12 @@ export class ResetPasswordConfirmComponent extends BaseComponent implements OnIn ); this.router.navigate([`/login`]); } catch (e) { + if (e?.message) { + this.matSnackBar.open(this.translate.instant(e.message), this.translate.instant(`OK`), { + duration: 0 + }); + } + console.log(`error`, e); } }