diff --git a/portal-2/src/app/app-routing.module.ts b/portal-2/src/app/app-routing.module.ts index 831a53cc..fac1677a 100644 --- a/portal-2/src/app/app-routing.module.ts +++ b/portal-2/src/app/app-routing.module.ts @@ -148,6 +148,10 @@ export function getUserModule() { return System.import('./login/user.module' + (process.env.AOT ? '.ngfactory' : '')) .then(mod => mod[(process.env.AOT ? 'UserModuleNgFactory' : 'UserModule')]); } +export function getReloadModule() { + return System.import('./reload/reload.module' + (process.env.AOT ? '.ngfactory' : '')) + .then(mod => mod[(process.env.AOT ? 'ReloadModuleNgFactory' : 'ReloadModule')]); +} @NgModule({ imports: [ RouterModule.forChild([ @@ -187,6 +191,7 @@ export function getUserModule() { { path: 'participate/direct-claim', loadChildren: getDirectLinkingModule }, { path: 'claims-project-manager', loadChildren: getClaimsByTokenModule }, { path: 'user-info', loadChildren: getUserModule }, + { path: 'reload', loadChildren: getReloadModule }, ]) ], diff --git a/portal-2/src/app/login/userMini.component.ts b/portal-2/src/app/login/userMini.component.ts index 2253d47d..9a122516 100644 --- a/portal-2/src/app/login/userMini.component.ts +++ b/portal-2/src/app/login/userMini.component.ts @@ -6,6 +6,7 @@ import {Location} from '@angular/common'; import {User,Session} from './utils/helper.class'; import {RouterHelper} from '../utils/routerHelper.class'; import {OpenaireProperties} from '../utils/properties/openaireProperties'; +import {StringUtils} from '../utils/string-utils.class'; @Component({ selector: 'user-mini', @@ -16,7 +17,7 @@ import {OpenaireProperties} from '../utils/properties/openaireProperties'; {{user.fullname+" "}} - Sign in | Register + Sign in | Register @@ -40,7 +41,7 @@ import {OpenaireProperties} from '../utils/properties/openaireProperties'; {{user.fullname+" "}} - Sign in | Register + Sign in | Register @@ -62,7 +63,6 @@ export class UserMiniComponent { @Input() public mobileView:boolean = false ; public server: boolean = true; public routerHelper:RouterHelper = new RouterHelper(); - public loginUrl= OpenaireProperties.getLoginURL(); public redirectUrl: string = ""; private baseUrl = "user-info"; @@ -92,6 +92,7 @@ export class UserMiniComponent { }else { this.isAuthorized = false; } + }else{ Session.removeUser(); this.loggedIn = false; @@ -116,7 +117,8 @@ export class UserMiniComponent { logOut(){ if(Session.isLoggedIn()){ Session.removeUser(); - window.location.href = OpenaireProperties.getLogoutURL()+ location.href; + console.log("Redirect to "+location.href); + window.location.href = OpenaireProperties.getLogoutURL()+ StringUtils.URIEncode(location.href); } this.loggedIn = false; @@ -124,6 +126,12 @@ export class UserMiniComponent { this.user = new User(); } + logIn(){ + Session.setCurrentUrl(location.pathname); + Session.setCurrentParameters(location.search); + window.location.href = OpenaireProperties.getLoginURL(); + } + onClick(id: string) { var el: HTMLElement = document.getElementById(id); el.classList.remove('uk-open'); diff --git a/portal-2/src/app/login/utils/helper.class.ts b/portal-2/src/app/login/utils/helper.class.ts index 44792659..a7089978 100644 --- a/portal-2/src/app/login/utils/helper.class.ts +++ b/portal-2/src/app/login/utils/helper.class.ts @@ -9,7 +9,7 @@ export class User { id: string; fullname: string; expirationDate: number; - role:string; + role:string[]; jwt:string; } @@ -50,7 +50,7 @@ export class Session{ loggedIn = false; } }else{ - if(cookie != null && this.getUserFromCookie()!= null){ + if(cookie != null && this.getUserFromCookie()!= null){ loggedIn = true }else{ loggedIn = false; @@ -68,7 +68,7 @@ export class Session{ var user:User = MyJWT.parseUserInfo(cookie); if( typeof localStorage !== 'undefined') { localStorage.setItem("user", JSON.stringify(user)); - if(user && user.email){ + if(user && user.email && Session.isRegisteredUser()){ COOKIE.deleteCookie(COOKIE.cookieName_u); // delete cookie to avoid transfer through requests return user; }else{ @@ -97,11 +97,66 @@ export class Session{ } } - public static isAdminUser():boolean { - if(Session.isLoggedIn()){ - return (Session.getUser().role == '2'); - } + public static getCurrentUrl():string { + if( typeof localStorage !== 'undefined') { + return localStorage.getItem("url"); + } + return ""; + } + public static setCurrentUrl(url:string) { + if( typeof localStorage !== 'undefined') { + localStorage.setItem("url", url); + } + } + public static getCurrentParameters():any { + if( typeof localStorage !== 'undefined') { + var params = localStorage.getItem("params"); + var object= {}; + for(var i=0; i 1)? params.substring(1):""); + } + } + public static isAdminUser():boolean { + var isAdmin = false; + if(Session.isLoggedIn()){ + var claimRoles = ["urn:mace:openminted.eu:aai.openminted.eu:group:OpenAIRE+Curator+-+Claim","urn:mace:openminted.eu:aai.openminted.eu:group:OpenAIRE+Portal+Administrator"] + + for (var i = 0; i < claimRoles.length; i++) { + if ((Session.getUser().role).indexOf(claimRoles[i]) > -1) { + isAdmin = true; + break; + } + } + // console.log("Is admin:"+ isAdmin) + return (isAdmin); + } + // console.log("Is admin:"+ isAdmin) + return (isAdmin); + } + public static isRegisteredUser():boolean { + var isRegisteredUser = false; + if(Session.isLoggedIn()){ + var claimRoles = ["urn:mace:openminted.eu:aai.openminted.eu:group:Registered+User"]; + for (var i = 0; i < claimRoles.length; i++) { + if ((Session.getUser().role).indexOf(claimRoles[i]) > -1) { + isRegisteredUser = true; + break; + } + } + // console.log("Is isRegisteredUser:"+ isRegisteredUser) + return (isRegisteredUser); + } + // console.log("Is isRegisteredUser:"+ isRegisteredUser) + return (isRegisteredUser); } public static isUserValid() { if(Session.isLoggedIn()){ @@ -150,7 +205,9 @@ export class MyJWT{ user.email = info.email; // user.id = info.userId; user.fullname = (StringUtils.URIDecode(info.fullname)).replace("+"," "); - user.role = info.role;; + user.role =JSON.parse( StringUtils.URIDecode(info.role)); + // console.log("User Role is:"); + // console.log(user.role) user.jwt = data; user.expirationDate = info.exp; localStorage.setItem("user", JSON.stringify(user)); diff --git a/portal-2/src/app/reload/reload-routing.module.ts b/portal-2/src/app/reload/reload-routing.module.ts new file mode 100644 index 00000000..f304da05 --- /dev/null +++ b/portal-2/src/app/reload/reload-routing.module.ts @@ -0,0 +1,16 @@ +import { NgModule } from '@angular/core'; +import { RouterModule } from '@angular/router'; + +import{ReloadComponent} from './reload.component'; +import {FreeGuard} from'../login/freeGuard.guard'; +import {PreviousRouteRecorder} from '../utils/piwik/previousRouteRecorder.guard'; + +@NgModule({ + imports: [ + RouterModule.forChild([ + { path: '', component: ReloadComponent, canActivate: [FreeGuard], canDeactivate: [PreviousRouteRecorder] } + + ]) + ] +}) +export class ReloadRoutingModule { } diff --git a/portal-2/src/app/reload/reload.component.ts b/portal-2/src/app/reload/reload.component.ts new file mode 100644 index 00000000..94ddceab --- /dev/null +++ b/portal-2/src/app/reload/reload.component.ts @@ -0,0 +1,51 @@ +import {Component, Input, Output, EventEmitter, ViewChild} from '@angular/core'; +import {Observable} from 'rxjs/Observable'; +import {ActivatedRoute, Router} from '@angular/router'; +import {Location} from '@angular/common'; + +import {OpenaireProperties} from '../utils/properties/openaireProperties'; +import {ErrorCodes} from '../utils/properties/openaireProperties'; +import {RouterHelper} from '../utils/routerHelper.class'; +import {Session} from '../login/utils/helper.class'; + +@Component({ + selector: 'reload', + template: ` +
+
+
+ +
+ Go to initial page.... +
+
+
+
+ ` +}) +export class ReloadComponent { + + constructor ( + private route: ActivatedRoute, + private _router: Router, + private location: Location + ) { + + } + + public ngOnInit() { + + var url = Session.getCurrentUrl(); + if(url && url != null && url != ""){ + Session.setCurrentUrl(""); + var array = Session.getCurrentParameters(); + Session.setCurrentParameters(""); + this._router.navigate([url],{ queryParams: array}); + + }else{ + this._router.navigate(['/']); + + } + } + +} diff --git a/portal-2/src/app/reload/reload.module.ts b/portal-2/src/app/reload/reload.module.ts new file mode 100644 index 00000000..2b7e8469 --- /dev/null +++ b/portal-2/src/app/reload/reload.module.ts @@ -0,0 +1,29 @@ +import { NgModule} from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { FormsModule } from '@angular/forms'; +import { RouterModule } from '@angular/router'; + +import{ReloadRoutingModule } from './reload-routing.module'; +import{ReloadComponent} from './reload.component'; + + + import {FreeGuard} from'../login/freeGuard.guard'; +import {PreviousRouteRecorder} from '../utils/piwik/previousRouteRecorder.guard'; + +@NgModule({ + imports: [ + CommonModule, FormsModule, RouterModule, + ReloadRoutingModule + + ], + declarations: [ + ReloadComponent + ], + providers:[ + FreeGuard, PreviousRouteRecorder + ], + exports: [ + ReloadComponent + ] +}) +export class ReloadModule { } diff --git a/portal-2/src/server.routes.ts b/portal-2/src/server.routes.ts index c5ebd134..b6de3c0b 100644 --- a/portal-2/src/server.routes.ts +++ b/portal-2/src/server.routes.ts @@ -17,7 +17,7 @@ export const routes: string[] = [ 'participate/deposit-publications','participate/deposit-datasets','participate/deposit-publications-result','participate/deposit-datasets-result', 'participate/deposit-subject-result', 'search/content-providers','search/content-providers-table','search/entity-registries','search/entity-registries-table','search/journals','search/journals-table', 'project-report', 'claims','myclaims','participate/claim', 'participate/direct-claim', 'claims-project-manager', - 'test', 'user-info', + 'test', 'user-info', 'reload', '**','error' ];