]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/signup/signup.component.ts
Fix client admin
[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',
19 templateUrl: './signup.component.html'
20})
21export class SignupComponent extends FormReactive implements OnInit {
df98563e 22 error: string = null
a184c71b 23
df98563e 24 form: FormGroup
a184c71b
C
25 formErrors = {
26 'username': '',
27 'email': '',
28 'password': ''
df98563e 29 }
a184c71b
C
30 validationMessages = {
31 'username': USER_USERNAME.MESSAGES,
32 'email': USER_EMAIL.MESSAGES,
df98563e
C
33 'password': USER_PASSWORD.MESSAGES
34 }
a184c71b 35
df98563e 36 constructor (
a184c71b
C
37 private formBuilder: FormBuilder,
38 private router: Router,
39 private notificationsService: NotificationsService,
40 private userService: UserService
41 ) {
df98563e 42 super()
a184c71b
C
43 }
44
df98563e 45 buildForm () {
a184c71b
C
46 this.form = this.formBuilder.group({
47 username: [ '', USER_USERNAME.VALIDATORS ],
48 email: [ '', USER_EMAIL.VALIDATORS ],
df98563e
C
49 password: [ '', USER_PASSWORD.VALIDATORS ]
50 })
a184c71b 51
df98563e 52 this.form.valueChanges.subscribe(data => this.onValueChanged(data))
a184c71b
C
53 }
54
df98563e
C
55 ngOnInit () {
56 this.buildForm()
a184c71b
C
57 }
58
df98563e
C
59 signup () {
60 this.error = null
a184c71b 61
4771e000 62 const userCreate: UserCreate = this.form.value
a184c71b 63
4771e000 64 this.userService.signup(userCreate).subscribe(
a184c71b 65 () => {
4771e000 66 this.notificationsService.success('Success', `Registration for ${userCreate.username} complete.`)
df98563e 67 this.router.navigate([ '/videos/list' ])
a184c71b
C
68 },
69
70 err => this.error = err.text
df98563e 71 )
a184c71b
C
72 }
73}