]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { Component, OnInit } from '@angular/core' |
df98563e | 2 | import { NotificationsService } from 'angular2-notifications' |
c30745f3 | 3 | import { FormReactive, USER_PASSWORD, UserService } from '../../../shared' |
b1d40cff | 4 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d18d6478 | 5 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
af5e743b C |
6 | |
7 | @Component({ | |
8 | selector: 'my-account-change-password', | |
4bb6886d C |
9 | templateUrl: './my-account-change-password.component.html', |
10 | styleUrls: [ './my-account-change-password.component.scss' ] | |
af5e743b | 11 | }) |
4bb6886d | 12 | export class MyAccountChangePasswordComponent extends FormReactive implements OnInit { |
df98563e | 13 | error: string = null |
af5e743b | 14 | |
df98563e | 15 | constructor ( |
d18d6478 | 16 | protected formValidatorService: FormValidatorService, |
af5e743b | 17 | private notificationsService: NotificationsService, |
b1d40cff C |
18 | private userService: UserService, |
19 | private i18n: I18n | |
af5e743b | 20 | ) { |
df98563e | 21 | super() |
af5e743b C |
22 | } |
23 | ||
df98563e | 24 | ngOnInit () { |
d18d6478 C |
25 | this.buildForm({ |
26 | 'new-password': USER_PASSWORD, | |
27 | 'new-confirmed-password': USER_PASSWORD | |
28 | }) | |
af5e743b C |
29 | } |
30 | ||
df98563e C |
31 | changePassword () { |
32 | const newPassword = this.form.value['new-password'] | |
33 | const newConfirmedPassword = this.form.value['new-confirmed-password'] | |
af5e743b | 34 | |
df98563e | 35 | this.error = null |
af5e743b C |
36 | |
37 | if (newPassword !== newConfirmedPassword) { | |
b1d40cff | 38 | this.error = this.i18n('The new password and the confirmed password do not correspond.') |
df98563e | 39 | return |
af5e743b C |
40 | } |
41 | ||
42 | this.userService.changePassword(newPassword).subscribe( | |
b1d40cff | 43 | () => this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')), |
af5e743b | 44 | |
f7354483 | 45 | err => this.error = err.message |
df98563e | 46 | ) |
af5e743b C |
47 | } |
48 | } |