|
|
|
@ -16,22 +16,11 @@ export class UserManagementService {
|
|
|
|
|
private readonly getUserInfoSubject: AdvancedAsyncSubject<User> = new AdvancedAsyncSubject<User>();
|
|
|
|
|
public fixRedirectURL: string = null;
|
|
|
|
|
private redirectUrl: string = null;
|
|
|
|
|
private readonly promise: Promise<User>;
|
|
|
|
|
private subscription;
|
|
|
|
|
private readonly routerSubscription;
|
|
|
|
|
|
|
|
|
|
constructor(private http: HttpClient, private router: Router) {
|
|
|
|
|
this.promise = new Promise<any>((resolve => {
|
|
|
|
|
this.updateUserInfo(resolve);
|
|
|
|
|
}));
|
|
|
|
|
this.routerSubscription = this.router.events.subscribe(event => {
|
|
|
|
|
if (event instanceof NavigationEnd) {
|
|
|
|
|
const token = COOKIE.getCookie('AccessToken');
|
|
|
|
|
if (!token && this.getUserInfoSubject.getValue() !== null) {
|
|
|
|
|
this.getUserInfoSubject.next(null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
constructor(private http: HttpClient) {
|
|
|
|
|
this.updateUserInfo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
clearSubscriptions() {
|
|
|
|
@ -43,12 +32,12 @@ export class UserManagementService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getUserInfo(subject: boolean = true): Observable<User> {
|
|
|
|
|
if (subject) {
|
|
|
|
|
return this.getUserInfoSubject.asObservable();
|
|
|
|
|
} else {
|
|
|
|
|
return from(this.getUserInfoAsync());
|
|
|
|
|
}
|
|
|
|
|
public get user(): User {
|
|
|
|
|
return this.getUserInfoSubject.getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getUserInfo(): Observable<User> {
|
|
|
|
|
return this.getUserInfoSubject.asObservable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public updateUserInfo(resolve: Function = null) {
|
|
|
|
@ -67,14 +56,6 @@ export class UserManagementService {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async getUserInfoAsync(): Promise<User> {
|
|
|
|
|
await this.promise;
|
|
|
|
|
if (this.subscription) {
|
|
|
|
|
this.subscription.unsubscribe();
|
|
|
|
|
}
|
|
|
|
|
return this.getUserInfoSubject.getValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private parseUserInfo(info: any) {
|
|
|
|
|
const user: User = new User();
|
|
|
|
|
user.id = (info.sub && info.sub.indexOf('@')) ? info.sub.substring(0, info.sub.indexOf('@')) : info.sub;
|
|
|
|
@ -144,6 +125,7 @@ export class UserManagementService {
|
|
|
|
|
public logout() {
|
|
|
|
|
this.setRedirectUrl();
|
|
|
|
|
Session.removeUser();
|
|
|
|
|
this.getUserInfoSubject.next(null);
|
|
|
|
|
window.location.href = properties.logoutUrl + "?redirect=" + this.redirectUrl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|