]>
Commit | Line | Data |
---|---|---|
ecb4e35f | 1 | import { Component, OnInit } from '@angular/core' |
ecb4e35f | 2 | import { ActivatedRoute, Router } from '@angular/router' |
e309822b | 3 | import { UserService, UserValidatorsService } from '@app/shared' |
ecb4e35f C |
4 | import { NotificationsService } from 'angular2-notifications' |
5 | import { AuthService } from '../core' | |
6 | import { FormReactive } from '../shared' | |
b1d40cff | 7 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d18d6478 | 8 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' |
e309822b | 9 | import { ResetPasswordValidatorsService } from '@app/shared/forms/form-validators/reset-password-validators.service' |
ecb4e35f C |
10 | |
11 | @Component({ | |
12 | selector: 'my-login', | |
13 | templateUrl: './reset-password.component.html', | |
14 | styleUrls: [ './reset-password.component.scss' ] | |
15 | }) | |
16 | ||
17 | export class ResetPasswordComponent extends FormReactive implements OnInit { | |
ecb4e35f C |
18 | private userId: number |
19 | private verificationString: string | |
20 | ||
21 | constructor ( | |
d18d6478 | 22 | protected formValidatorService: FormValidatorService, |
e309822b C |
23 | private resetPasswordValidatorsService: ResetPasswordValidatorsService, |
24 | private userValidatorsService: UserValidatorsService, | |
ecb4e35f C |
25 | private authService: AuthService, |
26 | private userService: UserService, | |
27 | private notificationsService: NotificationsService, | |
ecb4e35f | 28 | private router: Router, |
b1d40cff C |
29 | private route: ActivatedRoute, |
30 | private i18n: I18n | |
ecb4e35f C |
31 | ) { |
32 | super() | |
33 | } | |
34 | ||
ecb4e35f | 35 | ngOnInit () { |
d18d6478 | 36 | this.buildForm({ |
e309822b C |
37 | password: this.userValidatorsService.USER_PASSWORD, |
38 | 'password-confirm': this.resetPasswordValidatorsService.RESET_PASSWORD_CONFIRM | |
d18d6478 | 39 | }) |
ecb4e35f C |
40 | |
41 | this.userId = this.route.snapshot.queryParams['userId'] | |
42 | this.verificationString = this.route.snapshot.queryParams['verificationString'] | |
43 | ||
44 | if (!this.userId || !this.verificationString) { | |
b1d40cff | 45 | this.notificationsService.error(this.i18n('Error'), this.i18n('Unable to find user id or verification string.')) |
ecb4e35f C |
46 | this.router.navigate([ '/' ]) |
47 | } | |
48 | } | |
49 | ||
50 | resetPassword () { | |
51 | this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password) | |
52 | .subscribe( | |
53 | () => { | |
b1d40cff | 54 | this.notificationsService.success(this.i18n('Success'), this.i18n('Your password has been successfully reset!')) |
ecb4e35f C |
55 | this.router.navigate([ '/login' ]) |
56 | }, | |
57 | ||
58 | err => this.notificationsService.error('Error', err.message) | |
59 | ) | |
60 | } | |
61 | ||
62 | isConfirmedPasswordValid () { | |
63 | const values = this.form.value | |
64 | return values.password === values['password-confirm'] | |
65 | } | |
66 | } |