From a890d1e0d30851741392e6e7f14acffe685d28e0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 26 Sep 2018 16:28:15 +0200 Subject: Check current password on server side --- .../my-account-change-password.component.html | 10 +++---- .../my-account-change-password.component.ts | 33 +++++++++------------- 2 files changed, 19 insertions(+), 24 deletions(-) (limited to 'client/src/app/+my-account') diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html index 00b6d20fa..ae797d1bc 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html +++ b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.html @@ -1,14 +1,14 @@
{{ error }}
-
+ -
- {{ formErrors['old-password'] }} +
+ {{ formErrors['current-password'] }}
confirmPasswordControl.setErrors({ matchPassword: true })) } - checkPassword () { - this.error = null - const oldPassword = this.form.value[ 'old-password' ] + changePassword () { + const currentPassword = this.form.value[ 'current-password' ] + const newPassword = this.form.value[ 'new-password' ] - // compare old password - this.authService.login(this.user.account.name, oldPassword) - .subscribe( - () => this.changePassword(), - err => { - if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect old password.') - else this.error = err.message - } - ) - - } - - private changePassword () { - this.userService.changePassword(this.form.value[ 'new-password' ]).subscribe( + this.userService.changePassword(currentPassword, newPassword).subscribe( () => { this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')) this.form.reset() + this.error = null }, - err => this.error = err.message + err => { + if (err.status === 401) { + this.error = this.i18n('You current password is invalid.') + return + } + + this.error = err.message + } ) } } -- cgit v1.2.3