]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+signup/+verify-account/verify-account-email/verify-account-email.component.ts
Fix signup email verification
[github/Chocobozzz/PeerTube.git] / client / src / app / +signup / +verify-account / verify-account-email / verify-account-email.component.ts
CommitLineData
d9eaee39
JM
1import { Component, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
3import { I18n } from '@ngx-translate/i18n-polyfill'
0ba5f5ba 4import { AuthService, Notifier } from '@app/core'
d9eaee39
JM
5import { UserService } from '@app/shared'
6
7@Component({
8 selector: 'my-verify-account-email',
9 templateUrl: './verify-account-email.component.html'
10})
11
12export 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
d9eaee39 36 if (!this.userId || !this.verificationString) {
f8b2c1b4 37 this.notifier.error(this.i18n('Unable to find user id or verification string.'))
d9eaee39
JM
38 } else {
39 this.verifyEmail()
40 }
41 }
42
43 verifyEmail () {
0ba5f5ba 44 this.userService.verifyEmail(this.userId, this.verificationString, this.isPendingEmail)
d9eaee39
JM
45 .subscribe(
46 () => {
d1ea2a98
C
47 if (this.authService.isLoggedIn()) {
48 this.authService.refreshUserInformation()
49 }
0ba5f5ba 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}