1 import { Component, OnInit } from '@angular/core'
2 import { FormBuilder, FormGroup, Validators } from '@angular/forms'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { USER_PASSWORD, UserService } from '@app/shared'
5 import { NotificationsService } from 'angular2-notifications'
6 import { AuthService } from '../core'
7 import { FormReactive } from '../shared'
11 templateUrl: './reset-password.component.html',
12 styleUrls: [ './reset-password.component.scss' ]
15 export class ResetPasswordComponent extends FormReactive implements OnInit {
19 'password-confirm': ''
21 validationMessages = {
22 'password': USER_PASSWORD.MESSAGES,
24 'required': 'Confirmation of the password is required.'
28 private userId: number
29 private verificationString: string
32 private authService: AuthService,
33 private userService: UserService,
34 private notificationsService: NotificationsService,
35 private formBuilder: FormBuilder,
36 private router: Router,
37 private route: ActivatedRoute
43 this.form = this.formBuilder.group({
44 password: [ '', USER_PASSWORD.VALIDATORS ],
45 'password-confirm': [ '', Validators.required ]
48 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
54 this.userId = this.route.snapshot.queryParams['userId']
55 this.verificationString = this.route.snapshot.queryParams['verificationString']
57 if (!this.userId || !this.verificationString) {
58 this.notificationsService.error('Error', 'Unable to find user id or verification string.')
59 this.router.navigate([ '/' ])
64 this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password)
67 this.notificationsService.success('Success', 'Your password has been successfully reset!')
68 this.router.navigate([ '/login' ])
71 err => this.notificationsService.error('Error', err.message)
75 isConfirmedPasswordValid () {
76 const values = this.form.value
77 return values.password === values['password-confirm']