aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/menu/menu.component.ts
blob: e2b9987478f56f92f0923b054db247d02cf9eee2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { AuthService, AuthStatus } from '../auth';
import { ConfigService } from '../config';

@Component({
  selector: 'my-menu',
  templateUrl: './menu.component.html',
  styleUrls: [ './menu-admin.component.scss' ]
})
export class MenuComponent implements OnInit {
  isLoggedIn: boolean;

  constructor (
    private authService: AuthService,
    private configService: ConfigService,
    private router: Router
  ) {}

  ngOnInit() {
    this.isLoggedIn = this.authService.isLoggedIn();

    this.authService.loginChangedSource.subscribe(
      status => {
        if (status === AuthStatus.LoggedIn) {
          this.isLoggedIn = true;
          console.log('Logged in.');
        } else if (status === AuthStatus.LoggedOut) {
          this.isLoggedIn = false;
          console.log('Logged out.');
        } else {
          console.error('Unknown auth status: ' + status);
        }
      }
    );
  }

  isRegistrationEnabled() {
    return this.configService.getConfig().signup.enabled;
  }

  isUserAdmin() {
    return this.authService.isAdmin();
  }

  logout() {
    this.authService.logout();
    // Redirect to home page
    this.router.navigate(['/videos/list']);
  }
}