diff options
Diffstat (limited to 'client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts')
-rw-r--r-- | client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts index da0021df9..e5343b33d 100644 --- a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts +++ b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts | |||
@@ -30,7 +30,7 @@ export class MyAccountChangePasswordComponent extends FormReactive implements On | |||
30 | 30 | ||
31 | ngOnInit () { | 31 | ngOnInit () { |
32 | this.buildForm({ | 32 | this.buildForm({ |
33 | 'old-password': this.userValidatorsService.USER_PASSWORD, | 33 | 'current-password': this.userValidatorsService.USER_PASSWORD, |
34 | 'new-password': this.userValidatorsService.USER_PASSWORD, | 34 | 'new-password': this.userValidatorsService.USER_PASSWORD, |
35 | 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD | 35 | 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD |
36 | }) | 36 | }) |
@@ -44,31 +44,26 @@ export class MyAccountChangePasswordComponent extends FormReactive implements On | |||
44 | .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true })) | 44 | .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true })) |
45 | } | 45 | } |
46 | 46 | ||
47 | checkPassword () { | 47 | changePassword () { |
48 | this.error = null | 48 | const currentPassword = this.form.value[ 'current-password' ] |
49 | const oldPassword = this.form.value[ 'old-password' ] | 49 | const newPassword = this.form.value[ 'new-password' ] |
50 | 50 | ||
51 | // compare old password | 51 | this.userService.changePassword(currentPassword, newPassword).subscribe( |
52 | this.authService.login(this.user.account.name, oldPassword) | ||
53 | .subscribe( | ||
54 | () => this.changePassword(), | ||
55 | err => { | ||
56 | if (err.message.indexOf('credentials are invalid') !== -1) this.error = this.i18n('Incorrect old password.') | ||
57 | else this.error = err.message | ||
58 | } | ||
59 | ) | ||
60 | |||
61 | } | ||
62 | |||
63 | private changePassword () { | ||
64 | this.userService.changePassword(this.form.value[ 'new-password' ]).subscribe( | ||
65 | () => { | 52 | () => { |
66 | this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')) | 53 | this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')) |
67 | 54 | ||
68 | this.form.reset() | 55 | this.form.reset() |
56 | this.error = null | ||
69 | }, | 57 | }, |
70 | 58 | ||
71 | err => this.error = err.message | 59 | err => { |
60 | if (err.status === 401) { | ||
61 | this.error = this.i18n('You current password is invalid.') | ||
62 | return | ||
63 | } | ||
64 | |||
65 | this.error = err.message | ||
66 | } | ||
72 | ) | 67 | ) |
73 | } | 68 | } |
74 | } | 69 | } |