diff --git a/login/user.component.ts b/login/user.component.ts
index f18aa429..e1b353a0 100644
--- a/login/user.component.ts
+++ b/login/user.component.ts
@@ -18,6 +18,7 @@ import {StringUtils} from "../utils/string-utils.class";
export class UserComponent {
public user: User;
+ public loading: boolean = true;
public loggedIn: boolean = false;
public server: boolean = true;
public errorMessage: string = "";
@@ -27,7 +28,7 @@ export class UserComponent {
public redirectUrl: string = "";
public routerHelper: RouterHelper = new RouterHelper();
public loginUrl;
- properties: EnvProperties;
+ public properties: EnvProperties = properties;
@Input() mainComponent = true;
constructor(private router: Router,
@@ -35,35 +36,32 @@ export class UserComponent {
private _meta: Meta,
private _title: Title,
private userManagementsService: UserManagementService) {
-
- var title = "OpenAIRE | Login";
- this._title.setTitle(title);
+ this._title.setTitle("OpenAIRE | Login");
}
ngOnInit() {
-
- this.properties = properties;
this.loginUrl = this.properties.loginUrl;
-
if (typeof document !== 'undefined') {
this.server = false;
- this.subscriptions.push(this.userManagementsService.getUserInfo().subscribe(user => {
+ this.subscriptions.push(this.userManagementsService.getUserInfo(false).subscribe(user => {
this.user = user;
this.loggedIn = !!this.user;
this.errorMessage = "";
+ this.loading = true;
this.subscriptions.push(this.route.queryParams.subscribe(params => {
this.errorCode = params["errorCode"];
this.redirectUrl = params["redirectUrl"];
this.errorMessage = "";
if (this.loggedIn && this.errorCode == '1') {
this.redirect();
+ } else {
+ this.loading = false;
}
}));
}));
}
}
-
ngOnDestroy() {
this.subscriptions.forEach(subscription => {
if (subscription instanceof Subscriber) {
@@ -75,49 +73,13 @@ export class UserComponent {
redirect() {
if (this.redirectUrl && this.redirectUrl != "") {
this.redirectUrl = decodeURIComponent(this.redirectUrl);
- var route = this.redirectUrl;
- var queryParams = "";
- var paramsArray = [];
- var valuesArray = [];
- if (this.redirectUrl.indexOf('?') != -1) {
- route = this.redirectUrl.split('?')[0];
- queryParams = this.redirectUrl.split('?')[1];
- }
- if (queryParams != "") {
- var queryParamsArray = queryParams.split('&');
- for (var i = 0; i < queryParamsArray.length; i++) {
- paramsArray.push(queryParamsArray[i].split("=")[0]);
- valuesArray.push(queryParamsArray[i].split("=")[1]);
- }
- console.debug('here');
- this.router.navigate([route], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)});
- } else {
- this.router.navigate([route]);
- }
+ this.userManagementsService.setRedirectUrl(this.redirectUrl);
+ this.router.navigate(['/reload']);
}
- // else{
- // this.router.navigate(['/']);
- // }
}
logIn() {
- if (this.redirectUrl && this.redirectUrl != "") {
- this.redirectUrl = decodeURIComponent(this.redirectUrl);
- var route = this.redirectUrl;
- var queryParams = "";
- if (this.redirectUrl.indexOf('?') != -1) {
- var splits = this.redirectUrl.split('?');
- if (splits.length > 0) {
- route = splits[0];
- }
- if (splits.length > 1) {
- queryParams = splits[1];
- }
- }
- Session.setReloadUrl(location.protocol + "//" + location.host,properties.baseLink + route, queryParams);
- }
- console.log(Session.getReloadUrl());
- window.location.href = this.properties.loginUrl;
+ this.userManagementsService.login();
}
getTheRolesFormatted(roles: string[]) {
diff --git a/login/user.module.ts b/login/user.module.ts
index 851e5cc0..f592e6b8 100644
--- a/login/user.module.ts
+++ b/login/user.module.ts
@@ -8,10 +8,11 @@ import {UserRoutingModule} from './user-routing.module';
import {UserComponent} from './user.component';
import {PreviousRouteRecorder} from '../utils/piwik/previousRouteRecorder.guard';
+import {LoadingModule} from "../utils/loading/loading.module";
@NgModule({
imports: [
- CommonModule, FormsModule, UserRoutingModule, RouterModule
+ CommonModule, FormsModule, UserRoutingModule, RouterModule, LoadingModule
],
providers: [
PreviousRouteRecorder
diff --git a/login/userMini.component.ts b/login/userMini.component.ts
index 05317ab5..9ece0ec8 100644
--- a/login/userMini.component.ts
+++ b/login/userMini.component.ts
@@ -1,11 +1,10 @@
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
-import {ActivatedRoute, NavigationStart, Router} from '@angular/router';
-import {User, Session} from './utils/helper.class';
+import {ActivatedRoute, Router} from '@angular/router';
+import {Session, User} from './utils/helper.class';
import {RouterHelper} from '../utils/routerHelper.class';
-import {StringUtils} from '../utils/string-utils.class';
-import {properties} from "../../../environments/environment";
import {Subscriber} from "rxjs";
import {MenuItem} from "../sharedComponents/menu";
+import {UserManagementService} from "../services/user-management.service";
// declare var logoutClicked;
@Component({
@@ -161,7 +160,6 @@ import {MenuItem} from "../sharedComponents/menu";
`
})
-
export class UserMiniComponent implements OnInit, OnChanges {
@Input() user: User;
public loggedIn: boolean = false;
@@ -176,31 +174,22 @@ export class UserMiniComponent implements OnInit, OnChanges {
@Input() logOutUrl;
@Input() cookieDomain;
@Input() fixRedirectUrl: string;
- @Input() redirectUrl: string;
@Input() dark: boolean = false;
- search: string = '';
subscriptions = [];
- constructor(private router: Router, private route: ActivatedRoute) {
- this.subscriptions.push(this.router.events.forEach(event => {
- if (event instanceof NavigationStart) {
- this.initialize(event.url);
- }
- }));
+ constructor(private router: Router, private route: ActivatedRoute, private userManagementService: UserManagementService) {
}
ngOnInit() {
if (typeof document !== 'undefined') {
this.server = false;
}
- this.subscriptions.push(this.route.queryParams.subscribe(params => {
- this.initialize();
- }));
+ this.initUser();
}
ngOnChanges(changes: SimpleChanges): void {
if (changes.user) {
- this.initialize();
+ this.initUser();
}
}
@@ -212,42 +201,21 @@ export class UserMiniComponent implements OnInit, OnChanges {
});
}
- initialize(url: string = null) {
- 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 if (typeof location !== 'undefined') {
- this.redirectUrl = location.pathname;
- this.search = location.search;
- }
+ initUser() {
if (this.user) {
this.loggedIn = true;
this.parseName();
this.isAuthorized = Session.isClaimsCurator(this.user) || Session.isPortalAdministrator(this.user);
-
} else {
this.loggedIn = false;
this.isAuthorized = false;
this.user = null;
}
-
}
logOut() {
if (this.user) {
- 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);
- }
+ this.userManagementService.logout();
}
this.loggedIn = false;
this.isAuthorized = false;
@@ -255,9 +223,7 @@ export class UserMiniComponent implements OnInit, OnChanges {
}
logIn() {
- Session.setReloadUrl(location.protocol + "//" + location.host,
- this.fixRedirectUrl ? (properties.baseLink + this.fixRedirectUrl) : this.redirectUrl, this.search);
- window.location.href = this.logInUrl;
+ this.userManagementService.login();
}
isTheActiveSubMenu(menuItem: MenuItem): boolean {
diff --git a/login/utils/helper.class.ts b/login/utils/helper.class.ts
index 10dc4b46..28ba612e 100644
--- a/login/utils/helper.class.ts
+++ b/login/utils/helper.class.ts
@@ -24,11 +24,12 @@ export class Session {
return (cookie != null && cookie != "");
}
- public static setReloadUrl(host: string, path: string, params: string) {
+ public static setReloadUrl(host: string, path: string, params: string, fragment: string) {
var URL = {};
URL["host"] = host;
URL["path"] = path;
URL["params"] = params;
+ URL["fragment"] = fragment;
COOKIE.setCookie("reloadURL", JSON.stringify(URL), -1);
}
diff --git a/reload/reload.component.ts b/reload/reload.component.ts
index 92eade58..d842d1f2 100644
--- a/reload/reload.component.ts
+++ b/reload/reload.component.ts
@@ -17,42 +17,36 @@ export class ReloadComponent {
public ngOnInit() {
HelperFunctions.scroll();
let URL = Session.getReloadUrl();
- if (URL && URL["path"] && URL["path"] != null && URL["path"] != "") {
+ if (URL && URL["path"] && URL["path"] != "") {
let url: string = URL["path"];
let host = URL["host"];
let paramsObject = ((URL["params"] && URL["params"] != null) ? Session.getParamsObj(URL["params"]) : null);
- let hash = url.indexOf("#");
if (host == (location.protocol + "//" + location.host)) {
- let fragment = (hash !== -1)?url.slice(hash + 1):null;
- if(fragment) {
- url = url.slice(0, hash);
- }
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;
if (paramsObject) {
- Session.setReloadUrl("", "", "")
- if(fragment) {
- this._router.navigate([url], {queryParams: paramsObject, fragment: fragment});
+ Session.setReloadUrl("", "", "", "");
+ if(URL['fragment'] && URL['fragment'] !== '') {
+ this._router.navigate([url], {queryParams: paramsObject, fragment: URL['fragment']});
} else {
this._router.navigate([url], {queryParams: paramsObject});
}
} else {
- Session.setReloadUrl("", "", "")
- if(fragment) {
- this._router.navigate([url], {fragment: fragment});
+ Session.setReloadUrl("", "", "", "");
+ if(URL['fragment'] && URL['fragment'] !== '') {
+ this._router.navigate([url], {fragment: URL['fragment']});
} else {
this._router.navigate([url]);
}
}
} else {
- Session.setReloadUrl("", "", "")
+ Session.setReloadUrl("", "", "", "");
window.location.href = host + url + ((URL["params"] && URL["params"] != null) ? ((URL["params"].indexOf("?") == -1 ? "?" : "") + URL["params"]) : "");
}
} else {
- Session.setReloadUrl("", "", "")
+ Session.setReloadUrl("", "", "", "");
this._router.navigate(['/']);
-
}
}
diff --git a/services/user-management.service.ts b/services/user-management.service.ts
index cd310486..4a867a71 100644
--- a/services/user-management.service.ts
+++ b/services/user-management.service.ts
@@ -1,10 +1,12 @@
import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {BehaviorSubject, from, Observable, of} from "rxjs";
-import {COOKIE, User} from "../login/utils/helper.class";
+import {COOKIE, Session, User} from "../login/utils/helper.class";
import {map} from "rxjs/operators";
import {NavigationEnd, Router} from "@angular/router";
import {properties} from "../../../environments/environment";
+import {el} from "@angular/platform-browser/testing/src/browser_util";
+import {StringUtils} from "../utils/string-utils.class";
@Injectable({
providedIn: 'root'
@@ -15,6 +17,7 @@ export class UserManagementService{
private readonly promise: Promise
;
sub;
routeSub;
+
constructor(private http: HttpClient,
private router: Router) {
this.promise = new Promise((resolve => {
@@ -110,4 +113,42 @@ export class UserManagementService{
user.expirationDate = info.exp_date;
return user;
}
+
+ public setRedirectUrl(url: string = null) {
+ if(url) {
+ let parts = url.split('?');
+ let path = properties.baseLink + parts[0];
+ let params = null;
+ if (parts.length == 2) {
+ params = parts[1];
+ }
+ let hash = path.indexOf("#");
+ let fragment = (hash !== -1)?path.slice(hash + 1):null;
+ if(fragment) {
+ path = path.slice(0, hash);
+ } else {
+ fragment = "";
+ }
+ if(!path.includes('/reload')) {
+ Session.setReloadUrl(location.protocol + "//" + location.host, path, params, fragment);
+ }
+ } else {
+ Session.setReloadUrl(location.protocol + "//" + location.host, location.pathname, location.search, location.hash);
+ }
+ }
+
+ public login() {
+ this.setRedirectUrl();
+ window.location.href = properties.loginUrl;
+ }
+
+ public logout() {
+ this.setRedirectUrl();
+ Session.removeUser();
+ if (properties.logoutUrl.includes('openid_logout')) {
+ window.location.href = properties.logoutUrl;
+ } else {
+ window.location.href = properties.logoutUrl + StringUtils.URIEncode(location.href);
+ }
+ }
}