]>
Commit | Line | Data |
---|---|---|
d9eaee39 | 1 | import { Component, OnInit } from '@angular/core' |
67ed6552 C |
2 | import { ActivatedRoute } from '@angular/router' |
3 | import { AuthService, Notifier, UserService } from '@app/core' | |
d9eaee39 JM |
4 | |
5 | @Component({ | |
6 | selector: 'my-verify-account-email', | |
7 | templateUrl: './verify-account-email.component.html' | |
8 | }) | |
9 | ||
10 | export class VerifyAccountEmailComponent implements OnInit { | |
11 | success = false | |
0ba5f5ba C |
12 | failed = false |
13 | isPendingEmail = false | |
d9eaee39 JM |
14 | |
15 | private userId: number | |
16 | private verificationString: string | |
17 | ||
18 | constructor ( | |
19 | private userService: UserService, | |
0ba5f5ba | 20 | private authService: AuthService, |
f8b2c1b4 | 21 | private notifier: Notifier, |
66357162 C |
22 | private route: ActivatedRoute |
23 | ) { | |
d9eaee39 JM |
24 | } |
25 | ||
26 | ngOnInit () { | |
0ba5f5ba C |
27 | const queryParams = this.route.snapshot.queryParams |
28 | this.userId = queryParams['userId'] | |
29 | this.verificationString = queryParams['verificationString'] | |
30 | this.isPendingEmail = queryParams['isPendingEmail'] === 'true' | |
31 | ||
d9eaee39 | 32 | if (!this.userId || !this.verificationString) { |
66357162 | 33 | this.notifier.error($localize`Unable to find user id or verification string.`) |
d9eaee39 JM |
34 | } else { |
35 | this.verifyEmail() | |
36 | } | |
37 | } | |
38 | ||
39 | verifyEmail () { | |
0ba5f5ba | 40 | this.userService.verifyEmail(this.userId, this.verificationString, this.isPendingEmail) |
d9eaee39 JM |
41 | .subscribe( |
42 | () => { | |
d1ea2a98 C |
43 | if (this.authService.isLoggedIn()) { |
44 | this.authService.refreshUserInformation() | |
45 | } | |
0ba5f5ba | 46 | |
d9eaee39 | 47 | this.success = true |
d9eaee39 JM |
48 | }, |
49 | ||
50 | err => { | |
0ba5f5ba C |
51 | this.failed = true |
52 | ||
f8b2c1b4 | 53 | this.notifier.error(err.message) |
d9eaee39 JM |
54 | } |
55 | ) | |
56 | } | |
57 | } |