]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/login/login.component.ts
Server: avoid request entity too large for requests between pods
[github/Chocobozzz/PeerTube.git] / client / src / app / login / login.component.ts
CommitLineData
0f6da32b
C
1import { Component, OnInit } from '@angular/core';
2import { Validators } from '@angular/common';
3import { FormControl, FormGroup, REACTIVE_FORM_DIRECTIVES } from '@angular/forms';
00a44645 4import { Router } from '@angular/router';
b1794c53 5
bd5c83a8 6import { AuthService } from '../shared';
b1794c53
C
7
8@Component({
a840d396 9 selector: 'my-login',
0f6da32b
C
10 template: require('./login.component.html'),
11 directives: [ REACTIVE_FORM_DIRECTIVES ]
b1794c53
C
12})
13
0f6da32b 14export class LoginComponent implements OnInit {
192ea60b 15 error: string = null;
0f6da32b
C
16 username = '';
17 password: '';
18 loginForm: FormGroup;
192ea60b 19
4fd8aa32
C
20 constructor(
21 private authService: AuthService,
22 private router: Router
23 ) {}
b1794c53 24
0f6da32b
C
25 ngOnInit() {
26 this.loginForm = new FormGroup({
27 username: new FormControl('', [ <any>Validators.required ]),
28 password: new FormControl('', [ <any>Validators.required ]),
29 });
30 }
31
32 login() {
33 this.authService.login(this.username, this.password).subscribe(
b1794c53 34 result => {
192ea60b
C
35 this.error = null;
36
00a44645 37 this.router.navigate(['/videos/list']);
b1794c53 38 },
1553e15d 39 error => {
bd5c83a8
C
40 console.error(error);
41
1553e15d 42 if (error.error === 'invalid_grant') {
192ea60b 43 this.error = 'Credentials are invalid.';
2e2bef6f 44 } else {
192ea60b 45 this.error = `${error.error}: ${error.error_description}`;
1553e15d
C
46 }
47 }
b1794c53
C
48 );
49 }
50}