]>
Commit | Line | Data |
---|---|---|
1 | import { Component, OnInit } from '@angular/core' | |
2 | import { ActivatedRoute } from '@angular/router' | |
3 | import { AuthService, Notifier, UserService } from '@app/core' | |
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 | |
12 | failed = false | |
13 | isPendingEmail = false | |
14 | ||
15 | private userId: number | |
16 | private verificationString: string | |
17 | ||
18 | constructor ( | |
19 | private userService: UserService, | |
20 | private authService: AuthService, | |
21 | private notifier: Notifier, | |
22 | private route: ActivatedRoute | |
23 | ) { | |
24 | } | |
25 | ||
26 | ngOnInit () { | |
27 | const queryParams = this.route.snapshot.queryParams | |
28 | this.userId = queryParams['userId'] | |
29 | this.verificationString = queryParams['verificationString'] | |
30 | this.isPendingEmail = queryParams['isPendingEmail'] === 'true' | |
31 | ||
32 | if (!this.userId || !this.verificationString) { | |
33 | this.notifier.error($localize`Unable to find user id or verification string.`) | |
34 | } else { | |
35 | this.verifyEmail() | |
36 | } | |
37 | } | |
38 | ||
39 | verifyEmail () { | |
40 | this.userService.verifyEmail(this.userId, this.verificationString, this.isPendingEmail) | |
41 | .subscribe( | |
42 | () => { | |
43 | if (this.authService.isLoggedIn()) { | |
44 | this.authService.refreshUserInformation() | |
45 | } | |
46 | ||
47 | this.success = true | |
48 | }, | |
49 | ||
50 | err => { | |
51 | this.failed = true | |
52 | ||
53 | this.notifier.error(err.message) | |
54 | } | |
55 | ) | |
56 | } | |
57 | } |