3bd604b662ca7fdcec0e2071803bd33b676d3668
[oweals/peertube.git] /
1 import { Component, OnInit } from '@angular/core'
2 import { I18n } from '@ngx-translate/i18n-polyfill'
3 import { Notifier, RedirectService } from '@app/core'
4 import { ServerService } from '@app/core/server'
5 import { FormReactive, UserService } from '@app/shared'
6 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7 import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
8 import { ServerConfig } from '@shared/models'
9
10 @Component({
11   selector: 'my-verify-account-ask-send-email',
12   templateUrl: './verify-account-ask-send-email.component.html',
13   styleUrls: [ './verify-account-ask-send-email.component.scss' ]
14 })
15
16 export class VerifyAccountAskSendEmailComponent extends FormReactive implements OnInit {
17   private serverConfig: ServerConfig
18
19   constructor (
20     protected formValidatorService: FormValidatorService,
21     private userValidatorsService: UserValidatorsService,
22     private userService: UserService,
23     private serverService: ServerService,
24     private notifier: Notifier,
25     private redirectService: RedirectService,
26     private i18n: I18n
27   ) {
28     super()
29   }
30
31   get requiresEmailVerification () {
32     return this.serverConfig.signup.requiresEmailVerification
33   }
34
35   ngOnInit () {
36     this.serverConfig = this.serverService.getTmpConfig()
37     this.serverService.getConfig()
38         .subscribe(config => this.serverConfig = config)
39
40     this.buildForm({
41       'verify-email-email': this.userValidatorsService.USER_EMAIL
42     })
43   }
44
45   askSendVerifyEmail () {
46     const email = this.form.value['verify-email-email']
47     this.userService.askSendVerifyEmail(email)
48       .subscribe(
49         () => {
50           const message = this.i18n(
51             'An email with verification link will be sent to {{email}}.',
52             { email }
53           )
54           this.notifier.success(message)
55           this.redirectService.redirectToHomepage()
56         },
57
58         err => {
59           this.notifier.error(err.message)
60         }
61       )
62   }
63 }