]>
Commit | Line | Data |
---|---|---|
d9eaee39 | 1 | import { Component, OnInit } from '@angular/core' |
67ed6552 | 2 | import { ActivatedRoute } from '@angular/router' |
9589907c C |
3 | import { SignupService } from '@app/+signup/shared/signup.service' |
4 | import { AuthService, Notifier, ServerService } from '@app/core' | |
d9eaee39 JM |
5 | |
6 | @Component({ | |
7 | selector: 'my-verify-account-email', | |
8 | templateUrl: './verify-account-email.component.html' | |
9 | }) | |
10 | ||
11 | export class VerifyAccountEmailComponent implements OnInit { | |
12 | success = false | |
0ba5f5ba C |
13 | failed = false |
14 | isPendingEmail = false | |
d9eaee39 | 15 | |
9589907c C |
16 | requiresApproval: boolean |
17 | loaded = false | |
18 | ||
d9eaee39 | 19 | private userId: number |
9589907c | 20 | private registrationId: number |
d9eaee39 JM |
21 | private verificationString: string |
22 | ||
23 | constructor ( | |
9589907c C |
24 | private signupService: SignupService, |
25 | private server: ServerService, | |
0ba5f5ba | 26 | private authService: AuthService, |
f8b2c1b4 | 27 | private notifier: Notifier, |
66357162 | 28 | private route: ActivatedRoute |
9df52d66 | 29 | ) { |
d9eaee39 JM |
30 | } |
31 | ||
9589907c C |
32 | get instanceName () { |
33 | return this.server.getHTMLConfig().instance.name | |
34 | } | |
35 | ||
d9eaee39 | 36 | ngOnInit () { |
0ba5f5ba | 37 | const queryParams = this.route.snapshot.queryParams |
9589907c C |
38 | |
39 | this.server.getConfig().subscribe(config => { | |
40 | this.requiresApproval = config.signup.requiresApproval | |
41 | ||
42 | this.loaded = true | |
43 | }) | |
44 | ||
0ba5f5ba | 45 | this.userId = queryParams['userId'] |
9589907c C |
46 | this.registrationId = queryParams['registrationId'] |
47 | ||
0ba5f5ba | 48 | this.verificationString = queryParams['verificationString'] |
9589907c | 49 | |
0ba5f5ba C |
50 | this.isPendingEmail = queryParams['isPendingEmail'] === 'true' |
51 | ||
9589907c C |
52 | if (!this.verificationString) { |
53 | this.notifier.error($localize`Unable to find verification string in URL query.`) | |
54 | return | |
55 | } | |
56 | ||
57 | if (!this.userId && !this.registrationId) { | |
58 | this.notifier.error($localize`Unable to find user id or registration id in URL query.`) | |
59 | return | |
d9eaee39 | 60 | } |
9589907c C |
61 | |
62 | this.verifyEmail() | |
63 | } | |
64 | ||
65 | isRegistrationRequest () { | |
66 | return !!this.registrationId | |
67 | } | |
68 | ||
69 | displaySignupSuccess () { | |
70 | if (!this.success) return false | |
71 | if (!this.isRegistrationRequest() && this.isPendingEmail) return false | |
72 | ||
73 | return true | |
d9eaee39 JM |
74 | } |
75 | ||
76 | verifyEmail () { | |
9589907c C |
77 | if (this.isRegistrationRequest()) { |
78 | return this.verifyRegistrationEmail() | |
79 | } | |
80 | ||
81 | return this.verifyUserEmail() | |
82 | } | |
83 | ||
84 | private verifyUserEmail () { | |
85 | const options = { | |
86 | userId: this.userId, | |
87 | verificationString: this.verificationString, | |
88 | isPendingEmail: this.isPendingEmail | |
89 | } | |
90 | ||
91 | this.signupService.verifyUserEmail(options) | |
1378c0d3 C |
92 | .subscribe({ |
93 | next: () => { | |
d1ea2a98 C |
94 | if (this.authService.isLoggedIn()) { |
95 | this.authService.refreshUserInformation() | |
96 | } | |
0ba5f5ba | 97 | |
d9eaee39 | 98 | this.success = true |
d9eaee39 JM |
99 | }, |
100 | ||
1378c0d3 | 101 | error: err => { |
0ba5f5ba C |
102 | this.failed = true |
103 | ||
f8b2c1b4 | 104 | this.notifier.error(err.message) |
d9eaee39 | 105 | } |
1378c0d3 | 106 | }) |
d9eaee39 | 107 | } |
9589907c C |
108 | |
109 | private verifyRegistrationEmail () { | |
110 | const options = { | |
111 | registrationId: this.registrationId, | |
112 | verificationString: this.verificationString | |
113 | } | |
114 | ||
115 | this.signupService.verifyRegistrationEmail(options) | |
116 | .subscribe({ | |
117 | next: () => { | |
118 | this.success = true | |
119 | }, | |
120 | ||
121 | error: err => { | |
122 | this.failed = true | |
123 | ||
124 | this.notifier.error(err.message) | |
125 | } | |
126 | }) | |
127 | } | |
d9eaee39 | 128 | } |