Project

General

Profile

1
/**
2
 * Created by stefania on 7/5/16.
3
 */
4

    
5
import {Component, OnInit, ViewEncapsulation} from "@angular/core";
6
import {AuthenticationService} from '../../services/authentication.service';
7

    
8
@Component({
9
  selector: 'top-menu',
10
  templateUrl: './topmenu.component.html',
11
  encapsulation: ViewEncapsulation.None
12
})
13

    
14
export class TopMenuComponent implements OnInit {
15
  userLoggedIn: boolean = false;
16
  userName: string = '';
17
  isUserAdmin: boolean = false;
18
  adminHomePage = process.env.FAQ_HOMEPAGE;
19

    
20
  constructor(public authService: AuthenticationService) { }
21

    
22
  ngOnInit() {
23
    this.getIsUserLoggedIn();
24
    this.getUserName();
25
    this.getIsUserAdmin();
26
  }
27

    
28

    
29
  onClick(id: string) {
30
    var el: HTMLElement = document.getElementById(id);
31
    el.classList.remove('uk-open');
32
  }
33

    
34

    
35
  login(){
36
    this.authService.loginWithState();
37
  }
38

    
39
  logout(){
40
    if( this.userLoggedIn ){
41
      this.authService.logout();
42
    }
43
  }
44

    
45

    
46
  getUserName() {
47
    this.userName = this.authService.getUserName();
48
    return this.userName;
49
  }
50

    
51
  getIsUserLoggedIn() {
52
    this.userLoggedIn = this.authService.getIsUserLoggedIn();
53
    return this.userLoggedIn;
54
  }
55

    
56
  getIsUserAdmin() {
57
    this.isUserAdmin = (this.authService.getUserRole().includes('ROLE_ADMIN'));
58
    return this.isUserAdmin;
59
  }
60
}
(2-2/2)