]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/signup/signup.component.ts
Update FAQ.md
[github/Chocobozzz/PeerTube.git] / client / src / app / signup / signup.component.ts
CommitLineData
df98563e 1import { Component, OnInit } from '@angular/core'
df98563e 2import { NotificationsService } from 'angular2-notifications'
4771e000 3import { UserCreate } from '../../../../shared'
e309822b 4import { FormReactive, UserService, UserValidatorsService } from '../shared'
d9eaee39 5import { RedirectService, ServerService } from '@app/core'
b1d40cff 6import { I18n } from '@ngx-translate/i18n-polyfill'
d18d6478 7import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
a184c71b
C
8
9@Component({
10 selector: 'my-signup',
d235f6b0
C
11 templateUrl: './signup.component.html',
12 styleUrls: [ './signup.component.scss' ]
a184c71b
C
13})
14export class SignupComponent extends FormReactive implements OnInit {
df98563e 15 error: string = null
a184c71b 16
df98563e 17 constructor (
d18d6478 18 protected formValidatorService: FormValidatorService,
e309822b 19 private userValidatorsService: UserValidatorsService,
a184c71b 20 private notificationsService: NotificationsService,
5afdd0a5 21 private userService: UserService,
d9eaee39 22 private serverService: ServerService,
b1d40cff 23 private redirectService: RedirectService,
b1d40cff 24 private i18n: I18n
a184c71b 25 ) {
df98563e 26 super()
a184c71b
C
27 }
28
8a19bee1
C
29 get instanceHost () {
30 return window.location.host
31 }
32
d9eaee39
JM
33 get requiresEmailVerification () {
34 return this.serverService.getConfig().signup.requiresEmailVerification
35 }
36
df98563e 37 ngOnInit () {
d18d6478 38 this.buildForm({
e309822b
C
39 username: this.userValidatorsService.USER_USERNAME,
40 password: this.userValidatorsService.USER_PASSWORD,
b4a929ac
C
41 email: this.userValidatorsService.USER_EMAIL,
42 terms: this.userValidatorsService.USER_TERMS
d18d6478 43 })
a184c71b
C
44 }
45
df98563e
C
46 signup () {
47 this.error = null
a184c71b 48
4771e000 49 const userCreate: UserCreate = this.form.value
a184c71b 50
4771e000 51 this.userService.signup(userCreate).subscribe(
a184c71b 52 () => {
d9eaee39
JM
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 }
b1d40cff 64 this.redirectService.redirectToHomepage()
a184c71b
C
65 },
66
f7354483 67 err => this.error = err.message
df98563e 68 )
a184c71b
C
69 }
70}