1 import { Component, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { Notifier, UserService } from '@app/core'
4 import { RESET_PASSWORD_CONFIRM_VALIDATOR } from '@app/shared/form-validators/reset-password-validators'
5 import { USER_PASSWORD_VALIDATOR } from '@app/shared/form-validators/user-validators'
6 import { FormReactive, FormValidatorService } from '@app/shared/shared-forms'
10 templateUrl: './reset-password.component.html',
11 styleUrls: [ './reset-password.component.scss' ]
14 export class ResetPasswordComponent extends FormReactive implements OnInit {
15 private userId: number
16 private verificationString: string
19 protected formValidatorService: FormValidatorService,
20 private userService: UserService,
21 private notifier: Notifier,
22 private router: Router,
23 private route: ActivatedRoute
30 password: USER_PASSWORD_VALIDATOR,
31 'password-confirm': RESET_PASSWORD_CONFIRM_VALIDATOR
34 this.userId = this.route.snapshot.queryParams['userId']
35 this.verificationString = this.route.snapshot.queryParams['verificationString']
37 if (!this.userId || !this.verificationString) {
38 this.notifier.error($localize`Unable to find user id or verification string.`)
39 this.router.navigate([ '/' ])
44 this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password)
47 this.notifier.success($localize`Your password has been successfully reset!`)
48 this.router.navigate([ '/login' ])
51 err => this.notifier.error(err.message)
55 isConfirmedPasswordValid () {
56 const values = this.form.value
57 return values.password === values['password-confirm']