]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/login/login.component.ts
Add tags support to the video list
[github/Chocobozzz/PeerTube.git] / client / src / app / login / login.component.ts
CommitLineData
230809ef 1import { Component } from '@angular/core';
00a44645 2import { Router } from '@angular/router';
b1794c53 3
4a6995be 4import { AuthService, AuthStatus, User } from '../shared';
b1794c53
C
5
6@Component({
a840d396 7 selector: 'my-login',
4a6995be 8 template: require('./login.component.html')
b1794c53
C
9})
10
a840d396 11export class LoginComponent {
192ea60b
C
12 error: string = null;
13
4fd8aa32
C
14 constructor(
15 private authService: AuthService,
16 private router: Router
17 ) {}
b1794c53
C
18
19 login(username: string, password: string) {
ccf6ed16 20 this.authService.login(username, password).subscribe(
b1794c53 21 result => {
192ea60b
C
22 this.error = null;
23
1553e15d
C
24 const user = new User(username, result);
25 user.save();
b1794c53 26
ccf6ed16 27 this.authService.setStatus(AuthStatus.LoggedIn);
b1794c53 28
00a44645 29 this.router.navigate(['/videos/list']);
b1794c53 30 },
1553e15d
C
31 error => {
32 if (error.error === 'invalid_grant') {
192ea60b 33 this.error = 'Credentials are invalid.';
2e2bef6f 34 } else {
192ea60b 35 this.error = `${error.error}: ${error.error_description}`;
1553e15d
C
36 }
37 }
b1794c53
C
38 );
39 }
40}