[Trunk|Library]: CanLoad does not work in connect guards, maybe it works in angular 6
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@54912 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
0bddc14435
commit
75533e17bf
|
@ -1,136 +1,78 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {Http, Response} from '@angular/http';
|
||||
import {Headers, RequestOptions} from '@angular/http';
|
||||
import {Observable} from 'rxjs/Rx';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Http} from '@angular/http';
|
||||
|
||||
import {CommunityInfo} from '../community/communityInfo';
|
||||
import{EnvProperties} from '../../utils/properties/env-properties';
|
||||
import {CommunityInfo} from '../community/communityInfo';
|
||||
import {EnvProperties} from '../../utils/properties/env-properties';
|
||||
|
||||
@Injectable()
|
||||
export class CommunitiesService {
|
||||
|
||||
constructor(private http:Http) {
|
||||
constructor(private http: Http) {
|
||||
}
|
||||
|
||||
getCommunities(properties:EnvProperties, url: string) {
|
||||
return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)) : url)
|
||||
getCommunities(properties: EnvProperties, url: string) {
|
||||
return this.http.get((properties.useCache) ? (properties.cacheUrl + encodeURIComponent(url)) : url)
|
||||
.map(res => <any> res.json()).map(res => this.parseCommunities(res));
|
||||
}
|
||||
|
||||
parseCommunities(data: any): CommunityInfo[] {
|
||||
let communities: CommunityInfo[] = [];
|
||||
const communities: CommunityInfo[] = [];
|
||||
|
||||
let length = Array.isArray(data) ? data.length :1;
|
||||
const length = Array.isArray(data) ? data.length : 1;
|
||||
|
||||
for (let i=0; i<length; i++) {
|
||||
let resData = Array.isArray(data) ? data[i] : data;
|
||||
|
||||
var result: CommunityInfo = new CommunityInfo();
|
||||
//TODO @Sofia remove this if/else
|
||||
// if there is case to be array do with resData what you do with data ( let resData = Array.isArray(data) ? data[i] : data;)
|
||||
//don;t repeat the same code
|
||||
if(Array.isArray(resData)) {
|
||||
result['title'] = resData[0].name;
|
||||
result['shortTitle'] = resData[0].shortName;
|
||||
result['communityId'] = resData[0].id;
|
||||
result['queryId'] = resData[0].queryId;
|
||||
result['logoUrl'] = resData[0].logoUrl;
|
||||
result['description'] = resData[0].description;
|
||||
result['date'] = resData[0].creationDate;
|
||||
result['status'] = "all";
|
||||
if(resData[0].hasOwnProperty('status')){
|
||||
result['status'] = resData[0].status;
|
||||
var status = ["all","hidden","manager"];
|
||||
if(status.indexOf(result['status']) ==-1){
|
||||
result['status'] = "hidden";
|
||||
}
|
||||
}
|
||||
|
||||
if (resData[0].type != null) {
|
||||
result['type'] = resData[0].type;
|
||||
}
|
||||
|
||||
if(resData[0].managers != null) {
|
||||
if(result['managers'] == undefined) {
|
||||
result['managers'] = new Array<string>();
|
||||
}
|
||||
|
||||
let managers = resData[0].managers;
|
||||
let length = Array.isArray(managers) ? managers.length : 1;
|
||||
|
||||
for(let i=0; i<length; i++) {
|
||||
let manager = Array.isArray(managers) ? managers[i] : managers;
|
||||
result.managers[i] = manager;
|
||||
}
|
||||
}
|
||||
|
||||
if(resData[0].subjects != null) {
|
||||
if(result['subjects'] == undefined) {
|
||||
result['subjects'] = new Array<string>();
|
||||
}
|
||||
|
||||
let subjects = resData[0].subjects;
|
||||
let length = Array.isArray(subjects) ? subjects.length : 1;
|
||||
|
||||
for(let i=0; i<length; i++) {
|
||||
let subject = Array.isArray(subjects) ? subjects[i] : subjects;
|
||||
result.subjects[i] = subject;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
result['title'] = resData.name;
|
||||
result['shortTitle'] = resData.shortName;
|
||||
result['communityId'] = resData.id;
|
||||
result['queryId'] = resData.queryId;
|
||||
result['logoUrl'] = resData.logoUrl;
|
||||
result['description'] = resData.description;
|
||||
result['date'] = resData.creationDate;
|
||||
result['status'] = "all";
|
||||
if(resData.hasOwnProperty('status')){
|
||||
result['status'] = resData.status;
|
||||
var status = ["all","hidden","manager"];
|
||||
if(status.indexOf(result['status']) ==-1){
|
||||
result['status'] = "hidden";
|
||||
}
|
||||
}
|
||||
if (resData.type != null) {
|
||||
result['type'] = resData.type;
|
||||
}
|
||||
|
||||
if(resData.managers != null) {
|
||||
if(result['managers'] == undefined) {
|
||||
result['managers'] = new Array<string>();
|
||||
}
|
||||
|
||||
let managers = resData.managers;
|
||||
let length = Array.isArray(managers) ? managers.length : 1;
|
||||
|
||||
for(let i=0; i<length; i++) {
|
||||
let manager = Array.isArray(managers) ? managers[i] : managers;
|
||||
result.managers[i] = manager;
|
||||
}
|
||||
}
|
||||
|
||||
if(resData.subjects != null) {
|
||||
if(result['subjects'] == undefined) {
|
||||
result['subjects'] = new Array<string>();
|
||||
}
|
||||
|
||||
let subjects = resData.subjects;
|
||||
let length = Array.isArray(subjects) ? subjects.length : 1;
|
||||
|
||||
for(let i=0; i<length; i++) {
|
||||
let subject = Array.isArray(subjects) ? subjects[i] : subjects;
|
||||
result.subjects[i] = subject;
|
||||
}
|
||||
for (let i = 0; i < length; i++) {
|
||||
const resData = Array.isArray(data) ? data[i] : data;
|
||||
const result: CommunityInfo = new CommunityInfo();
|
||||
result['title'] = resData.name;
|
||||
result['shortTitle'] = resData.shortName;
|
||||
result['communityId'] = resData.id;
|
||||
result['queryId'] = resData.queryId;
|
||||
result['logoUrl'] = resData.logoUrl;
|
||||
result['description'] = resData.description;
|
||||
result['date'] = resData.creationDate;
|
||||
result['status'] = 'all';
|
||||
if (resData.hasOwnProperty('status')) {
|
||||
result['status'] = resData.status;
|
||||
const status = ['all', 'hidden', 'manager'];
|
||||
if (status.indexOf(result['status']) === -1) {
|
||||
result['status'] = 'hidden';
|
||||
}
|
||||
}
|
||||
if (result['type'] == 'community' || result['type'] == "ri") {
|
||||
communities.push(result);
|
||||
if (resData.type != null) {
|
||||
result['type'] = resData.type;
|
||||
}
|
||||
|
||||
if (resData.managers != null) {
|
||||
if (result['managers'] === undefined) {
|
||||
result['managers'] = new Array<string>();
|
||||
}
|
||||
|
||||
const managers = resData.managers;
|
||||
const lengthManagers = Array.isArray(managers) ? managers.length : 1;
|
||||
|
||||
for (let j = 0; j < lengthManagers; j++) {
|
||||
const manager = Array.isArray(managers) ? managers[j] : managers;
|
||||
result.managers[j] = manager;
|
||||
}
|
||||
}
|
||||
|
||||
if (resData.subjects != null) {
|
||||
if (result['subjects'] === undefined) {
|
||||
result['subjects'] = new Array<string>();
|
||||
}
|
||||
|
||||
const subjects = resData.subjects;
|
||||
const lengthSubjects = Array.isArray(subjects) ? subjects.length : 1;
|
||||
|
||||
for (let j = 0; j < lengthSubjects; j++) {
|
||||
const subject = Array.isArray(subjects) ? subjects[i] : subjects;
|
||||
result.subjects[j] = subject;
|
||||
}
|
||||
}
|
||||
if (result['type'] === 'community' || result['type'] === 'ri') {
|
||||
communities.push(result);
|
||||
}
|
||||
}
|
||||
|
||||
return communities;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,52 +7,50 @@ import {
|
|||
ActivatedRoute,
|
||||
CanLoad, Route
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from '../../login/utils/helper.class';
|
||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||
import {CommunityService} from '../community/community.service';
|
||||
import { EnvironmentSpecificService} from '../../utils/properties/environment-specific.service';
|
||||
import { mergeMap } from 'rxjs/operators';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectAdminLoginGuard implements CanActivate, CanLoad{
|
||||
constructor(private router: Router,
|
||||
private communityService: CommunityService,
|
||||
private propertiesService:EnvironmentSpecificService,
|
||||
private route: ActivatedRoute) {}
|
||||
private propertiesService: EnvironmentSpecificService) {}
|
||||
|
||||
check(path: string): Observable<boolean> | boolean {
|
||||
check(route: ActivatedRouteSnapshot, path: string): Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
let community = this.route.queryParams["communityId"];
|
||||
const community = route.queryParams['communityId'];
|
||||
if (Session.isLoggedIn()) {
|
||||
if (Session.isPortalAdministrator() || Session.isCommunityCurator()) {
|
||||
return true;
|
||||
} else {
|
||||
let obs = this.propertiesService.subscribeEnvironment().map(res => res).mergeMap(properties => {
|
||||
return this.communityService.iscommunityManager(properties, properties["communityAPI"] + community, Session.getUserEmail())
|
||||
const obs = this.propertiesService.subscribeEnvironment().map(res => res).mergeMap(properties => {
|
||||
return this.communityService.iscommunityManager(properties, properties['communityAPI'] + community, Session.getUserEmail());
|
||||
});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
"errorCode": errorCode,
|
||||
"redirectUrl": path
|
||||
'errorCode': errorCode,
|
||||
'redirectUrl': path
|
||||
}
|
||||
}));
|
||||
return obs;
|
||||
}
|
||||
} else {
|
||||
errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], {queryParams: {"errorCode": errorCode, "redirectUrl": path}});
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(state.url);
|
||||
return this.check(route, state.url);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check('/' + route.path);
|
||||
return this.check(null, '/' + route.path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
CanLoad,
|
||||
Route, ActivatedRoute
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from '../../login/utils/helper.class';
|
||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||
import {CommunityService} from '../community/community.service';
|
||||
|
@ -16,41 +16,44 @@ import { EnvironmentSpecificService} from '../../utils/properties/environment-sp
|
|||
@Injectable()
|
||||
export class ConnectRIGuard implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router, private communityService: CommunityService, private propertiesService:EnvironmentSpecificService, private route:ActivatedRoute) {}
|
||||
constructor(private router: Router,
|
||||
private communityService: CommunityService,
|
||||
private propertiesService: EnvironmentSpecificService) {
|
||||
}
|
||||
|
||||
check(path: string) : Observable<boolean> | boolean {
|
||||
check(route: ActivatedRouteSnapshot, path: string): Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
let community = (this.route.queryParams["communityId"]);
|
||||
const community = (route.queryParams['communityId']);
|
||||
|
||||
if(Session.isLoggedIn()) {
|
||||
if(Session.isPortalAdministrator()) {
|
||||
if (Session.isLoggedIn()) {
|
||||
if (Session.isPortalAdministrator()) {
|
||||
return true;
|
||||
} else {
|
||||
let obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
||||
return this.communityService.iscommunityRI(properties, properties["communityAPI"] + community)
|
||||
const obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
||||
return this.communityService.iscommunityRI(properties, properties['communityAPI'] + community);
|
||||
});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
"errorCode": errorCode,
|
||||
"redirectUrl": path
|
||||
'errorCode': errorCode,
|
||||
'redirectUrl': path
|
||||
}
|
||||
}));
|
||||
return obs;
|
||||
}
|
||||
} else{
|
||||
} else {
|
||||
errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": path } });
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check(state.url);
|
||||
return this.check(route, state.url);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check('/' + route.path);
|
||||
return this.check(null, '/' + route.path);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, ActivatedRoute} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from '../../login/utils/helper.class';
|
||||
import {LoginErrorCodes} from '../../login/utils/guardHelper.class';
|
||||
import {CommunityService} from '../community/community.service';
|
||||
|
@ -8,36 +8,42 @@ import { EnvironmentSpecificService} from '../../utils/properties/environment-sp
|
|||
import {ConnectHelper} from '../connectHelper';
|
||||
|
||||
@Injectable()
|
||||
export class ConnectSubscriberGuard implements CanActivate {
|
||||
export class ConnectSubscriberGuard implements CanActivate, CanLoad{
|
||||
constructor(private router: Router,
|
||||
private communityService: CommunityService,
|
||||
private propertiesService:EnvironmentSpecificService,
|
||||
private route: ActivatedRoute) {}
|
||||
private propertiesService: EnvironmentSpecificService) {}
|
||||
|
||||
check(route: ActivatedRouteSnapshot, path: string): Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||
let community = route.queryParams['communityId'];
|
||||
if (!community && (typeof document !== 'undefined')) {
|
||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
}
|
||||
if (!Session.isLoggedIn()) {
|
||||
errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
|
||||
return false;
|
||||
} else {
|
||||
const obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
||||
return this.communityService.isSubscribedToCommunity(community, Session.getUserEmail(), properties['adminToolsAPIURL']);
|
||||
});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
'errorCode': errorCode,
|
||||
'redirectUrl': path
|
||||
}
|
||||
}));
|
||||
return obs;
|
||||
}
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
let errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||
let community = this.route.queryParams["communityId"];
|
||||
if(!community && (typeof document !== 'undefined')){
|
||||
community = ConnectHelper.getCommunityFromDomain(document.location.hostname);
|
||||
}
|
||||
if(!Session.isLoggedIn()){
|
||||
errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, "redirectUrl": state.url } });
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
let obs = this.propertiesService.subscribeEnvironment().mergeMap(properties => {
|
||||
return this.communityService.isSubscribedToCommunity(community, Session.getUserEmail(), properties["adminToolsAPIURL"])
|
||||
});
|
||||
obs.filter(enabled => !enabled)
|
||||
.subscribe(() => this.router.navigate(['/user-info'], {
|
||||
queryParams: {
|
||||
"errorCode": errorCode,
|
||||
"redirectUrl": state.url
|
||||
}
|
||||
}));
|
||||
return obs;
|
||||
}
|
||||
return this.check(route, state.url);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check(null, '/' + route.path);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
ActivatedRoute,
|
||||
Router,
|
||||
CanActivate,
|
||||
ActivatedRouteSnapshot,
|
||||
RouterStateSnapshot,
|
||||
CanLoad, Route
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/filter';
|
||||
|
||||
@Injectable()
|
||||
export class IsCommunity implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router,
|
||||
private route: ActivatedRoute) {}
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
check(): Observable<boolean> | boolean {
|
||||
let community = this.route.queryParams["communityId"];
|
||||
if(community && community!="undefined"){
|
||||
check(route: ActivatedRouteSnapshot): Observable<boolean> | boolean {
|
||||
const community = route.queryParams['communityId'];
|
||||
console.log(community);
|
||||
if (community && community !== 'undefined') {
|
||||
return true;
|
||||
}else{
|
||||
} else {
|
||||
this.router.navigate(['errorcommunity']);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean {
|
||||
return this.check();
|
||||
return this.check(route);
|
||||
}
|
||||
|
||||
canLoad(route: Route): Observable<boolean> | Promise<boolean> | boolean {
|
||||
return this.check();
|
||||
return this.check(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,27 +1,28 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
||||
@Injectable()
|
||||
export class AdminLoginGuard implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router) {}
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
check(path: string) : boolean{
|
||||
check(path: string): boolean {
|
||||
let loggedIn = false;
|
||||
let isAdmin = false;
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
if(Session.isLoggedIn()){
|
||||
if (Session.isLoggedIn()) {
|
||||
loggedIn = true;
|
||||
isAdmin = Session.isPortalAdministrator();
|
||||
if(!isAdmin){
|
||||
if (!isAdmin) {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
}
|
||||
if(!loggedIn || !isAdmin) {
|
||||
this.router.navigate(['/user-info'], {queryParams: {"errorCode": errorCode, "redirectUrl": path}});
|
||||
if (!loggedIn || !isAdmin) {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
|
||||
}
|
||||
return loggedIn && isAdmin;
|
||||
}
|
||||
|
|
|
@ -1,31 +1,30 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanLoad, Route} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
||||
@Injectable()
|
||||
export class ClaimsCuratorGuard implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router) {}
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
check(path: string) : boolean{
|
||||
check(path: string): boolean {
|
||||
let loggedIn = false;
|
||||
let isAuthorized = false;
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
|
||||
if(Session.isLoggedIn()){
|
||||
if (Session.isLoggedIn()) {
|
||||
loggedIn = true;
|
||||
if(Session.isClaimsCurator() || Session.isPortalAdministrator()){
|
||||
if (Session.isClaimsCurator() || Session.isPortalAdministrator()) {
|
||||
isAuthorized = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||
}
|
||||
}
|
||||
if(!loggedIn || !isAuthorized){
|
||||
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
||||
this.router.navigate(['/user-info'], {queryParams: {"errorCode": errorCode, "redirectUrl": path}});
|
||||
if (!loggedIn || !isAuthorized) {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': errorCode, 'redirectUrl': path}});
|
||||
}
|
||||
return loggedIn && isAuthorized;
|
||||
}
|
||||
|
|
|
@ -7,19 +7,19 @@ import {
|
|||
Route,
|
||||
CanLoad
|
||||
} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
||||
@Injectable()
|
||||
export class FreeGuard implements CanActivate, CanLoad{
|
||||
export class FreeGuard implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router) {}
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
check(path: string) :boolean {
|
||||
let valid = true;
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
if(!valid){
|
||||
this.router.navigate(['/user-info'], {queryParams: {"errorCode": errorCode, "redirectUrl": path}});
|
||||
check(path: string): boolean {
|
||||
const valid = true;
|
||||
if (!valid) {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_VALID, 'redirectUrl': path}});
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
|
|
@ -1,24 +1,22 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Route, CanLoad} from '@angular/router';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Observable} from 'rxjs/Observable';
|
||||
import {Session} from './utils/helper.class';
|
||||
import {LoginErrorCodes} from './utils/guardHelper.class';
|
||||
|
||||
@Injectable()
|
||||
export class LoginGuard implements CanActivate, CanLoad {
|
||||
|
||||
constructor(private router: Router) {}
|
||||
constructor(private router: Router) {
|
||||
}
|
||||
|
||||
check(path: string): boolean{
|
||||
check(path: string): boolean {
|
||||
let loggedIn = false;
|
||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||
|
||||
if(Session.isLoggedIn()) {
|
||||
if (Session.isLoggedIn()) {
|
||||
loggedIn = true;
|
||||
}
|
||||
if(!loggedIn){
|
||||
// this.guardHelper.redirect("/user-info",errorCode,state.url);
|
||||
this.router.navigate(['/user-info'], { queryParams: { "errorCode": errorCode, path} });
|
||||
if (!loggedIn) {
|
||||
this.router.navigate(['/user-info'], {queryParams: {'errorCode': LoginErrorCodes.NOT_LOGIN, path}});
|
||||
}
|
||||
return loggedIn;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue