Use cookie to save the reload url - to share it through different domains/ dashboards
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@52177 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
7ca752f345
commit
707b80ed71
|
@ -120,38 +120,11 @@ export class UserComponent {
|
|||
queryParams = splits[1];
|
||||
}
|
||||
}
|
||||
console.log("saving url & params...");
|
||||
console.log(queryParams);
|
||||
Session.setCurrentUrl(baseUrl);
|
||||
Session.setCurrentParameters(queryParams);
|
||||
Session.setReloadUrl(location.protocol +"//"+location.host, baseUrl, queryParams);
|
||||
}
|
||||
|
||||
window.location.href = this.properties.loginUrl;
|
||||
}
|
||||
|
||||
// login() {
|
||||
// this.sublogin =this._loginService.authenticate(/*this.user*/this.username, this.password).subscribe(
|
||||
// data => {
|
||||
// this.user = data;
|
||||
// this.loggedIn = true;
|
||||
// this.username = "";
|
||||
// this.password = "";
|
||||
// this.errorCode = "";
|
||||
// this.redirect();
|
||||
//
|
||||
// },
|
||||
// err => {
|
||||
// console.log(err);
|
||||
// if(err.status == "404") {
|
||||
// this.errorMessage = "Wrong username";
|
||||
// } else if(err.status == "401") {
|
||||
// this.errorMessage = "Wrong password";
|
||||
// }
|
||||
// this.username = "";
|
||||
// this.password = "";
|
||||
// this.errorCode = "";
|
||||
//
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -139,12 +139,8 @@ export class UserMiniComponent {
|
|||
logOut(){
|
||||
if(Session.isLoggedIn()){
|
||||
Session.removeUser();
|
||||
console.log("Try to Logout!");
|
||||
// this.logoutOpenaire.logout().subscribe(params => {
|
||||
// console.log("Logout!");
|
||||
// });
|
||||
// logoutClicked();
|
||||
console.log("Redirect to "+location.href);
|
||||
console.log("Try to Logout!");
|
||||
// console.log("Redirect to "+location.href);
|
||||
window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href);
|
||||
|
||||
}
|
||||
|
@ -154,9 +150,8 @@ export class UserMiniComponent {
|
|||
}
|
||||
|
||||
logIn(){
|
||||
console.log("LOgin is clicked " + this.logInUrl);
|
||||
Session.setCurrentUrl(location.pathname);
|
||||
Session.setCurrentParameters(location.search);
|
||||
// console.log("LOgin is clicked " + this.logInUrl);
|
||||
Session.setReloadUrl(location.protocol +"//"+location.host, location.pathname, location.search);
|
||||
window.location.href = this.logInUrl
|
||||
}
|
||||
|
||||
|
|
|
@ -122,40 +122,35 @@ export class Session{
|
|||
// }
|
||||
|
||||
}
|
||||
public static getCurrentUrl():string {
|
||||
if( typeof localStorage !== 'undefined') {
|
||||
return localStorage.getItem("url");
|
||||
}
|
||||
return "";
|
||||
|
||||
}
|
||||
public static setCurrentUrl(url:string) {
|
||||
if( typeof localStorage !== 'undefined') {
|
||||
localStorage.setItem("url", url);
|
||||
}
|
||||
public static setReloadUrl(host:string,path:string, params:string) {
|
||||
var URL = {};
|
||||
URL["host"]=host;
|
||||
URL["path"]=path;
|
||||
URL["params"]=params;
|
||||
COOKIE.setCookie("reloadURL", JSON.stringify(URL), -1);
|
||||
|
||||
}
|
||||
public static getCurrentParameters():any {
|
||||
if( typeof localStorage !== 'undefined') {
|
||||
var params = localStorage.getItem("params");
|
||||
var object = null;
|
||||
public static getReloadUrl(plainText:boolean =false) {
|
||||
var URL = COOKIE.getCookie("reloadURL");
|
||||
URL = JSON.parse(URL);
|
||||
return URL;
|
||||
|
||||
}
|
||||
public static getParamsObj(params:string) {
|
||||
|
||||
var object = null;
|
||||
if(params.split("&").length > 0){
|
||||
object = {};
|
||||
}
|
||||
for(var i=0; i<params.split("&").length; i++){
|
||||
object[(params.split("&")[i]).split("=")[0]] = (params.split("&")[i]).split("=")[1];
|
||||
}
|
||||
return object;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
public static setCurrentParameters(params:string) {
|
||||
if( typeof localStorage !== 'undefined') {
|
||||
if(params.indexOf("?")==0){
|
||||
params = params.substring(1);
|
||||
}
|
||||
localStorage.setItem("params",(params && params.length > 1)? params:"");
|
||||
}
|
||||
|
||||
return object;
|
||||
|
||||
}
|
||||
|
||||
public static isClaimsCurator():boolean {
|
||||
var isAuthorized = false;
|
||||
var user:User = this.getUserFromCookie();
|
||||
|
|
|
@ -35,17 +35,26 @@ export class ReloadComponent {
|
|||
if (typeof document !== 'undefined') {
|
||||
this.element.nativeElement.scrollIntoView();
|
||||
}
|
||||
var url = Session.getCurrentUrl();
|
||||
var URL = Session.getReloadUrl();
|
||||
var url = URL["path"];
|
||||
if(url && url != null && url != ""){
|
||||
Session.setCurrentUrl("");
|
||||
var paramsObject = Session.getCurrentParameters();
|
||||
Session.setCurrentParameters("");
|
||||
if(paramsObject && paramsObject != null){
|
||||
this._router.navigate([url],{ queryParams: paramsObject});
|
||||
var host = URL["host"];
|
||||
var paramsObject = Session.getParamsObj(URL["params"]);
|
||||
if(host == location.host){
|
||||
if(paramsObject && paramsObject != null){
|
||||
Session.setReloadUrl("","","")
|
||||
this._router.navigate([url],{ queryParams: paramsObject});
|
||||
}else{
|
||||
Session.setReloadUrl("","","")
|
||||
this._router.navigate([url]);
|
||||
}
|
||||
}else{
|
||||
this._router.navigate([url]);
|
||||
Session.setReloadUrl("","","")
|
||||
window.location.href = host+url+ URL["params"];
|
||||
}
|
||||
|
||||
}else{
|
||||
Session.setReloadUrl("","","")
|
||||
this._router.navigate(['/']);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue