[Library | Trunk]: Remove parameter from userInfo.
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59040 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
09fa6aa94b
commit
885999c8ad
|
@ -28,7 +28,7 @@ export class ConnectAdminLoginGuard implements CanActivate, CanLoad {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
let email = null;
|
let email = null;
|
||||||
const authorized = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
|
const authorized = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
|
||||||
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
return this.userManagementService.getUserInfo().pipe(map(user => {
|
||||||
if (user) {
|
if (user) {
|
||||||
email = user.email;
|
email = user.email;
|
||||||
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) {
|
if (Session.isPortalAdministrator(user) || Session.isCommunityCurator(user)) {
|
||||||
|
|
|
@ -23,7 +23,7 @@ export class ConnectSubscriberGuard implements CanActivate {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
let email = null;
|
let email = null;
|
||||||
const subscribed = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
|
const subscribed = this.propertiesService.subscribeEnvironment().pipe(map(res => res), mergeMap(properties => {
|
||||||
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
return this.userManagementService.getUserInfo().pipe(map(user => {
|
||||||
if (user) {
|
if (user) {
|
||||||
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
errorCode = LoginErrorCodes.NOT_SUBSCRIBER;
|
||||||
email = user.email;
|
email = user.email;
|
||||||
|
|
|
@ -19,7 +19,7 @@ export class IsCommunityOrAdmin implements CanActivate {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
const obs = this.propertiesService.subscribeEnvironment().pipe(mergeMap(properties => {
|
||||||
return this.userManagementService.getUserInfo(false).pipe(map(user => {
|
return this.userManagementService.getUserInfo().pipe(map(user => {
|
||||||
return Session.isPortalAdministrator(user);
|
return Session.isPortalAdministrator(user);
|
||||||
}));
|
}));
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -15,7 +15,7 @@ export class AdminLoginGuard implements CanActivate {
|
||||||
|
|
||||||
check(path: string): Observable<boolean> {
|
check(path: string): Observable<boolean> {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
const obs = this.userManagementService.getUserInfo().pipe(map(user => {
|
||||||
if (user) {
|
if (user) {
|
||||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ export class ClaimsCuratorGuard implements CanActivate {
|
||||||
|
|
||||||
check(path: string): Observable<boolean> | boolean {
|
check(path: string): Observable<boolean> | boolean {
|
||||||
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
let errorCode = LoginErrorCodes.NOT_LOGIN;
|
||||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
const obs = this.userManagementService.getUserInfo().pipe(map(user => {
|
||||||
if (user) {
|
if (user) {
|
||||||
errorCode = LoginErrorCodes.NOT_ADMIN;
|
errorCode = LoginErrorCodes.NOT_ADMIN;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ export class LoginGuard implements CanActivate, CanLoad {
|
||||||
|
|
||||||
check(path: string): Observable<boolean> | boolean {
|
check(path: string): Observable<boolean> | boolean {
|
||||||
if (Session.isLoggedIn()) {
|
if (Session.isLoggedIn()) {
|
||||||
const obs = this.userManagementService.getUserInfo(false).pipe(map(user => {
|
const obs = this.userManagementService.getUserInfo().pipe(map(user => {
|
||||||
return user !== null;
|
return user !== null;
|
||||||
}));
|
}));
|
||||||
obs.pipe(filter(isLoggedIn => !isLoggedIn)).subscribe(() => {
|
obs.pipe(filter(isLoggedIn => !isLoggedIn)).subscribe(() => {
|
||||||
|
|
|
@ -13,11 +13,12 @@ import {properties} from "../../../environments/environment";
|
||||||
export class UserManagementService {
|
export class UserManagementService {
|
||||||
|
|
||||||
private getUserInfoSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
|
private getUserInfoSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
|
||||||
|
private initialized = false
|
||||||
private readonly promise: Promise<User>;
|
private readonly promise: Promise<User>;
|
||||||
|
|
||||||
constructor(private http: HttpClient,
|
constructor(private http: HttpClient,
|
||||||
private router: Router) {
|
private router: Router) {
|
||||||
this.promise = new Promise<any>((resolve => {
|
this.promise = new Promise<any>(resolve => {
|
||||||
const token = COOKIE.getCookie('AccessToken');
|
const token = COOKIE.getCookie('AccessToken');
|
||||||
if (!token) {
|
if (!token) {
|
||||||
this.getUserInfoSubject.next(null);
|
this.getUserInfoSubject.next(null);
|
||||||
|
@ -32,7 +33,7 @@ export class UserManagementService {
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}));
|
});
|
||||||
this.router.events.subscribe(event => {
|
this.router.events.subscribe(event => {
|
||||||
if (event instanceof NavigationEnd) {
|
if (event instanceof NavigationEnd) {
|
||||||
const token = COOKIE.getCookie('AccessToken');
|
const token = COOKIE.getCookie('AccessToken');
|
||||||
|
@ -43,8 +44,8 @@ export class UserManagementService {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUserInfo(subject: boolean = true): Observable<User> {
|
public getUserInfo(): Observable<User> {
|
||||||
if(subject) {
|
if(this.initialized) {
|
||||||
return this.getUserInfoSubject.asObservable();
|
return this.getUserInfoSubject.asObservable();
|
||||||
} else {
|
} else {
|
||||||
return from(this.getUserInfoAsync());
|
return from(this.getUserInfoAsync());
|
||||||
|
@ -53,6 +54,7 @@ export class UserManagementService {
|
||||||
|
|
||||||
private async getUserInfoAsync(): Promise<User> {
|
private async getUserInfoAsync(): Promise<User> {
|
||||||
await this.promise;
|
await this.promise;
|
||||||
|
this.initialized = true;
|
||||||
return this.getUserInfoSubject.getValue();
|
return this.getUserInfoSubject.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue