]>
Commit | Line | Data |
---|---|---|
df98563e | 1 | import { Component, OnInit } from '@angular/core' |
df98563e | 2 | import { NotificationsService } from 'angular2-notifications' |
e309822b | 3 | import { FormReactive, 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' |
e309822b | 6 | import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service' |
af5e743b C |
7 | |
8 | @Component({ | |
9 | selector: 'my-account-change-password', | |
4bb6886d C |
10 | templateUrl: './my-account-change-password.component.html', |
11 | styleUrls: [ './my-account-change-password.component.scss' ] | |
af5e743b | 12 | }) |
4bb6886d | 13 | export class MyAccountChangePasswordComponent extends FormReactive implements OnInit { |
df98563e | 14 | error: string = null |
a94419a6 | 15 | unsendable = true // default to true to not have to not the if in change password |
af5e743b | 16 | |
df98563e | 17 | constructor ( |
d18d6478 | 18 | protected formValidatorService: FormValidatorService, |
e309822b | 19 | private userValidatorsService: UserValidatorsService, |
af5e743b | 20 | private notificationsService: NotificationsService, |
b1d40cff C |
21 | private userService: UserService, |
22 | private i18n: I18n | |
af5e743b | 23 | ) { |
df98563e | 24 | super() |
af5e743b C |
25 | } |
26 | ||
df98563e | 27 | ngOnInit () { |
d18d6478 | 28 | this.buildForm({ |
e309822b C |
29 | 'new-password': this.userValidatorsService.USER_PASSWORD, |
30 | 'new-confirmed-password': this.userValidatorsService.USER_PASSWORD | |
d18d6478 | 31 | }) |
af5e743b C |
32 | } |
33 | ||
a94419a6 J |
34 | validateNewPassword () { |
35 | if (this.form.value['new-password'] && this.form.value['new-confirmed-password']) { | |
36 | if (this.form.value['new-password'] === this.form.value['new-confirmed-password']) { | |
37 | this.error = null | |
38 | this.unsendable = false | |
39 | return | |
40 | } | |
41 | } | |
42 | this.unsendable = true | |
43 | } | |
af5e743b | 44 | |
a94419a6 J |
45 | printAnError () { |
46 | console.log(this.unsendable) | |
47 | this.validateNewPassword() | |
48 | if (this.unsendable) { | |
b1d40cff | 49 | this.error = this.i18n('The new password and the confirmed password do not correspond.') |
a94419a6 J |
50 | } |
51 | } | |
52 | ||
53 | changePassword () { | |
54 | if (this.unsendable) { | |
df98563e | 55 | return |
af5e743b C |
56 | } |
57 | ||
a94419a6 | 58 | this.userService.changePassword(this.form.value['new-password']).subscribe( |
b1d40cff | 59 | () => this.notificationsService.success(this.i18n('Success'), this.i18n('Password updated.')), |
af5e743b | 60 | |
f7354483 | 61 | err => this.error = err.message |
df98563e | 62 | ) |
af5e743b C |
63 | } |
64 | } |