Read the proper roles from AAI, add a reload page after login that redirects to the previous page

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-portal/trunk@48966 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
argiro.kokogiannaki 2017-09-15 08:37:53 +00:00
parent c3ddb73e5f
commit 16123df09d
7 changed files with 179 additions and 13 deletions

View File

@ -148,6 +148,10 @@ export function getUserModule() {
return System.import('./login/user.module' + (process.env.AOT ? '.ngfactory' : '')) return System.import('./login/user.module' + (process.env.AOT ? '.ngfactory' : ''))
.then(mod => mod[(process.env.AOT ? 'UserModuleNgFactory' : 'UserModule')]); .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({ @NgModule({
imports: [ imports: [
RouterModule.forChild([ RouterModule.forChild([
@ -187,6 +191,7 @@ export function getUserModule() {
{ path: 'participate/direct-claim', loadChildren: getDirectLinkingModule }, { path: 'participate/direct-claim', loadChildren: getDirectLinkingModule },
{ path: 'claims-project-manager', loadChildren: getClaimsByTokenModule }, { path: 'claims-project-manager', loadChildren: getClaimsByTokenModule },
{ path: 'user-info', loadChildren: getUserModule }, { path: 'user-info', loadChildren: getUserModule },
{ path: 'reload', loadChildren: getReloadModule },
]) ])
], ],

View File

@ -6,6 +6,7 @@ import {Location} from '@angular/common';
import {User,Session} from './utils/helper.class'; import {User,Session} from './utils/helper.class';
import {RouterHelper} from '../utils/routerHelper.class'; import {RouterHelper} from '../utils/routerHelper.class';
import {OpenaireProperties} from '../utils/properties/openaireProperties'; import {OpenaireProperties} from '../utils/properties/openaireProperties';
import {StringUtils} from '../utils/string-utils.class';
@Component({ @Component({
selector: 'user-mini', selector: 'user-mini',
@ -16,7 +17,7 @@ import {OpenaireProperties} from '../utils/properties/openaireProperties';
<a *ngIf="loggedIn" > <a *ngIf="loggedIn" >
<span>{{user.fullname+" "}} <span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg></span></span> <span>{{user.fullname+" "}} <span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg></span></span>
</a> </a>
<a *ngIf="!loggedIn" class="loginLink" [href]="loginUrl" >Sign in | Register <span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg> </span> <a *ngIf="!loggedIn" class="loginLink" (click)="logIn()" >Sign in | Register <span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg> </span>
</a> </a>
@ -40,7 +41,7 @@ import {OpenaireProperties} from '../utils/properties/openaireProperties';
<span>{{user.fullname+" "}}<span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg></span></span> <span>{{user.fullname+" "}}<span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg></span></span>
</span> </span>
<span *ngIf="!loggedIn"> <span *ngIf="!loggedIn">
<a class="loginLink" [href]="loginUrl" >Sign in | Register <span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg></span> <a class="loginLink" (click)="logIn()" >Sign in | Register <span class="uk-margin-small-right uk-icon" ><svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" ratio="1"><circle fill="none" stroke="#000" stroke-width="1.1" cx="9.9" cy="6.4" r="4.4"></circle><path fill="none" stroke="#000" stroke-width="1.1" d="M1.5,19 C2.3,14.5 5.8,11.2 10,11.2 C14.2,11.2 17.7,14.6 18.5,19.2"></path></svg></span>
</a> </a>
</span> </span>
@ -62,7 +63,6 @@ export class UserMiniComponent {
@Input() public mobileView:boolean = false ; @Input() public mobileView:boolean = false ;
public server: boolean = true; public server: boolean = true;
public routerHelper:RouterHelper = new RouterHelper(); public routerHelper:RouterHelper = new RouterHelper();
public loginUrl= OpenaireProperties.getLoginURL();
public redirectUrl: string = ""; public redirectUrl: string = "";
private baseUrl = "user-info"; private baseUrl = "user-info";
@ -92,6 +92,7 @@ export class UserMiniComponent {
}else { }else {
this.isAuthorized = false; this.isAuthorized = false;
} }
}else{ }else{
Session.removeUser(); Session.removeUser();
this.loggedIn = false; this.loggedIn = false;
@ -116,7 +117,8 @@ export class UserMiniComponent {
logOut(){ logOut(){
if(Session.isLoggedIn()){ if(Session.isLoggedIn()){
Session.removeUser(); 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; this.loggedIn = false;
@ -124,6 +126,12 @@ export class UserMiniComponent {
this.user = new User(); this.user = new User();
} }
logIn(){
Session.setCurrentUrl(location.pathname);
Session.setCurrentParameters(location.search);
window.location.href = OpenaireProperties.getLoginURL();
}
onClick(id: string) { onClick(id: string) {
var el: HTMLElement = document.getElementById(id); var el: HTMLElement = document.getElementById(id);
el.classList.remove('uk-open'); el.classList.remove('uk-open');

View File

@ -9,7 +9,7 @@ export class User {
id: string; id: string;
fullname: string; fullname: string;
expirationDate: number; expirationDate: number;
role:string; role:string[];
jwt:string; jwt:string;
} }
@ -68,7 +68,7 @@ export class Session{
var user:User = MyJWT.parseUserInfo(cookie); var user:User = MyJWT.parseUserInfo(cookie);
if( typeof localStorage !== 'undefined') { if( typeof localStorage !== 'undefined') {
localStorage.setItem("user", JSON.stringify(user)); 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 COOKIE.deleteCookie(COOKIE.cookieName_u); // delete cookie to avoid transfer through requests
return user; return user;
}else{ }else{
@ -97,11 +97,66 @@ export class Session{
} }
} }
public static isAdminUser():boolean { public static getCurrentUrl():string {
if(Session.isLoggedIn()){ if( typeof localStorage !== 'undefined') {
return (Session.getUser().role == '2'); 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<params.split("&").length; i++){
object[(params.split("&")[i]).split("=")[0]] = (params.split("&")[i]).split("=")[1];
}
return object;
}
return {};
}
public static setCurrentParameters(params:string) {
if( typeof localStorage !== 'undefined') {
localStorage.setItem("params",(params && params.length > 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() { public static isUserValid() {
if(Session.isLoggedIn()){ if(Session.isLoggedIn()){
@ -150,7 +205,9 @@ export class MyJWT{
user.email = info.email; user.email = info.email;
// user.id = info.userId; // user.id = info.userId;
user.fullname = (StringUtils.URIDecode(info.fullname)).replace("+"," "); 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.jwt = data;
user.expirationDate = info.exp; user.expirationDate = info.exp;
localStorage.setItem("user", JSON.stringify(user)); localStorage.setItem("user", JSON.stringify(user));

View File

@ -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 { }

View File

@ -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: `
<div id="tm-main" class=" uk-section uk-margin-small-top tm-middle" >
<div uk-grid uk-grid>
<div class="tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first ">
<div class="uk-container uk-margin-top publication">
Go to initial page....
</div>
</div>
</div>
</div>
`
})
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(['/']);
}
}
}

View File

@ -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 { }

View File

@ -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', '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', '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', 'project-report', 'claims','myclaims','participate/claim', 'participate/direct-claim', 'claims-project-manager',
'test', 'user-info', 'test', 'user-info', 'reload',
'**','error' '**','error'
]; ];