]>
Commit | Line | Data |
---|---|---|
230809ef C |
1 | import { Component } from '@angular/core'; |
2 | import { Router } from '@angular/router-deprecated'; | |
b1794c53 | 3 | |
41a2aee3 | 4 | import { AuthService, AuthStatus, User } from '../shared/index'; |
b1794c53 C |
5 | |
6 | @Component({ | |
7 | selector: 'my-user-login', | |
41a2aee3 C |
8 | styleUrls: [ 'client/app/users/login/login.component.css' ], |
9 | templateUrl: 'client/app/users/login/login.component.html' | |
b1794c53 C |
10 | }) |
11 | ||
12 | export class UserLoginComponent { | |
13 | constructor(private _authService: AuthService, private _router: Router) {} | |
14 | ||
15 | login(username: string, password: string) { | |
16 | this._authService.login(username, password).subscribe( | |
17 | result => { | |
1553e15d C |
18 | const user = new User(username, result); |
19 | user.save(); | |
b1794c53 C |
20 | |
21 | this._authService.setStatus(AuthStatus.LoggedIn); | |
22 | ||
23 | this._router.navigate(['VideosList']); | |
24 | }, | |
1553e15d C |
25 | error => { |
26 | if (error.error === 'invalid_grant') { | |
27 | alert('Credentials are invalid.'); | |
2e2bef6f C |
28 | } else { |
29 | alert(`${error.error}: ${error.error_description}`); | |
1553e15d C |
30 | } |
31 | } | |
b1794c53 C |
32 | ); |
33 | } | |
34 | } |