diff options
Diffstat (limited to 'client/src/app/+signup/+verify-account/verify-account-email/verify-account-email.component.ts')
-rw-r--r-- | client/src/app/+signup/+verify-account/verify-account-email/verify-account-email.component.ts | 86 |
1 files changed, 78 insertions, 8 deletions
diff --git a/client/src/app/+signup/+verify-account/verify-account-email/verify-account-email.component.ts b/client/src/app/+signup/+verify-account/verify-account-email/verify-account-email.component.ts index 88efce4a1..faf663391 100644 --- a/client/src/app/+signup/+verify-account/verify-account-email/verify-account-email.component.ts +++ b/client/src/app/+signup/+verify-account/verify-account-email/verify-account-email.component.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | 1 | import { Component, OnInit } from '@angular/core' |
2 | import { ActivatedRoute } from '@angular/router' | 2 | import { ActivatedRoute } from '@angular/router' |
3 | import { AuthService, Notifier } from '@app/core' | 3 | import { SignupService } from '@app/+signup/shared/signup.service' |
4 | import { UserSignupService } from '@app/shared/shared-users' | 4 | import { AuthService, Notifier, ServerService } from '@app/core' |
5 | 5 | ||
6 | @Component({ | 6 | @Component({ |
7 | selector: 'my-verify-account-email', | 7 | selector: 'my-verify-account-email', |
@@ -13,32 +13,82 @@ export class VerifyAccountEmailComponent implements OnInit { | |||
13 | failed = false | 13 | failed = false |
14 | isPendingEmail = false | 14 | isPendingEmail = false |
15 | 15 | ||
16 | requiresApproval: boolean | ||
17 | loaded = false | ||
18 | |||
16 | private userId: number | 19 | private userId: number |
20 | private registrationId: number | ||
17 | private verificationString: string | 21 | private verificationString: string |
18 | 22 | ||
19 | constructor ( | 23 | constructor ( |
20 | private userSignupService: UserSignupService, | 24 | private signupService: SignupService, |
25 | private server: ServerService, | ||
21 | private authService: AuthService, | 26 | private authService: AuthService, |
22 | private notifier: Notifier, | 27 | private notifier: Notifier, |
23 | private route: ActivatedRoute | 28 | private route: ActivatedRoute |
24 | ) { | 29 | ) { |
25 | } | 30 | } |
26 | 31 | ||
32 | get instanceName () { | ||
33 | return this.server.getHTMLConfig().instance.name | ||
34 | } | ||
35 | |||
27 | ngOnInit () { | 36 | ngOnInit () { |
28 | const queryParams = this.route.snapshot.queryParams | 37 | const queryParams = this.route.snapshot.queryParams |
38 | |||
39 | this.server.getConfig().subscribe(config => { | ||
40 | this.requiresApproval = config.signup.requiresApproval | ||
41 | |||
42 | this.loaded = true | ||
43 | }) | ||
44 | |||
29 | this.userId = queryParams['userId'] | 45 | this.userId = queryParams['userId'] |
46 | this.registrationId = queryParams['registrationId'] | ||
47 | |||
30 | this.verificationString = queryParams['verificationString'] | 48 | this.verificationString = queryParams['verificationString'] |
49 | |||
31 | this.isPendingEmail = queryParams['isPendingEmail'] === 'true' | 50 | this.isPendingEmail = queryParams['isPendingEmail'] === 'true' |
32 | 51 | ||
33 | if (!this.userId || !this.verificationString) { | 52 | if (!this.verificationString) { |
34 | this.notifier.error($localize`Unable to find user id or verification string.`) | 53 | this.notifier.error($localize`Unable to find verification string in URL query.`) |
35 | } else { | 54 | return |
36 | this.verifyEmail() | 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 | ||
37 | } | 60 | } |
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 | ||
38 | } | 74 | } |
39 | 75 | ||
40 | verifyEmail () { | 76 | verifyEmail () { |
41 | this.userSignupService.verifyEmail(this.userId, this.verificationString, this.isPendingEmail) | 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) | ||
42 | .subscribe({ | 92 | .subscribe({ |
43 | next: () => { | 93 | next: () => { |
44 | if (this.authService.isLoggedIn()) { | 94 | if (this.authService.isLoggedIn()) { |
@@ -55,4 +105,24 @@ export class VerifyAccountEmailComponent implements OnInit { | |||
55 | } | 105 | } |
56 | }) | 106 | }) |
57 | } | 107 | } |
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 | } | ||
58 | } | 128 | } |