[Library]: Add check if isClient to getUserInfo

git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@57545 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
k.triantafyllou 2019-11-08 11:01:50 +00:00
parent 90f748f8e6
commit 4316c70b9a
8 changed files with 25 additions and 22 deletions

View File

@ -58,8 +58,10 @@ export class ClaimsAdminComponent {
}
ngOnInit() {
this.userManagementService.getUserInfo(this.userInfoURL).subscribe(user => {
this.user = user;
});
if (typeof document !== 'undefined') {
this.userManagementService.getUserInfo(this.userInfoURL).subscribe(user => {
this.user = user;
});
}
}
}

View File

@ -28,7 +28,7 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad {
let errorCode = LoginErrorCodes.NOT_LOGIN;
let email = null;
const authorized = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
return this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => {
if (user) {
email = user.email;
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) {

View File

@ -21,7 +21,7 @@ export class ConnectSubscriberGuard implements CanActivate {
let errorCode = LoginErrorCodes.NOT_LOGIN;
let email = null;
const subscribed = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
return this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties.userInfoUrl).pipe(map(user => {
if (user) {
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
email = user.email;

View File

@ -19,7 +19,7 @@ export class IsCommunityOrAdmin implements CanActivate {
return true;
} else {
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
return this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map(user => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map(user => {
return Session.isPortalAdministrator(user);
}));
}));

View File

@ -26,7 +26,7 @@ export class AdminLoginGuard implements CanActivate{
check(path: string): Observable<boolean> {
let errorCode = LoginErrorCodes.NOT_LOGIN;
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
return this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => {
if(user) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}

View File

@ -26,7 +26,7 @@ export class ClaimsCuratorGuard implements CanActivate {
check(path: string): Observable<boolean> |boolean {
let errorCode = LoginErrorCodes.NOT_LOGIN;
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
return this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => {
return typeof document !== 'undefined' && this.userManagementService.getUserInfo(properties['userInfoUrl']).pipe(map( user => {
if(user) {
errorCode = LoginErrorCodes.NOT_ADMIN;
}

View File

@ -47,22 +47,23 @@ export class UserComponent {
});
if (typeof document !== 'undefined') {
this.server = false;
}
this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.loggedIn = !!this.user;
this.errorMessage = "";
this.sub = this.route.queryParams.subscribe(params => {
this.errorCode = params["errorCode"];
this.redirectUrl = params["redirectUrl"];
this.userManagementsService.getUserInfo(this.properties.userInfoUrl).subscribe(user => {
this.user = user;
this.loggedIn = !!this.user;
this.errorMessage = "";
if (this.loggedIn && this.errorCode == '1') {
this.redirect();
}
this.sub = this.route.queryParams.subscribe(params => {
this.errorCode = params["errorCode"];
this.redirectUrl = params["redirectUrl"];
this.errorMessage = "";
if (this.loggedIn && this.errorCode == '1') {
this.redirect();
}
});
});
});
}
}
ngOnDestroy() {
this.sub.unsubscribe();
if (this.sublogin) {

View File

@ -2,7 +2,7 @@ import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable, of} from "rxjs";
import {COOKIE, User} from "../login/utils/helper.class";
import {catchError, map} from "rxjs/operators";
import {catchError, map, timeout} from "rxjs/operators";
@Injectable({
providedIn: 'root'
@ -16,7 +16,7 @@ export class UserManagementService {
const token = COOKIE.getCookie('AccessToken');
return this.http.get<User>(url + token).pipe(map(userInfo => {
return this.parseUserInfo(userInfo);
})).pipe(catchError(() => {
})).pipe(timeout(2000), catchError(() => {
return of(null);
}));
}