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