]>
Commit | Line | Data |
---|---|---|
beacf699 | 1 | import { Component, OnInit } from '@angular/core'; |
ab32b0fc | 2 | import { Router } from '@angular/router'; |
602eb142 C |
3 | |
4 | import { AuthService, AuthStatus } from './shared'; | |
5 | ||
6 | @Component({ | |
7 | selector: 'my-menu', | |
ec8d8440 | 8 | templateUrl: './menu.component.html' |
602eb142 C |
9 | }) |
10 | export class MenuComponent implements OnInit { | |
602eb142 C |
11 | isLoggedIn: boolean; |
12 | ||
13 | constructor ( | |
14 | private authService: AuthService, | |
15 | private router: Router | |
16 | ) {} | |
17 | ||
18 | ngOnInit() { | |
19 | this.isLoggedIn = this.authService.isLoggedIn(); | |
20 | ||
21 | this.authService.loginChangedSource.subscribe( | |
22 | status => { | |
23 | if (status === AuthStatus.LoggedIn) { | |
24 | this.isLoggedIn = true; | |
25 | console.log('Logged in.'); | |
26 | } else if (status === AuthStatus.LoggedOut) { | |
27 | this.isLoggedIn = false; | |
28 | console.log('Logged out.'); | |
29 | } else { | |
30 | console.error('Unknown auth status: ' + status); | |
31 | } | |
32 | } | |
33 | ); | |
34 | } | |
35 | ||
602eb142 C |
36 | isUserAdmin() { |
37 | return this.authService.isAdmin(); | |
38 | } | |
39 | ||
40 | logout() { | |
41 | this.authService.logout(); | |
42 | // Redirect to home page | |
43 | this.router.navigate(['/videos/list']); | |
44 | } | |
45 | } |