From ca54df782c1ad25af58f99db7f4c90ce88d571e8 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Mon, 21 Sep 2020 12:50:04 +0000 Subject: [PATCH] [Library|Trunk] Login guard: correct query params for redirectUrl user compoents: fixes for the use of baselink (don't add it when already exists in the route), rename baseurl to route in components functions git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59442 d315682c-612b-4755-9ff5-7f18f6832af3 --- login/loginGuard.guard.ts | 4 ++-- login/user.component.ts | 14 +++++++------- login/userMini.component.ts | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/login/loginGuard.guard.ts b/login/loginGuard.guard.ts index 3e2363a9..6e13fdfb 100644 --- a/login/loginGuard.guard.ts +++ b/login/loginGuard.guard.ts @@ -19,11 +19,11 @@ export class LoginGuard implements CanActivate, CanLoad { return user !== null; })); obs.pipe(filter(isLoggedIn => !isLoggedIn)).subscribe(() => { - this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}}); + this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN,'redirectUrl': path}}); }); return obs; } else { - this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}}); + this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, 'redirectUrl':path}}); return false; } } diff --git a/login/user.component.ts b/login/user.component.ts index f097ea7b..4b51b925 100644 --- a/login/user.component.ts +++ b/login/user.component.ts @@ -77,12 +77,12 @@ export class UserComponent { redirect() { if (this.redirectUrl && this.redirectUrl != "") { this.redirectUrl = decodeURIComponent(this.redirectUrl); - var baseUrl = this.redirectUrl; + var route = this.redirectUrl; var queryParams = ""; var paramsArray = []; var valuesArray = []; if (this.redirectUrl.indexOf('?') != -1) { - baseUrl = this.redirectUrl.split('?')[0]; + route = this.redirectUrl.split('?')[0]; queryParams = this.redirectUrl.split('?')[1]; } if (queryParams != "") { @@ -91,9 +91,9 @@ export class UserComponent { paramsArray.push(queryParamsArray[i].split("=")[0]); valuesArray.push(queryParamsArray[i].split("=")[1]); } - this.router.navigate([baseUrl], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)}); + this.router.navigate([route], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)}); } else { - this.router.navigate([baseUrl]); + this.router.navigate([route]); } } // else{ @@ -104,18 +104,18 @@ export class UserComponent { logIn() { if (this.redirectUrl && this.redirectUrl != "") { this.redirectUrl = decodeURIComponent(this.redirectUrl); - var baseUrl = this.redirectUrl; + var route = this.redirectUrl; var queryParams = ""; if (this.redirectUrl.indexOf('?') != -1) { var splits = this.redirectUrl.split('?'); if (splits.length > 0) { - baseUrl = splits[0]; + route = splits[0]; } if (splits.length > 1) { queryParams = splits[1]; } } - Session.setReloadUrl(location.protocol + "//" + location.host,properties.baseLink + baseUrl, queryParams); + Session.setReloadUrl(location.protocol + "//" + location.host,properties.baseLink + route, queryParams); } console.log(Session.getReloadUrl()); window.location.href = this.properties.loginUrl; diff --git a/login/userMini.component.ts b/login/userMini.component.ts index d55c718f..44fdcefd 100644 --- a/login/userMini.component.ts +++ b/login/userMini.component.ts @@ -239,7 +239,7 @@ export class UserMiniComponent implements OnInit, OnChanges { } logIn() { - Session.setReloadUrl(location.protocol + "//" + location.host, properties.baseLink + this.redirectUrl, this.search); + Session.setReloadUrl(location.protocol + "//" + location.host, this.redirectUrl, this.search); window.location.href = this.logInUrl; }