component.ts 1.7 KB
Newer Older
1
// Copyright 2017 The Kubernetes Authors.
2 3 4 5 6 7 8 9 10 11 12 13 14
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

15 16 17
import {Component, OnInit} from '@angular/core';
import {LoginStatus} from '@api/backendapi';
import {AuthService} from '../../common/services/global/authentication';
18

19 20 21 22
@Component({
  selector: 'kd-user-panel',
  templateUrl: './template.html',
  styleUrls: ['./style.scss'],
S
Sebastian Florek 已提交
23
  host: {
S
Sebastian Florek 已提交
24
    '[class.kd-hidden]': 'this.isAuthEnabled() === false',
S
Shu Muto 已提交
25
  },
26
})
S
Sebastian Florek 已提交
27 28
export class UserPanelComponent implements OnInit {
  loginStatus: LoginStatus;
S
Sebastian Florek 已提交
29
  isLoginStatusInitialized = false;
S
Sebastian Florek 已提交
30

S
Sebastian Florek 已提交
31
  constructor(private readonly authService_: AuthService) {}
S
Sebastian Florek 已提交
32 33 34 35

  ngOnInit(): void {
    this.authService_.getLoginStatus().subscribe(status => {
      this.loginStatus = status;
S
Sebastian Florek 已提交
36
      this.isLoginStatusInitialized = true;
S
Sebastian Florek 已提交
37 38 39 40
    });
  }

  isAuthSkipped(): boolean {
M
Marcin Maciaszczyk 已提交
41
    return this.loginStatus && !this.authService_.isLoginPageEnabled() && !this.loginStatus.headerPresent;
S
Sebastian Florek 已提交
42 43 44
  }

  isLoggedIn(): boolean {
S
Shu Muto 已提交
45
    return this.loginStatus && !this.loginStatus.headerPresent && this.loginStatus.tokenPresent;
S
Sebastian Florek 已提交
46 47 48
  }

  isAuthEnabled(): boolean {
S
Sebastian Florek 已提交
49
    return this.loginStatus ? this.loginStatus.httpsMode : false;
S
Sebastian Florek 已提交
50 51 52 53 54 55
  }

  logout(): void {
    this.authService_.logout();
  }
}