1 import { filter } from 'rxjs/operators'
2 import { Component, OnInit } from '@angular/core'
3 import { AuthService, Notifier, UserService } from '@app/core'
4 import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
5 import { User } from '@shared/models'
8 selector: 'my-account-change-password',
9 templateUrl: './my-account-change-password.component.html',
10 styleUrls: [ './my-account-change-password.component.scss' ]
12 export class MyAccountChangePasswordComponent extends FormReactive implements OnInit {
17 protected formValidatorService: FormValidatorService,
18 private userValidatorsService: UserValidatorsService,
19 private notifier: Notifier,
20 private authService: AuthService,
21 private userService: UserService
28 'current-password': this.userValidatorsService.USER_PASSWORD,
29 'new-password': this.userValidatorsService.USER_PASSWORD,
30 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD
33 this.user = this.authService.getUser()
35 const confirmPasswordControl = this.form.get('new-confirmed-password')
37 confirmPasswordControl.valueChanges
38 .pipe(filter(v => v !== this.form.value[ 'new-password' ]))
39 .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true }))
43 const currentPassword = this.form.value[ 'current-password' ]
44 const newPassword = this.form.value[ 'new-password' ]
46 this.userService.changePassword(currentPassword, newPassword).subscribe(
48 this.notifier.success($localize`Password updated.`)
55 if (err.status === 401) {
56 this.error = $localize`You current password is invalid.`
60 this.error = err.message