Login Guards implement now CanLoad
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@54649 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
ddeb96ee32
commit
e73b632bc3
|
@ -16,7 +16,7 @@ export class ConnectAdminLoginGuard implements CanActivate {
|
|||
var user;
|
||||
var loggedIn = false;
|
||||
var isAdmin = false;
|
||||
var errorCode = LoginErrorCodes.NOT_LOGGIN;
|
||||
var errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
|
||||
let community = (route.queryParams["communityId"]);
|
||||
if(Session.isLoggedIn()){
|
||||
|
@ -39,7 +39,7 @@ export class ConnectAdminLoginGuard implements CanActivate {
|
|||
return obs;
|
||||
}
|
||||
}else{
|
||||
errorCode =LoginErrorCodes.NOT_LOGGIN;
|
||||
errorCode =LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
|
||||
return false;
|
||||
|
|
|
@ -16,7 +16,7 @@ export class ConnectRIGuard implements CanActivate {
|
|||
var user;
|
||||
var loggedIn = false;
|
||||
var isAdmin = false;
|
||||
var errorCode = LoginErrorCodes.NOT_LOGGIN;
|
||||
var errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
|
||||
let community = (route.queryParams["communityId"]);
|
||||
if(Session.isLoggedIn()){
|
||||
|
@ -39,7 +39,7 @@ export class ConnectRIGuard implements CanActivate {
|
|||
return obs;
|
||||
}
|
||||
}else{
|
||||
errorCode =LoginErrorCodes.NOT_LOGGIN;
|
||||
errorCode =LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
|
||||
return false;
|
||||
|
|
|
@ -16,14 +16,14 @@ export class ConnectSubscriberGuard implements CanActivate {
|
|||
console.log(state.url);
|
||||
var user;
|
||||
var authorized = false;
|
||||
var errorCode = LoginErrorCodes.NOT_SUBSCIBER;
|
||||
var errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||
|
||||
let community = (route.queryParams["communityId"]);
|
||||
if(!community){
|
||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
}
|
||||
if(!Session.isLoggedIn()){
|
||||
errorCode = LoginErrorCodes.NOT_LOGGIN;
|
||||
errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -1,45 +1,38 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
||||
@Injectable()
|
||||
export class AdminLoginGuard implements CanActivate {
|
||||
export class AdminLoginGuard implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
var user;
|
||||
var loggedIn = false;
|
||||
var isAdmin = false;
|
||||
var errorCode = LoginErrorCodes.NOT_LOGGIN;
|
||||
check(route: Route) : boolean{
|
||||
let loggedIn = false;
|
||||
let isAdmin = false;
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
if(Session.isLoggedIn()){
|
||||
loggedIn = true;
|
||||
if(!Session.isLoggedIn()){
|
||||
loggedIn = false;
|
||||
errorCode = LoginErrorCodes.NOT_VALID;
|
||||
}else {
|
||||
isAdmin = Session.isPortalAdministrator();
|
||||
if(!isAdmin){
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
isAdmin = Session.isPortalAdministrator();
|
||||
if(!isAdmin){
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
}else{
|
||||
errorCode =LoginErrorCodes.NOT_LOGGIN;
|
||||
}
|
||||
|
||||
if(!loggedIn){
|
||||
if(!loggedIn || !isAdmin) {
|
||||
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
|
||||
return false;
|
||||
}else if(!isAdmin){
|
||||
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
route.path = '/' + route.path;
|
||||
this.router.navigate(['user-info'], {queryParams: {"errorCode": errorCode, "redirectUrl": route.path}});
|
||||
}
|
||||
return loggedIn && isAdmin;
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(route.routeConfig);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check(route);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +1,43 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
||||
@Injectable()
|
||||
export class ClaimsCuratorGuard implements CanActivate {
|
||||
export class ClaimsCuratorGuard implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
var user;
|
||||
var role = route.data['role']
|
||||
var loggedIn = false;
|
||||
var isAuthorized = false;
|
||||
var errorCode = LoginErrorCodes.NOT_LOGGIN;
|
||||
check(route: Route) : boolean{
|
||||
//var user;
|
||||
//var role = route.data['role']
|
||||
let loggedIn = false;
|
||||
let isAuthorized = false;
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
|
||||
if(Session.isLoggedIn()){
|
||||
loggedIn = true;
|
||||
if(!Session.isLoggedIn()){
|
||||
loggedIn = false;
|
||||
errorCode = LoginErrorCodes.NOT_VALID;
|
||||
}else {
|
||||
if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
|
||||
isAuthorized =true;
|
||||
}
|
||||
if(!Session.isClaimsCurator() && !Session.isPortalAdministrator()){
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
errorCode =LoginErrorCodes.NOT_LOGGIN;
|
||||
if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
|
||||
isAuthorized = true;
|
||||
}
|
||||
else {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
}
|
||||
|
||||
if(!loggedIn){
|
||||
if(!loggedIn || !isAuthorized){
|
||||
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
|
||||
return false;
|
||||
}else if(!isAuthorized){
|
||||
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
route.path = '/' + route.path;
|
||||
this.router.navigate(['user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": route.path } });
|
||||
}
|
||||
return loggedIn && isAuthorized;
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(route.routeConfig);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check(route);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +1,38 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, ActivatedRoute} from '@angular/router';
|
||||
import {
|
||||
Router,
|
||||
CanActivate,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
Route,
|
||||
CanLoad
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
||||
@Injectable()
|
||||
export class FreeGuard implements CanActivate {
|
||||
export class FreeGuard implements CanActivate, CanLoad{
|
||||
|
||||
constructor(private router: Router) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
var user;
|
||||
var valid = true;
|
||||
var loggedIn = false;
|
||||
var errorCode = LoginErrorCodes.NOT_LOGGIN;
|
||||
|
||||
if(Session.isLoggedIn()){
|
||||
loggedIn = true;
|
||||
if(!Session.isLoggedIn()){
|
||||
loggedIn = false;
|
||||
valid = false;
|
||||
errorCode = LoginErrorCodes.NOT_VALID;
|
||||
}
|
||||
}
|
||||
|
||||
check(route: Route):boolean {
|
||||
//var user;
|
||||
let valid = true;
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
if(!valid){
|
||||
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
||||
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
return false;
|
||||
route.path = '/' + route.path;
|
||||
this.router.navigate(['user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": route.path } });
|
||||
}
|
||||
return true;
|
||||
return valid;
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(route.routeConfig);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check(route);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,34 +1,35 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Router,CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Route, CanLoad} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
||||
@Injectable()
|
||||
export class LoginGuard implements CanActivate {
|
||||
export class LoginGuard implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router) {}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
var user;
|
||||
var loggedIn = false;
|
||||
var errorCode = LoginErrorCodes.NOT_LOGGIN;
|
||||
check(route: Route): boolean{
|
||||
//var user;
|
||||
let loggedIn = false;
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
|
||||
if(Session.isLoggedIn()){
|
||||
if(Session.isLoggedIn()) {
|
||||
loggedIn = true;
|
||||
if(!Session.isLoggedIn()){
|
||||
loggedIn = false;
|
||||
errorCode = LoginErrorCodes.NOT_VALID;
|
||||
}
|
||||
}else{
|
||||
errorCode = LoginErrorCodes.NOT_LOGGIN;
|
||||
}
|
||||
if(!loggedIn){
|
||||
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
route.path = '/' + route.path;
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": route.path } });
|
||||
}
|
||||
return loggedIn;
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(route.routeConfig);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check(route);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,11 +11,11 @@ import { Router} from '@angular/router';
|
|||
//
|
||||
// }
|
||||
export class LoginErrorCodes {
|
||||
public static NOT_LOGGIN:number =1;
|
||||
public static NOT_LOGIN:number =1;
|
||||
public static NOT_ADMIN:number =2;
|
||||
public static NOT_VALID:number =3;
|
||||
public static NOT_CONNECT_ADMIN:number =4;
|
||||
public static NO_COMMUNITY:number =5;
|
||||
public static NOT_SUBSCIBER:number =6;
|
||||
public static NOT_SUBSCRIBER:number =6;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue