Add redirect url in login/logout. Add new userInfo method in getUserInfo
This commit is contained in:
parent
104c54a3e8
commit
0aa44646b1
|
@ -1,5 +1,3 @@
|
||||||
import {StringUtils} from "../../utils/string-utils.class";
|
|
||||||
|
|
||||||
export class User {
|
export class User {
|
||||||
email: string;
|
email: string;
|
||||||
firstname: string;
|
firstname: string;
|
||||||
|
@ -15,8 +13,6 @@ export class User {
|
||||||
export class Session {
|
export class Session {
|
||||||
public static removeUser() {
|
public static removeUser() {
|
||||||
COOKIE.deleteCookie(COOKIE.cookieName_id);
|
COOKIE.deleteCookie(COOKIE.cookieName_id);
|
||||||
//COOKIE.deleteCookie("openAIRESession");
|
|
||||||
COOKIE.deleteCookie("openAIREUser");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isLoggedIn(): boolean {
|
public static isLoggedIn(): boolean {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {map} from "rxjs/operators";
|
||||||
import {NavigationEnd, Router} from "@angular/router";
|
import {NavigationEnd, Router} from "@angular/router";
|
||||||
import {properties} from "../../../environments/environment";
|
import {properties} from "../../../environments/environment";
|
||||||
import {StringUtils} from "../utils/string-utils.class";
|
import {StringUtils} from "../utils/string-utils.class";
|
||||||
|
import {CustomOptions} from "./servicesUtils/customOptions.class";
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
@ -14,6 +15,7 @@ export class UserManagementService{
|
||||||
|
|
||||||
private getUserInfoSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
|
private getUserInfoSubject: BehaviorSubject<User> = new BehaviorSubject<User>(null);
|
||||||
public fixRedirectURL: string = null;
|
public fixRedirectURL: string = null;
|
||||||
|
private redirectUrl: string = null;
|
||||||
private readonly promise: Promise<User>;
|
private readonly promise: Promise<User>;
|
||||||
sub;
|
sub;
|
||||||
routeSub;
|
routeSub;
|
||||||
|
@ -51,14 +53,16 @@ export class UserManagementService{
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateUserInfo(resolve: Function = null) {
|
public updateUserInfo(resolve: Function = null) {
|
||||||
|
/** @deprecated **/
|
||||||
const token = COOKIE.getCookie('AccessToken');
|
const token = COOKIE.getCookie('AccessToken');
|
||||||
if (!token) {
|
if (!token && properties.userInfoUrl.includes("accessToken")) {
|
||||||
this.getUserInfoSubject.next(null);
|
this.getUserInfoSubject.next(null);
|
||||||
if (resolve) {
|
if (resolve) {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.sub = this.http.get<User>(properties.userInfoUrl + token).pipe(map(userInfo => {
|
let userInfoUrl = (properties.userInfoUrl.includes("accessToken")?(properties.userInfoUrl + token):properties.userInfoUrl);
|
||||||
|
this.sub = this.http.get<User>(userInfoUrl, CustomOptions.registryOptions()).pipe(map(userInfo => {
|
||||||
return this.parseUserInfo(userInfo);
|
return this.parseUserInfo(userInfo);
|
||||||
})).subscribe(user => {
|
})).subscribe(user => {
|
||||||
this.getUserInfoSubject.next(user);
|
this.getUserInfoSubject.next(user);
|
||||||
|
@ -66,7 +70,9 @@ export class UserManagementService{
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
}, error => {
|
}, error => {
|
||||||
|
if(this.getUserInfoSubject.value) {
|
||||||
this.getUserInfoSubject.next(null);
|
this.getUserInfoSubject.next(null);
|
||||||
|
}
|
||||||
if (resolve) {
|
if (resolve) {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
@ -132,7 +138,9 @@ export class UserManagementService{
|
||||||
if (!path.includes('/reload')) {
|
if (!path.includes('/reload')) {
|
||||||
Session.setReloadUrl(location.protocol + "//" + location.host, path, params, fragment);
|
Session.setReloadUrl(location.protocol + "//" + location.host, path, params, fragment);
|
||||||
}
|
}
|
||||||
|
this.redirectUrl = StringUtils.URIEncode(location.protocol + "//" + location.host + this.fixRedirectURL);
|
||||||
} else {
|
} else {
|
||||||
|
this.redirectUrl = StringUtils.URIEncode(location.href);
|
||||||
Session.setReloadUrl(location.protocol + "//" + location.host, location.pathname, location.search, location.hash);
|
Session.setReloadUrl(location.protocol + "//" + location.host, location.pathname, location.search, location.hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,14 +151,14 @@ export class UserManagementService{
|
||||||
} else {
|
} else {
|
||||||
this.setRedirectUrl();
|
this.setRedirectUrl();
|
||||||
}
|
}
|
||||||
window.location.href = properties.loginUrl;
|
window.location.href = properties.loginUrl + "?redirect=" + this.redirectUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public logout() {
|
public logout() {
|
||||||
this.setRedirectUrl();
|
this.setRedirectUrl();
|
||||||
Session.removeUser();
|
Session.removeUser();
|
||||||
if (properties.logoutUrl.includes('openid_logout')) {
|
if (properties.logoutUrl.includes('openid_logout')) {
|
||||||
window.location.href = properties.logoutUrl;
|
window.location.href = properties.logoutUrl + "?redirect=" + this.redirectUrl;
|
||||||
} else {
|
} else {
|
||||||
window.location.href = properties.logoutUrl + StringUtils.URIEncode(location.href);
|
window.location.href = properties.logoutUrl + StringUtils.URIEncode(location.href);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue