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