From 7955acd2bc0aa6eadc745a8ed53d75d8693d5bff Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Fri, 13 Sep 2019 09:38:21 +0000 Subject: [PATCH] [Library]: Fix some issues on guards. Change session is Logged in to check user's token. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57071 d315682c-612b-4755-9ff5-7f18f6832af3 --- connect/communityGuard/connectAdminLoginGuard.guard.ts | 1 + connect/communityGuard/connectSubscriber.guard.ts | 3 ++- connect/userEmailPreferences/mailPrefs.component.ts | 4 ---- login/utils/helper.class.ts | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/connect/communityGuard/connectAdminLoginGuard.guard.ts b/connect/communityGuard/connectAdminLoginGuard.guard.ts index 467a548a..12948ef4 100644 --- a/connect/communityGuard/connectAdminLoginGuard.guard.ts +++ b/connect/communityGuard/connectAdminLoginGuard.guard.ts @@ -34,6 +34,7 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad { if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) { return of(true); } else { + errorCode = LoginErrorCodes.NOT_ADMIN; return this.communityService.isCommunityManager(properties, properties['communityAPI'] + community, email); } diff --git a/connect/communityGuard/connectSubscriber.guard.ts b/connect/communityGuard/connectSubscriber.guard.ts index 27624249..d2e48b8b 100644 --- a/connect/communityGuard/connectSubscriber.guard.ts +++ b/connect/communityGuard/connectSubscriber.guard.ts @@ -18,11 +18,12 @@ export class ConnectSubscriberGuard implements CanActivate { private propertiesService: EnvironmentSpecificService) {} check(community: string, path: string): Observable | boolean { - let errorCode = LoginErrorCodes.NOT_SUBSCRIBER; + let errorCode = LoginErrorCodes.NOT_LOGIN; let email = null; const subscribed = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => { return this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => { if (user) { + errorCode = LoginErrorCodes.NOT_SUBSCRIBER; email = user.email; let communityDomain = ConnectHelper.getCommunityFromDomain(properties.domain); if(communityDomain) { diff --git a/connect/userEmailPreferences/mailPrefs.component.ts b/connect/userEmailPreferences/mailPrefs.component.ts index ba7090eb..0837a202 100644 --- a/connect/userEmailPreferences/mailPrefs.component.ts +++ b/connect/userEmailPreferences/mailPrefs.component.ts @@ -35,8 +35,6 @@ export class MailPrefsComponent { public userValidMessage:string = ""; public savedMessage: string = ""; - public fetchId:string; - private errorCodes: ErrorCodes; private errorMessages: ErrorMessagesComponent; @@ -58,8 +56,6 @@ export class MailPrefsComponent { this.communityId = params['communityId']; } - this.fetchId = Session.getUserEmail(); - this.getEmailPreferences(); }); diff --git a/login/utils/helper.class.ts b/login/utils/helper.class.ts index 302cae40..4db27cb9 100644 --- a/login/utils/helper.class.ts +++ b/login/utils/helper.class.ts @@ -25,7 +25,7 @@ export class Session{ public static isLoggedIn(): boolean { var loggedIn:boolean = false; var user:User = null; - var cookie= COOKIE.getCookie(COOKIE.cookieName_u); + var cookie= COOKIE.getCookie(COOKIE.cookieName_id); if(cookie == null ||cookie == ""){ return false; }else{