]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/signup/signup.component.ts
Merge branch 'develop' of https://github.com/Chocobozzz/PeerTube into move-utils...
[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 { AuthService, 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 info: string = null
16 error: string = null
17 signupDone = false
18
19 constructor (
20 protected formValidatorService: FormValidatorService,
21 private authService: AuthService,
22 private userValidatorsService: UserValidatorsService,
23 private notificationsService: NotificationsService,
24 private userService: UserService,
25 private serverService: ServerService,
26 private redirectService: RedirectService,
27 private i18n: I18n
28 ) {
29 super()
30 }
31
32 get instanceHost () {
33 return window.location.host
34 }
35
36 get requiresEmailVerification () {
37 return this.serverService.getConfig().signup.requiresEmailVerification
38 }
39
40 ngOnInit () {
41 this.buildForm({
42 username: this.userValidatorsService.USER_USERNAME,
43 password: this.userValidatorsService.USER_PASSWORD,
44 email: this.userValidatorsService.USER_EMAIL,
45 terms: this.userValidatorsService.USER_TERMS
46 })
47 }
48
49 signup () {
50 this.error = null
51
52 const userCreate: UserCreate = this.form.value
53
54 this.userService.signup(userCreate).subscribe(
55 () => {
56 this.signupDone = true
57
58 if (this.requiresEmailVerification) {
59 this.info = this.i18n('Welcome! Now please check your emails to verify your account and complete signup.')
60 return
61 }
62
63 // Auto login
64 this.authService.login(userCreate.username, userCreate.password)
65 .subscribe(
66 () => {
67 this.notificationsService.success(
68 this.i18n('Success'),
69 this.i18n('You are now logged in as {{username}}!', { username: userCreate.username })
70 )
71
72 this.redirectService.redirectToHomepage()
73 },
74
75 err => this.error = err.message
76 )
77 },
78
79 err => this.error = err.message
80 )
81 }
82 }