]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+signup/+verify-account/verify-account-email/verify-account-email.component.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +verify-account / verify-account-email / verify-account-email.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { ActivatedRoute } from '@angular/router'
3 import { SignupService } from '@app/+signup/shared/signup.service'
4 import { AuthService, Notifier, ServerService } from '@app/core'
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
13 failed = false
14 isPendingEmail = false
15
16 requiresApproval: boolean
17 loaded = false
18
19 private userId: number
20 private registrationId: number
21 private verificationString: string
22
23 constructor (
24 private signupService: SignupService,
25 private server: ServerService,
26 private authService: AuthService,
27 private notifier: Notifier,
28 private route: ActivatedRoute
29 ) {
30 }
31
32 get instanceName () {
33 return this.server.getHTMLConfig().instance.name
34 }
35
36 ngOnInit () {
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
45 this.userId = queryParams['userId']
46 this.registrationId = queryParams['registrationId']
47
48 this.verificationString = queryParams['verificationString']
49
50 this.isPendingEmail = queryParams['isPendingEmail'] === 'true'
51
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
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
74 }
75
76 verifyEmail () {
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)
92 .subscribe({
93 next: () => {
94 if (this.authService.isLoggedIn()) {
95 this.authService.refreshUserInformation()
96 }
97
98 this.success = true
99 },
100
101 error: err => {
102 this.failed = true
103
104 this.notifier.error(err.message)
105 }
106 })
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 }
128 }