]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/login/login.component.ts
Fix redirection after the upload of a video
[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, AuthStatus, User } 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 const user = new User(username, result);
25 user.save();
26
27 this.authService.setStatus(AuthStatus.LoggedIn);
28
29 this.router.navigate(['/videos/list']);
30 },
31 error => {
32 if (error.error === 'invalid_grant') {
33 this.error = 'Credentials are invalid.';
34 } else {
35 this.error = `${error.error}: ${error.error_description}`;
36 }
37 }
38 );
39 }
40 }