]>
Commit | Line | Data |
---|---|---|
d9eaee39 JM |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | |
3 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
0ba5f5ba | 4 | import { AuthService, Notifier } from '@app/core' |
d9eaee39 JM |
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 | |
0ba5f5ba C |
14 | failed = false |
15 | isPendingEmail = false | |
d9eaee39 JM |
16 | |
17 | private userId: number | |
18 | private verificationString: string | |
19 | ||
20 | constructor ( | |
21 | private userService: UserService, | |
0ba5f5ba | 22 | private authService: AuthService, |
f8b2c1b4 | 23 | private notifier: Notifier, |
d9eaee39 JM |
24 | private router: Router, |
25 | private route: ActivatedRoute, | |
26 | private i18n: I18n | |
27 | ) { | |
28 | } | |
29 | ||
30 | ngOnInit () { | |
0ba5f5ba C |
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 | console.log(this.isPendingEmail) | |
d9eaee39 JM |
37 | |
38 | if (!this.userId || !this.verificationString) { | |
f8b2c1b4 | 39 | this.notifier.error(this.i18n('Unable to find user id or verification string.')) |
d9eaee39 JM |
40 | } else { |
41 | this.verifyEmail() | |
42 | } | |
43 | } | |
44 | ||
45 | verifyEmail () { | |
0ba5f5ba | 46 | this.userService.verifyEmail(this.userId, this.verificationString, this.isPendingEmail) |
d9eaee39 JM |
47 | .subscribe( |
48 | () => { | |
0ba5f5ba C |
49 | this.authService.refreshUserInformation() |
50 | ||
d9eaee39 | 51 | this.success = true |
d9eaee39 JM |
52 | }, |
53 | ||
54 | err => { | |
0ba5f5ba C |
55 | this.failed = true |
56 | ||
f8b2c1b4 | 57 | this.notifier.error(err.message) |
d9eaee39 JM |
58 | } |
59 | ) | |
60 | } | |
61 | } |