mirror of
https://github.com/GNS3/gns3-web-ui.git
synced 2025-02-02 01:08:21 +00:00
Fix for redirection to login page
This commit is contained in:
parent
06ad9c2f07
commit
a5b4a12849
@ -22,6 +22,7 @@ export class LoginComponent implements OnInit {
|
||||
public version: string;
|
||||
public isLightThemeEnabled: boolean = false;
|
||||
public loginError: boolean = false;
|
||||
public returnUrl: string = "";
|
||||
|
||||
loginForm = new FormGroup({
|
||||
username: new FormControl('', [Validators.required]),
|
||||
@ -41,6 +42,7 @@ export class LoginComponent implements OnInit {
|
||||
|
||||
async ngOnInit() {
|
||||
const server_id = this.route.snapshot.paramMap.get('server_id');
|
||||
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
|
||||
this.serverService.get(parseInt(server_id, 10)).then((server: Server) => {
|
||||
this.server = server;
|
||||
|
||||
@ -72,7 +74,12 @@ export class LoginComponent implements OnInit {
|
||||
server.authToken = response.access_token;
|
||||
await this.serverService.update(server);
|
||||
|
||||
this.router.navigate(['/server', this.server.id, 'projects']);
|
||||
if (this.returnUrl.length <= 1) {
|
||||
this.router.navigate(['/server', this.server.id, 'projects'])
|
||||
} else {
|
||||
this.router.navigateByUrl(this.returnUrl);
|
||||
}
|
||||
|
||||
}, error => {
|
||||
this.loginError = true;
|
||||
});
|
||||
|
@ -1,19 +1,20 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot } from '@angular/router';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { Server } from 'app/models/server';
|
||||
import { ServerService } from '../services/server.service';
|
||||
|
||||
@Injectable()
|
||||
export class LoginGuard implements CanActivate {
|
||||
constructor(
|
||||
private serverService: ServerService
|
||||
private serverService: ServerService,
|
||||
private router: Router
|
||||
) {}
|
||||
|
||||
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
const server_id = next.paramMap.get('server_id');
|
||||
return this.serverService.get(parseInt(server_id, 10)).then((server: Server) => {
|
||||
if (server.authToken) return true;
|
||||
return false
|
||||
this.router.navigate(['/server', server.id, 'login'], { queryParams: { returnUrl: state.url }});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
|
||||
public isInstalledSoftwareAvailable = false;
|
||||
public uiVersion = version;
|
||||
public isLoginPage = false;
|
||||
public routeSubscription;
|
||||
|
||||
serverStatusSubscription: Subscription;
|
||||
shouldStopServersOnClosing = true;
|
||||
@ -41,9 +42,10 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
|
||||
) {}
|
||||
|
||||
ngOnInit() {
|
||||
if (this.router.url.includes("login")) {
|
||||
this.isLoginPage = true;
|
||||
};
|
||||
this.checkIfUserIsLoginPage();
|
||||
this.routeSubscription = this.router.events.subscribe((val) => {
|
||||
if (val instanceof NavigationEnd) this.checkIfUserIsLoginPage();
|
||||
});
|
||||
|
||||
this.recentlyOpenedServerId = this.recentlyOpenedProjectService.getServerId();
|
||||
this.recentlyOpenedProjectId = this.recentlyOpenedProjectService.getProjectId();
|
||||
@ -67,6 +69,14 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
|
||||
this.shouldStopServersOnClosing = this.electronService.isElectronApp;
|
||||
}
|
||||
|
||||
checkIfUserIsLoginPage() {
|
||||
if (this.router.url.includes("login")) {
|
||||
this.isLoginPage = true;
|
||||
} else {
|
||||
this.isLoginPage = false;
|
||||
}
|
||||
}
|
||||
|
||||
logout() {
|
||||
let serverId = this.router.url.split("/server/")[1].split("/")[0];
|
||||
this.serverService.get(+serverId).then((server: Server) => {
|
||||
@ -104,5 +114,6 @@ export class DefaultLayoutComponent implements OnInit, OnDestroy {
|
||||
|
||||
ngOnDestroy() {
|
||||
this.serverStatusSubscription.unsubscribe();
|
||||
this.routeSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user