Fix reload location after login logout
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59457 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
8e50219489
commit
bd41180c74
|
@ -3,7 +3,7 @@ import {HttpParams} from '@angular/common/http';
|
||||||
export class ConnectHelper {
|
export class ConnectHelper {
|
||||||
|
|
||||||
public static getCommunityFromDomain(domain: string): string{
|
public static getCommunityFromDomain(domain: string): string{
|
||||||
// domain = "https://mes.openaire.eu"; //for testing
|
domain = "beta.ee.openaire.eu"; //for testing
|
||||||
domain = domain.indexOf("//") != -1? domain.split("//")[1]:domain; //remove https:// prefix
|
domain = domain.indexOf("//") != -1? domain.split("//")[1]:domain; //remove https:// prefix
|
||||||
if (domain.indexOf('openaire.eu') === -1) {
|
if (domain.indexOf('openaire.eu') === -1) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
import {Component, ElementRef, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
|
||||||
import {Location} from '@angular/common';
|
import {Location} from '@angular/common';
|
||||||
import {User, Session} from './utils/helper.class';
|
import {User, Session} from './utils/helper.class';
|
||||||
import {RouterHelper} from '../utils/routerHelper.class';
|
import {RouterHelper} from '../utils/routerHelper.class';
|
||||||
|
@ -176,25 +176,27 @@ export class UserMiniComponent implements OnInit, OnChanges {
|
||||||
@Input() logInUrl;
|
@Input() logInUrl;
|
||||||
@Input() logOutUrl;
|
@Input() logOutUrl;
|
||||||
@Input() cookieDomain;
|
@Input() cookieDomain;
|
||||||
|
@Input() fixRedirectUrl: string;
|
||||||
@Input() redirectUrl: string;
|
@Input() redirectUrl: string;
|
||||||
@Input() dark: boolean = false;
|
@Input() dark: boolean = false;
|
||||||
search: string = '';
|
search: string = '';
|
||||||
sub: any;
|
sub: any;
|
||||||
|
|
||||||
constructor(private router: Router, private route: ActivatedRoute, private location: Location) {
|
constructor(private router: Router, private route: ActivatedRoute) {
|
||||||
|
this.router.events.forEach(event => {
|
||||||
|
if(event instanceof NavigationStart) {
|
||||||
|
this.initialize(event.url);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
|
||||||
if (typeof document !== 'undefined') {
|
if (typeof document !== 'undefined') {
|
||||||
this.server = false;
|
this.server = false;
|
||||||
}
|
}
|
||||||
this.initialize();
|
|
||||||
this.sub = this.route.queryParams.subscribe(params => {
|
this.sub = this.route.queryParams.subscribe(params => {
|
||||||
this.initialize();
|
this.initialize();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges): void {
|
ngOnChanges(changes: SimpleChanges): void {
|
||||||
|
@ -209,11 +211,21 @@ export class UserMiniComponent implements OnInit, OnChanges {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initialize() {
|
initialize(url: string = null) {
|
||||||
if (!this.redirectUrl && typeof location !== 'undefined') {
|
if (typeof location !== 'undefined') {
|
||||||
|
if(url) {
|
||||||
|
let parts = StringUtils.split(url, ['?']);
|
||||||
|
this.redirectUrl = properties.baseLink + parts[0];
|
||||||
|
if(parts.length == 2) {
|
||||||
|
this.search = parts[1];
|
||||||
|
} else {
|
||||||
|
this.search = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
this.redirectUrl = location.pathname;
|
this.redirectUrl = location.pathname;
|
||||||
this.search = location.search;
|
this.search = location.search;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (this.user) {
|
if (this.user) {
|
||||||
this.loggedIn = true;
|
this.loggedIn = true;
|
||||||
this.parseName();
|
this.parseName();
|
||||||
|
@ -230,8 +242,13 @@ export class UserMiniComponent implements OnInit, OnChanges {
|
||||||
logOut() {
|
logOut() {
|
||||||
if (this.user) {
|
if (this.user) {
|
||||||
Session.removeUser();
|
Session.removeUser();
|
||||||
|
// New method
|
||||||
|
if(properties.logoutUrl.includes('openid_logout')) {
|
||||||
|
Session.setReloadUrl(location.protocol + "//" + location.host, this.redirectUrl, this.search);
|
||||||
|
window.location.href = this.logOutUrl;
|
||||||
|
} else {
|
||||||
window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href);
|
window.location.href = this.logOutUrl + StringUtils.URIEncode(location.href);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.loggedIn = false;
|
this.loggedIn = false;
|
||||||
this.isAuthorized = false;
|
this.isAuthorized = false;
|
||||||
|
@ -239,7 +256,8 @@ export class UserMiniComponent implements OnInit, OnChanges {
|
||||||
}
|
}
|
||||||
|
|
||||||
logIn() {
|
logIn() {
|
||||||
Session.setReloadUrl(location.protocol + "//" + location.host, this.redirectUrl, this.search);
|
Session.setReloadUrl(location.protocol + "//" + location.host,
|
||||||
|
this.fixRedirectUrl?(properties.baseLink + this.fixRedirectUrl):this.redirectUrl, this.search);
|
||||||
window.location.href = this.logInUrl;
|
window.location.href = this.logInUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ 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("openAIRESession");
|
||||||
COOKIE.deleteCookie("openAIREUser");
|
COOKIE.deleteCookie("openAIREUser");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@ import {HelperFunctions} from "../utils/HelperFunctions.class";
|
||||||
})
|
})
|
||||||
export class ReloadComponent {
|
export class ReloadComponent {
|
||||||
|
|
||||||
constructor (private route: ActivatedRoute, private _router: Router) {}
|
constructor(private route: ActivatedRoute, private _router: Router) {
|
||||||
|
}
|
||||||
|
|
||||||
public ngOnInit() {
|
public ngOnInit() {
|
||||||
HelperFunctions.scroll();
|
HelperFunctions.scroll();
|
||||||
|
|
||||||
var URL = Session.getReloadUrl();
|
var URL = Session.getReloadUrl();
|
||||||
|
console.log(URL);
|
||||||
if (URL && URL["path"] && URL["path"] != null && URL["path"] != "") {
|
if (URL && URL["path"] && URL["path"] != null && URL["path"] != "") {
|
||||||
var url = URL["path"];
|
var url = URL["path"];
|
||||||
var host = URL["host"];
|
var host = URL["host"];
|
||||||
|
@ -33,7 +33,7 @@ export class ReloadComponent {
|
||||||
if (host == (location.protocol + "//" + location.host)) {
|
if (host == (location.protocol + "//" + location.host)) {
|
||||||
let baseUrl = (document && document.getElementsByTagName('base')) ? document.getElementsByTagName('base')[0].href.split(document.location.host)[1] : "/";
|
let baseUrl = (document && document.getElementsByTagName('base')) ? document.getElementsByTagName('base')[0].href.split(document.location.host)[1] : "/";
|
||||||
url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url;
|
url = (baseUrl.length > 1 && url.indexOf(baseUrl) != -1) ? ("/" + url.split(baseUrl)[1]) : url;
|
||||||
if(paramsObject && paramsObject != null){
|
if (paramsObject) {
|
||||||
Session.setReloadUrl("", "", "")
|
Session.setReloadUrl("", "", "")
|
||||||
this._router.navigate([url], {queryParams: paramsObject});
|
this._router.navigate([url], {queryParams: paramsObject});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -116,7 +116,7 @@
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<ng-container *ngIf="userMenu">
|
<ng-container *ngIf="userMenu">
|
||||||
<user-mini [user]="user" mobileView=true
|
<user-mini [user]="user" mobileView=true
|
||||||
[redirectUrl]="(communityId && communityId !== 'connect')?null:properties.afterLoginRedirectLink"
|
[fixRedirectUrl]="(communityId && communityId !== 'connect')?null:properties.afterLoginRedirectLink"
|
||||||
[userMenuItems]=userMenuItems [logInUrl]=properties.loginUrl
|
[userMenuItems]=userMenuItems [logInUrl]=properties.loginUrl
|
||||||
[logOutUrl]=properties.logoutUrl [cookieDomain]=properties.cookieDomain></user-mini>
|
[logOutUrl]=properties.logoutUrl [cookieDomain]=properties.cookieDomain></user-mini>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
@ -299,7 +299,7 @@
|
||||||
<!-- <div *ngIf="userMenu" class="uk-navbar-right"> -->
|
<!-- <div *ngIf="userMenu" class="uk-navbar-right"> -->
|
||||||
<!-- <div *ngIf="userMenu" class="uk-navbar-right"> -->
|
<!-- <div *ngIf="userMenu" class="uk-navbar-right"> -->
|
||||||
<user-mini *ngIf="userMenu" [user]="user" [dark]="dark"
|
<user-mini *ngIf="userMenu" [user]="user" [dark]="dark"
|
||||||
[redirectUrl]="(communityId && communityId !== 'connect')?null:properties.afterLoginRedirectLink"
|
[fixRedirectUrl]="(communityId && communityId !== 'connect')?null:properties.afterLoginRedirectLink"
|
||||||
[userMenuItems]=userMenuItems [logInUrl]=properties.loginUrl [logOutUrl]=properties.logoutUrl
|
[userMenuItems]=userMenuItems [logInUrl]=properties.loginUrl [logOutUrl]=properties.logoutUrl
|
||||||
[cookieDomain]=properties.cookieDomain></user-mini>
|
[cookieDomain]=properties.cookieDomain></user-mini>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue