]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/angular/users/components/login/login.component.ts
Add a loader animation when loading the videos list
[github/Chocobozzz/PeerTube.git] / client / angular / users / components / login / login.component.ts
CommitLineData
230809ef
C
1import { Component } from '@angular/core';
2import { Router } from '@angular/router-deprecated';
b1794c53
C
3
4import { AuthService } from '../../services/auth.service';
5import { AuthStatus } from '../../models/authStatus';
1553e15d 6import { User } from '../../models/user';
b1794c53
C
7
8@Component({
9 selector: 'my-user-login',
10 styleUrls: [ 'app/angular/users/components/login/login.component.css' ],
11 templateUrl: 'app/angular/users/components/login/login.component.html'
12})
13
14export class UserLoginComponent {
15 constructor(private _authService: AuthService, private _router: Router) {}
16
17 login(username: string, password: string) {
18 this._authService.login(username, password).subscribe(
19 result => {
1553e15d
C
20 const user = new User(username, result);
21 user.save();
b1794c53
C
22
23 this._authService.setStatus(AuthStatus.LoggedIn);
24
25 this._router.navigate(['VideosList']);
26 },
1553e15d
C
27 error => {
28 if (error.error === 'invalid_grant') {
29 alert('Credentials are invalid.');
2e2bef6f
C
30 } else {
31 alert(`${error.error}: ${error.error_description}`);
1553e15d
C
32 }
33 }
b1794c53
C
34 );
35 }
36}