[Library]: Delele user cookie from Helper.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57078 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
a77afb15c9
commit
4b8a9627b3
|
@ -15,80 +15,15 @@ export class User {
|
|||
export class Session{
|
||||
public static removeUser() {
|
||||
COOKIE.deleteCookie(COOKIE.cookieName_id)
|
||||
COOKIE.deleteCookie(COOKIE.cookieName_u);
|
||||
COOKIE.deleteCookie("openAIRESession");
|
||||
|
||||
}
|
||||
public static getUser():User {
|
||||
return this.getUserFromCookie();
|
||||
}
|
||||
|
||||
public static isLoggedIn(): boolean {
|
||||
var cookie= COOKIE.getCookie(COOKIE.cookieName_id);
|
||||
return (cookie != null && cookie != "");
|
||||
}
|
||||
|
||||
public static getUserFromCookie():User{
|
||||
var cookie= COOKIE.getCookie(COOKIE.cookieName_u);
|
||||
if(cookie != null && cookie!=""){
|
||||
var user:User = this.parseUserInfo(cookie);
|
||||
if(user && user.email){
|
||||
return user;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static parseUserInfo(data: any): User {
|
||||
|
||||
var dataStr:string = data.substr(1,data.length-2).replace(/\\/g,"");
|
||||
var info = JSON.parse(dataStr);
|
||||
var user: User = new User();
|
||||
var sub = (info.sub)?StringUtils.URIDecode(info.sub):"";
|
||||
user.id = (sub && sub.indexOf('@'))?sub.substring(0,sub.indexOf('@')):sub;
|
||||
|
||||
user.firstname = (StringUtils.URIDecode((info.firstname && info.firstname!="")?info.firstname:"")).replace("+"," ");
|
||||
user.lastname = (StringUtils.URIDecode((info.lastname && info.lastname!="")?info.lastname:"")).replace("+"," ");
|
||||
user.email = info.email;
|
||||
user.fullname = (StringUtils.URIDecode((info.fullname && info.fullname!="")?info.fullname:"")).replace("+"," ");
|
||||
if(user.fullname == ""){
|
||||
if(user.firstname != ""){
|
||||
user.fullname += user.firstname;
|
||||
}
|
||||
if(user.lastname !=""){
|
||||
user.fullname += user.lastname;
|
||||
}
|
||||
if(user.fullname == ""){ //fullname is still empty set a default
|
||||
user.fullname = "Anonymous user";
|
||||
}
|
||||
}
|
||||
if(info.role && info.role != ""){
|
||||
user.role =JSON.parse( StringUtils.URIDecode(info.role));
|
||||
}else{
|
||||
user.role =[];
|
||||
}
|
||||
user.expirationDate = info.exp;
|
||||
return user;
|
||||
}
|
||||
|
||||
public static getUserEmail():string {
|
||||
var user:User = this.getUserFromCookie();
|
||||
if(user!=null){
|
||||
return user.email;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static getUserFullName():string {
|
||||
var user:User = this.getUserFromCookie();
|
||||
if(user!=null){
|
||||
return user.fullname;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static setReloadUrl(host:string,path:string, params:string) {
|
||||
var URL = {};
|
||||
URL["host"]=host;
|
||||
|
@ -117,80 +52,6 @@ export class Session{
|
|||
}
|
||||
|
||||
//Methods to check roles
|
||||
// OLD
|
||||
/* public static isClaimsCurator():boolean {
|
||||
var isAuthorized = false;
|
||||
if(Session.isLoggedIn()){
|
||||
var roles = ["urn:geant:openaire.eu:group:Curator+-+Claim#aai.openaire.eu"]
|
||||
for (var i = 0; i < roles.length; i++) {
|
||||
if ((Session.getUser().role).indexOf(roles[i]) > -1) {
|
||||
isAuthorized = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isAuthorized;
|
||||
}
|
||||
return isAuthorized;
|
||||
}
|
||||
public static isCommunityCurator():boolean {
|
||||
var isAuthorized = false;
|
||||
if(Session.isLoggedIn()){
|
||||
var roles = ["urn:geant:openaire.eu:group:Curator+-+Community#aai.openaire.eu"]
|
||||
for (var i = 0; i < roles.length; i++) {
|
||||
if ((Session.getUser().role).indexOf(roles[i]) > -1) {
|
||||
isAuthorized = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isAuthorized;
|
||||
}
|
||||
return isAuthorized;
|
||||
}
|
||||
public static isPortalAdministrator():boolean {
|
||||
var isAuthorized = false;
|
||||
if(Session.isLoggedIn()){
|
||||
var roles = ["urn:geant:openaire.eu:group:Portal+Administrator#aai.openaire.eu"]
|
||||
for (var i = 0; i < roles.length; i++) {
|
||||
if ((Session.getUser().role).indexOf(roles[i]) > -1) {
|
||||
isAuthorized = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isAuthorized;
|
||||
}
|
||||
return isAuthorized;
|
||||
}
|
||||
public static isUserManager():boolean {
|
||||
var isAuthorized = false;
|
||||
if(Session.isLoggedIn()){
|
||||
var roles = ["urn:geant:openaire.eu:group:User+Manager#aai.openaire.eu"];
|
||||
for (var i = 0; i < roles.length; i++) {
|
||||
if ((Session.getUser().role).indexOf(roles[i]) > -1) {
|
||||
isAuthorized = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isAuthorized;
|
||||
}
|
||||
return isAuthorized;
|
||||
}
|
||||
public static isRegisteredUser():boolean {
|
||||
var isAuthorized = false;
|
||||
if(Session.isLoggedIn()){
|
||||
var claimRoles = ["urn:geant:openaire.eu:group:Registered+User#aai.openaire.eu"];
|
||||
for (var i = 0; i < claimRoles.length; i++) {
|
||||
if ((Session.getUser().role).indexOf(claimRoles[i]) > -1) {
|
||||
isAuthorized = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isAuthorized;
|
||||
}
|
||||
return isAuthorized;
|
||||
}*/
|
||||
|
||||
// NEW
|
||||
|
||||
public static isClaimsCurator(user: User): boolean {
|
||||
return user !== null &&
|
||||
user.role.indexOf('urn:geant:openaire.eu:group:Curator+-+Claim#aai.openaire.eu') !== -1;
|
||||
|
@ -219,7 +80,6 @@ export class Session{
|
|||
|
||||
}
|
||||
export class COOKIE{
|
||||
public static cookieName_u:string="openAIREUser"//"XCsrfToken";
|
||||
public static cookieName_id:string="AccessToken";
|
||||
|
||||
public static getCookie(name: string) : string {
|
||||
|
|
Loading…
Reference in New Issue