1 import { Component, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { UserService, UserValidatorsService } from '@app/shared'
4 import { NotificationsService } from 'angular2-notifications'
5 import { AuthService } from '../core'
6 import { FormReactive } from '../shared'
7 import { I18n } from '@ngx-translate/i18n-polyfill'
8 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
9 import { ResetPasswordValidatorsService } from '@app/shared/forms/form-validators/reset-password-validators.service'
13 templateUrl: './reset-password.component.html',
14 styleUrls: [ './reset-password.component.scss' ]
17 export class ResetPasswordComponent extends FormReactive implements OnInit {
18 private userId: number
19 private verificationString: string
22 protected formValidatorService: FormValidatorService,
23 private resetPasswordValidatorsService: ResetPasswordValidatorsService,
24 private userValidatorsService: UserValidatorsService,
25 private authService: AuthService,
26 private userService: UserService,
27 private notificationsService: NotificationsService,
28 private router: Router,
29 private route: ActivatedRoute,
37 password: this.userValidatorsService.USER_PASSWORD,
38 'password-confirm': this.resetPasswordValidatorsService.RESET_PASSWORD_CONFIRM
41 this.userId = this.route.snapshot.queryParams['userId']
42 this.verificationString = this.route.snapshot.queryParams['verificationString']
44 if (!this.userId || !this.verificationString) {
45 this.notificationsService.error(this.i18n('Error'), this.i18n('Unable to find user id or verification string.'))
46 this.router.navigate([ '/' ])
51 this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password)
54 this.notificationsService.success(this.i18n('Success'), this.i18n('Your password has been successfully reset!'))
55 this.router.navigate([ '/login' ])
58 err => this.notificationsService.error('Error', err.message)
62 isConfirmedPasswordValid () {
63 const values = this.form.value
64 return values.password === values['password-confirm']