]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+verify-account/verify-account-ask-send-email/verify-account-ask-send-email.component.ts
add user account email verificiation (#977)
[github/Chocobozzz/PeerTube.git] / client / src / app / +verify-account / verify-account-ask-send-email / verify-account-ask-send-email.component.ts
CommitLineData
d9eaee39
JM
1import { Component, OnInit } from '@angular/core'
2import { I18n } from '@ngx-translate/i18n-polyfill'
3import { NotificationsService } from 'angular2-notifications'
4import { ServerService } from '@app/core/server'
5import { RedirectService } from '@app/core'
6import { UserService, FormReactive } from '@app/shared'
7import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
8import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
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
16export class VerifyAccountAskSendEmailComponent extends FormReactive implements OnInit {
17
18 constructor (
19 protected formValidatorService: FormValidatorService,
20 private userValidatorsService: UserValidatorsService,
21 private userService: UserService,
22 private serverService: ServerService,
23 private notificationsService: NotificationsService,
24 private redirectService: RedirectService,
25 private i18n: I18n
26 ) {
27 super()
28 }
29
30 get requiresEmailVerification () {
31 return this.serverService.getConfig().signup.requiresEmailVerification
32 }
33
34 ngOnInit () {
35 this.buildForm({
36 'verify-email-email': this.userValidatorsService.USER_EMAIL
37 })
38 }
39
40 askSendVerifyEmail () {
41 const email = this.form.value['verify-email-email']
42 this.userService.askSendVerifyEmail(email)
43 .subscribe(
44 () => {
45 const message = this.i18n(
46 'An email with verification link will be sent to {{email}}.',
47 { email }
48 )
49 this.notificationsService.success(this.i18n('Success'), message)
50 this.redirectService.redirectToHomepage()
51 },
52
53 err => {
54 this.notificationsService.error(this.i18n('Error'), err.message)
55 }
56 )
57 }
58}