Project

General

Profile

« Previous | Next » 

Revision 48966

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

View differences:

helper.class.ts
9 9
    id: string;
10 10
    fullname: string;
11 11
    expirationDate: number;
12
    role:string;
12
    role:string[];
13 13
    jwt:string;
14 14

  
15 15
}
......
50 50
              loggedIn = false;
51 51
            }
52 52
          }else{
53
            if(cookie != null && this.getUserFromCookie()!= null){
53
            if(cookie != null && this.getUserFromCookie()!= null){              
54 54
               loggedIn = true
55 55
            }else{
56 56
              loggedIn = false;
......
68 68
      var user:User = MyJWT.parseUserInfo(cookie);
69 69
       if( typeof localStorage !== 'undefined') {
70 70
         localStorage.setItem("user", JSON.stringify(user));
71
         if(user && user.email){
71
         if(user && user.email && Session.isRegisteredUser()){
72 72
           COOKIE.deleteCookie(COOKIE.cookieName_u); // delete cookie to avoid transfer through requests
73 73
           return user;
74 74
         }else{
......
97 97
      }
98 98

  
99 99
  }
100
  public static getCurrentUrl():string {
101
    if( typeof localStorage !== 'undefined') {
102
        return localStorage.getItem("url");
103
    }
104
    return "";
105

  
106
    }
107
  public static setCurrentUrl(url:string) {
108
        if( typeof localStorage !== 'undefined') {
109
          localStorage.setItem("url", url);
110
        }
111
  }
112
  public static getCurrentParameters():any {
113
    if( typeof localStorage !== 'undefined') {
114
      var params = localStorage.getItem("params");
115
       var object= {};
116
      for(var i=0; i<params.split("&").length; i++){
117
        object[(params.split("&")[i]).split("=")[0]] = (params.split("&")[i]).split("=")[1];
118
      }
119
      return object;
120
    }
121
    return {};
122
  }
123
  public static setCurrentParameters(params:string) {
124
    if( typeof localStorage !== 'undefined') {
125
         localStorage.setItem("params",(params && params.length > 1)? params.substring(1):"");
126
       }
127
  }
100 128
  public static isAdminUser():boolean {
129
      var isAdmin = false;
101 130
      if(Session.isLoggedIn()){
102
          return (Session.getUser().role == '2');
131
        var claimRoles = ["urn:mace:openminted.eu:aai.openminted.eu:group:OpenAIRE+Curator+-+Claim","urn:mace:openminted.eu:aai.openminted.eu:group:OpenAIRE+Portal+Administrator"]
132

  
133
        for (var i = 0; i < claimRoles.length; i++) {
134
            if ((Session.getUser().role).indexOf(claimRoles[i]) > -1) {
135
                isAdmin = true;
136
                break;
137
            }
138
        }
139
          // console.log("Is admin:"+ isAdmin)
140
          return (isAdmin);
103 141
      }
104

  
142
      // console.log("Is admin:"+ isAdmin)
143
      return (isAdmin);
105 144
  }
145
  public static isRegisteredUser():boolean {
146
      var isRegisteredUser = false;
147
      if(Session.isLoggedIn()){
148
        var claimRoles = ["urn:mace:openminted.eu:aai.openminted.eu:group:Registered+User"];
149
        for (var i = 0; i < claimRoles.length; i++) {
150
            if ((Session.getUser().role).indexOf(claimRoles[i]) > -1) {
151
                isRegisteredUser = true;
152
                break;
153
            }
154
        }
155
          // console.log("Is isRegisteredUser:"+ isRegisteredUser)
156
          return (isRegisteredUser);
157
      }
158
      // console.log("Is isRegisteredUser:"+ isRegisteredUser)
159
      return (isRegisteredUser);
160
  }
106 161
  public static isUserValid() {
107 162
    if(Session.isLoggedIn()){
108 163
        var expires = Session.getUser().expirationDate;
......
150 205
      user.email = info.email;
151 206
      // user.id = info.userId;
152 207
      user.fullname = (StringUtils.URIDecode(info.fullname)).replace("+"," ");
153
      user.role = info.role;;
208
      user.role =JSON.parse( StringUtils.URIDecode(info.role));
209
      // console.log("User Role is:");
210
      // console.log(user.role)
154 211
      user.jwt = data;
155 212
      user.expirationDate = info.exp;
156 213
      localStorage.setItem("user", JSON.stringify(user));

Also available in: Unified diff