]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/core/auth/login/login.component.ts
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / core / auth / login / login.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { Router } from '@angular/router';
3
4 import { BsModalService } from 'ngx-bootstrap/modal';
5
6 import { AuthService } from '../../../shared/api/auth.service';
7 import { Credentials } from '../../../shared/models/credentials';
8 import { AuthStorageService } from '../../../shared/services/auth-storage.service';
9
10 @Component({
11 selector: 'cd-login',
12 templateUrl: './login.component.html',
13 styleUrls: ['./login.component.scss']
14 })
15 export class LoginComponent implements OnInit {
16 model = new Credentials();
17 isLoginActive = false;
18
19 constructor(
20 private authService: AuthService,
21 private authStorageService: AuthStorageService,
22 private bsModalService: BsModalService,
23 private router: Router
24 ) {}
25
26 ngOnInit() {
27 if (this.authStorageService.isLoggedIn()) {
28 this.router.navigate(['']);
29 } else {
30 // Make sure all open modal dialogs are closed. This might be
31 // necessary when the logged in user is redirected to the login
32 // page after a 401.
33 const modalsCount = this.bsModalService.getModalsCount();
34 for (let i = 1; i <= modalsCount; i++) {
35 this.bsModalService.hide(i);
36 }
37 let token = null;
38 if (window.location.hash.indexOf('access_token=') !== -1) {
39 token = window.location.hash.split('access_token=')[1];
40 const uri = window.location.toString();
41 window.history.replaceState({}, document.title, uri.split('?')[0]);
42 }
43 this.authService.check(token).subscribe((login: any) => {
44 if (login.login_url) {
45 if (login.login_url === '#/login') {
46 this.isLoginActive = true;
47 } else {
48 window.location.replace(login.login_url);
49 }
50 } else {
51 this.authStorageService.set(login.username, token, login.permissions);
52 this.router.navigate(['']);
53 }
54 });
55 }
56 }
57
58 login() {
59 this.authService.login(this.model).then(() => {
60 this.router.navigate(['']);
61 });
62 }
63 }