aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/reset-password/reset-password.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/reset-password/reset-password.component.ts')
-rw-r--r--client/src/app/reset-password/reset-password.component.ts79
1 files changed, 79 insertions, 0 deletions
diff --git a/client/src/app/reset-password/reset-password.component.ts b/client/src/app/reset-password/reset-password.component.ts
new file mode 100644
index 000000000..408374779
--- /dev/null
+++ b/client/src/app/reset-password/reset-password.component.ts
@@ -0,0 +1,79 @@
1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup, Validators } from '@angular/forms'
3import { ActivatedRoute, Router } from '@angular/router'
4import { USER_PASSWORD, UserService } from '@app/shared'
5import { NotificationsService } from 'angular2-notifications'
6import { AuthService } from '../core'
7import { FormReactive } from '../shared'
8
9@Component({
10 selector: 'my-login',
11 templateUrl: './reset-password.component.html',
12 styleUrls: [ './reset-password.component.scss' ]
13})
14
15export class ResetPasswordComponent extends FormReactive implements OnInit {
16 form: FormGroup
17 formErrors = {
18 'password': '',
19 'password-confirm': ''
20 }
21 validationMessages = {
22 'password': USER_PASSWORD.MESSAGES,
23 'password-confirm': {
24 'required': 'Confirmation of the password is required.'
25 }
26 }
27
28 private userId: number
29 private verificationString: string
30
31 constructor (
32 private authService: AuthService,
33 private userService: UserService,
34 private notificationsService: NotificationsService,
35 private formBuilder: FormBuilder,
36 private router: Router,
37 private route: ActivatedRoute
38 ) {
39 super()
40 }
41
42 buildForm () {
43 this.form = this.formBuilder.group({
44 password: [ '', USER_PASSWORD.VALIDATORS ],
45 'password-confirm': [ '', Validators.required ]
46 })
47
48 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
49 }
50
51 ngOnInit () {
52 this.buildForm()
53
54 this.userId = this.route.snapshot.queryParams['userId']
55 this.verificationString = this.route.snapshot.queryParams['verificationString']
56
57 if (!this.userId || !this.verificationString) {
58 this.notificationsService.error('Error', 'Unable to find user id or verification string.')
59 this.router.navigate([ '/' ])
60 }
61 }
62
63 resetPassword () {
64 this.userService.resetPassword(this.userId, this.verificationString, this.form.value.password)
65 .subscribe(
66 () => {
67 this.notificationsService.success('Success', 'Your password has been successfully reset!')
68 this.router.navigate([ '/login' ])
69 },
70
71 err => this.notificationsService.error('Error', err.message)
72 )
73 }
74
75 isConfirmedPasswordValid () {
76 const values = this.form.value
77 return values.password === values['password-confirm']
78 }
79}