]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+signup/+verify-account/verify-account-email/verify-account-email.component.ts
Reorganize client shared modules
[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 { AuthService, Notifier, UserService } from '@app/core'
4 import { I18n } from '@ngx-translate/i18n-polyfill'
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 private userId: number
17 private verificationString: string
18
19 constructor (
20 private userService: UserService,
21 private authService: AuthService,
22 private notifier: Notifier,
23 private route: ActivatedRoute,
24 private i18n: I18n
25 ) {
26 }
27
28 ngOnInit () {
29 const queryParams = this.route.snapshot.queryParams
30 this.userId = queryParams['userId']
31 this.verificationString = queryParams['verificationString']
32 this.isPendingEmail = queryParams['isPendingEmail'] === 'true'
33
34 if (!this.userId || !this.verificationString) {
35 this.notifier.error(this.i18n('Unable to find user id or verification string.'))
36 } else {
37 this.verifyEmail()
38 }
39 }
40
41 verifyEmail () {
42 this.userService.verifyEmail(this.userId, this.verificationString, this.isPendingEmail)
43 .subscribe(
44 () => {
45 if (this.authService.isLoggedIn()) {
46 this.authService.refreshUserInformation()
47 }
48
49 this.success = true
50 },
51
52 err => {
53 this.failed = true
54
55 this.notifier.error(err.message)
56 }
57 )
58 }
59 }