1 import { Component, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { FormReactive, UserService } from '../../../shared'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
5 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
6 import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
7 import { filter } from 'rxjs/operators'
8 import { AuthService } from '@app/core'
9 import { User } from '../../../../../../shared'
12 selector: 'my-account-change-password',
13 templateUrl: './my-account-change-password.component.html',
14 styleUrls: [ './my-account-change-password.component.scss' ]
16 export class MyAccountChangePasswordComponent extends FormReactive implements OnInit {
21 protected formValidatorService: FormValidatorService,
22 private userValidatorsService: UserValidatorsService,
23 private notificationsService: NotificationsService,
24 private authService: AuthService,
25 private userService: UserService,
33 'current-password': this.userValidatorsService.USER_PASSWORD,
34 'new-password': this.userValidatorsService.USER_PASSWORD,
35 'new-confirmed-password': this.userValidatorsService.USER_CONFIRM_PASSWORD
38 this.user = this.authService.getUser()
40 const confirmPasswordControl = this.form.get('new-confirmed-password')
42 confirmPasswordControl.valueChanges
43 .pipe(filter(v => v !== this.form.value[ 'new-password' ]))
44 .subscribe(() => confirmPasswordControl.setErrors({ matchPassword: true }))
48 const currentPassword = this.form.value[ 'current-password' ]
49 const newPassword = this.form.value[ 'new-password' ]
51 this.userService.changePassword(currentPassword, newPassword).subscribe(
53 this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.'))
60 if (err.status === 401) {
61 this.error = this.i18n('You current password is invalid.')
65 this.error = err.message