]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/signup/signup.component.ts
Responsive player
[github/Chocobozzz/PeerTube.git] / client / src / app / signup / signup.component.ts
CommitLineData
df98563e
C
1import { Component, OnInit } from '@angular/core'
2import { FormBuilder, FormGroup, Validators } from '@angular/forms'
3import { Router } from '@angular/router'
a184c71b 4
df98563e 5import { NotificationsService } from 'angular2-notifications'
a184c71b 6
df98563e 7import { AuthService } from '../core'
a184c71b
C
8import {
9 FormReactive,
10 UserService,
11 USER_USERNAME,
12 USER_EMAIL,
13 USER_PASSWORD
df98563e 14} from '../shared'
4771e000 15import { UserCreate } from '../../../../shared'
a184c71b
C
16
17@Component({
18 selector: 'my-signup',
d235f6b0
C
19 templateUrl: './signup.component.html',
20 styleUrls: [ './signup.component.scss' ]
a184c71b
C
21})
22export class SignupComponent extends FormReactive implements OnInit {
df98563e 23 error: string = null
a184c71b 24
df98563e 25 form: FormGroup
a184c71b
C
26 formErrors = {
27 'username': '',
28 'email': '',
29 'password': ''
df98563e 30 }
a184c71b
C
31 validationMessages = {
32 'username': USER_USERNAME.MESSAGES,
33 'email': USER_EMAIL.MESSAGES,
df98563e
C
34 'password': USER_PASSWORD.MESSAGES
35 }
a184c71b 36
df98563e 37 constructor (
a184c71b
C
38 private formBuilder: FormBuilder,
39 private router: Router,
40 private notificationsService: NotificationsService,
41 private userService: UserService
42 ) {
df98563e 43 super()
a184c71b
C
44 }
45
df98563e 46 buildForm () {
a184c71b
C
47 this.form = this.formBuilder.group({
48 username: [ '', USER_USERNAME.VALIDATORS ],
49 email: [ '', USER_EMAIL.VALIDATORS ],
df98563e
C
50 password: [ '', USER_PASSWORD.VALIDATORS ]
51 })
a184c71b 52
df98563e 53 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
a184c71b
C
54 }
55
df98563e
C
56 ngOnInit () {
57 this.buildForm()
a184c71b
C
58 }
59
df98563e
C
60 signup () {
61 this.error = null
a184c71b 62
4771e000 63 const userCreate: UserCreate = this.form.value
a184c71b 64
4771e000 65 this.userService.signup(userCreate).subscribe(
a184c71b 66 () => {
4771e000 67 this.notificationsService.success('Success', `Registration for ${userCreate.username} complete.`)
df98563e 68 this.router.navigate([ '/videos/list' ])
a184c71b
C
69 },
70
f7354483 71 err => this.error = err.message
df98563e 72 )
a184c71b
C
73 }
74}