1 import { Component, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { UserService, UserValidatorsService, FormReactive } from '@app/shared'
4 import { Notifier } from '@app/core'
5 import { I18n } from '@ngx-translate/i18n-polyfill'
6 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7 import { ResetPasswordValidatorsService } from '@app/shared/forms/form-validators/reset-password-validators.service'
11 templateUrl: './reset-password.component.html',
12 styleUrls: [ './reset-password.component.scss' ]
15 export class ResetPasswordComponent extends FormReactive implements OnInit {
16 private userId: number
17 private verificationString: string
20 protected formValidatorService: FormValidatorService,
21 private resetPasswordValidatorsService: ResetPasswordValidatorsService,
22 private userValidatorsService: UserValidatorsService,
23 private userService: UserService,
24 private notifier: Notifier,
25 private router: Router,
26 private route: ActivatedRoute,
34 password: this.userValidatorsService.USER_PASSWORD,
35 'password-confirm': this.resetPasswordValidatorsService.RESET_PASSWORD_CONFIRM
38 this.userId = this.route.snapshot.queryParams['userId']
39 this.verificationString = this.route.snapshot.queryParams['verificationString']
41 if (!this.userId || !this.verificationString) {
42 this.notifier.error(this.i18n('Unable to find user id or verification string.'))
43 this.router.navigate([ '/' ])
48 this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password)
51 this.notifier.success(this.i18n('Your password has been successfully reset!'))
52 this.router.navigate([ '/login' ])
55 err => this.notifier.error(err.message)
59 isConfirmedPasswordValid () {
60 const values = this.form.value
61 return values.password === values['password-confirm']