diff options
Diffstat (limited to 'client/angular/users/components/login/login.component.ts')
-rw-r--r-- | client/angular/users/components/login/login.component.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/client/angular/users/components/login/login.component.ts b/client/angular/users/components/login/login.component.ts new file mode 100644 index 000000000..0881a3a15 --- /dev/null +++ b/client/angular/users/components/login/login.component.ts | |||
@@ -0,0 +1,32 @@ | |||
1 | import { Component } from 'angular2/core'; | ||
2 | import { Router } from 'angular2/router'; | ||
3 | |||
4 | import { AuthService } from '../../services/auth.service'; | ||
5 | import { AuthStatus } from '../../models/authStatus'; | ||
6 | import { Token } from '../../models/token'; | ||
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 | |||
14 | export 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 => { | ||
20 | if (result.error) return alert(result.error_description); | ||
21 | |||
22 | let token = new Token(result); | ||
23 | token.save(); | ||
24 | |||
25 | this._authService.setStatus(AuthStatus.LoggedIn); | ||
26 | |||
27 | this._router.navigate(['VideosList']); | ||
28 | }, | ||
29 | error => alert(error) | ||
30 | ); | ||
31 | } | ||
32 | } | ||