]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/login/login.component.ts
First draft to use webpack instead of systemjs
[github/Chocobozzz/PeerTube.git] / client / src / app / login / login.component.ts
1 import { Component } from '@angular/core';
2 import { Router } from '@angular/router-deprecated';
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 constructor(
13 private authService: AuthService,
14 private router: Router
15 ) {}
16
17 login(username: string, password: string) {
18 this.authService.login(username, password).subscribe(
19 result => {
20 const user = new User(username, result);
21 user.save();
22
23 this.authService.setStatus(AuthStatus.LoggedIn);
24
25 this.router.navigate(['VideosList']);
26 },
27 error => {
28 if (error.error === 'invalid_grant') {
29 alert('Credentials are invalid.');
30 } else {
31 alert(`${error.error}: ${error.error_description}`);
32 }
33 }
34 );
35 }
36 }