]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/login/login.component.ts
Client: Add authHttp service that authentificates the http request and
[github/Chocobozzz/PeerTube.git] / client / src / app / login / login.component.ts
1 import { Component } from '@angular/core';
2 import { Router } from '@angular/router';
3
4 import { AuthService } from '../shared';
5
6 @Component({
7 selector: 'my-login',
8 template: require('./login.component.html')
9 })
10
11 export class LoginComponent {
12 error: string = null;
13
14 constructor(
15 private authService: AuthService,
16 private router: Router
17 ) {}
18
19 login(username: string, password: string) {
20 this.authService.login(username, password).subscribe(
21 result => {
22 this.error = null;
23
24 this.router.navigate(['/videos/list']);
25 },
26 error => {
27 console.error(error);
28
29 if (error.error === 'invalid_grant') {
30 this.error = 'Credentials are invalid.';
31 } else {
32 this.error = `${error.error}: ${error.error_description}`;
33 }
34 }
35 );
36 }
37 }