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