]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/signup/signup.component.ts
remove unused imports
[github/Chocobozzz/PeerTube.git] / client / src / app / signup / signup.component.ts
1 import { Component, OnInit } from '@angular/core'
2 import { NotificationsService } from 'angular2-notifications'
3 import { UserCreate } from '../../../../shared'
4 import { FormReactive, UserService, UserValidatorsService } from '../shared'
5 import { RedirectService, ServerService } from '@app/core'
6 import { I18n } from '@ngx-translate/i18n-polyfill'
7 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
8
9 @Component({
10 selector: 'my-signup',
11 templateUrl: './signup.component.html',
12 styleUrls: [ './signup.component.scss' ]
13 })
14 export class SignupComponent extends FormReactive implements OnInit {
15 error: string = null
16
17 constructor (
18 protected formValidatorService: FormValidatorService,
19 private userValidatorsService: UserValidatorsService,
20 private notificationsService: NotificationsService,
21 private userService: UserService,
22 private serverService: ServerService,
23 private redirectService: RedirectService,
24 private i18n: I18n
25 ) {
26 super()
27 }
28
29 get instanceHost () {
30 return window.location.host
31 }
32
33 get requiresEmailVerification () {
34 return this.serverService.getConfig().signup.requiresEmailVerification
35 }
36
37 ngOnInit () {
38 this.buildForm({
39 username: this.userValidatorsService.USER_USERNAME,
40 password: this.userValidatorsService.USER_PASSWORD,
41 email: this.userValidatorsService.USER_EMAIL,
42 terms: this.userValidatorsService.USER_TERMS
43 })
44 }
45
46 signup () {
47 this.error = null
48
49 const userCreate: UserCreate = this.form.value
50
51 this.userService.signup(userCreate).subscribe(
52 () => {
53 if (this.requiresEmailVerification) {
54 this.notificationsService.alert(
55 this.i18n('Welcome'),
56 this.i18n('Please check your email to verify your account and complete signup.')
57 )
58 } else {
59 this.notificationsService.success(
60 this.i18n('Success'),
61 this.i18n('Registration for {{username}} complete.', { username: userCreate.username })
62 )
63 }
64 this.redirectService.redirectToHomepage()
65 },
66
67 err => this.error = err.message
68 )
69 }
70 }