diff --git a/src/app/core/auth/auth.service.ts b/src/app/core/auth/auth.service.ts
index 150e44296e..3671507cb0 100644
--- a/src/app/core/auth/auth.service.ts
+++ b/src/app/core/auth/auth.service.ts
@@ -436,6 +436,10 @@ export class AuthService {
this.store.dispatch(new SetRedirectUrlAction(isNotUndefined(url) ? url : ''));
}
+ /**
+ * Set the redirect url if the current one has not been set yet
+ * @param newRedirectUrl
+ */
setRedirectUrlIfNotSet(newRedirectUrl: string) {
this.getRedirectUrl().pipe(
take(1))
diff --git a/src/app/shared/log-in/container/log-in-container.component.ts b/src/app/shared/log-in/container/log-in-container.component.ts
index 660e616b9d..46459362be 100644
--- a/src/app/shared/log-in/container/log-in-container.component.ts
+++ b/src/app/shared/log-in/container/log-in-container.component.ts
@@ -15,6 +15,12 @@ export class LogInContainerComponent implements OnInit {
@Input() authMethod: AuthMethod;
+ /**
+ * A boolean representing if LogInContainerComponent is in a standalone page
+ * @type {boolean}
+ */
+ @Input() isStandalonePage: boolean;
+
/**
* Injector to inject a section component with the @Input parameters
* @type {Injector}
@@ -36,6 +42,7 @@ export class LogInContainerComponent implements OnInit {
this.objectInjector = Injector.create({
providers: [
{ provide: 'authMethodProvider', useFactory: () => (this.authMethod), deps: [] },
+ { provide: 'isStandalonePage', useFactory: () => (this.isStandalonePage), deps: [] },
],
parent: this.injector
});
diff --git a/src/app/shared/log-in/log-in.component.html b/src/app/shared/log-in/log-in.component.html
index 5285bc65e4..af76c74a9e 100644
--- a/src/app/shared/log-in/log-in.component.html
+++ b/src/app/shared/log-in/log-in.component.html
@@ -4,7 +4,7 @@
{{"login.form.or-divider" | translate}}
-
+
diff --git a/src/app/shared/log-in/log-in.component.ts b/src/app/shared/log-in/log-in.component.ts
index 301eb1736b..9e289af603 100644
--- a/src/app/shared/log-in/log-in.component.ts
+++ b/src/app/shared/log-in/log-in.component.ts
@@ -2,9 +2,16 @@ import { Component, Input, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { select, Store } from '@ngrx/store';
import { AuthMethod } from '../../core/auth/models/auth.method';
-import { getAuthenticationMethods, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors';
+import {
+ getAuthenticationError,
+ getAuthenticationMethods,
+ isAuthenticated,
+ isAuthenticationLoading
+} from '../../core/auth/selectors';
import { CoreState } from '../../core/core.reducers';
import { getForgotPasswordPath, getRegisterPath } from '../../app-routing.module';
+import { hasValue } from '../empty.util';
+import { AuthService } from '../../core/auth/auth.service';
/**
* /users/sign-in
@@ -41,7 +48,8 @@ export class LogInComponent implements OnInit {
*/
public loading: Observable;
- constructor(private store: Store) {
+ constructor(private store: Store,
+ private authService: AuthService) {
}
ngOnInit(): void {
@@ -55,6 +63,13 @@ export class LogInComponent implements OnInit {
// set isAuthenticated
this.isAuthenticated = this.store.pipe(select(isAuthenticated));
+
+ // Clear the redirect URL if an authentication error occurs and this is not a standalone page
+ this.store.pipe(select(getAuthenticationError)).subscribe((error) => {
+ if (hasValue(error) && !this.isStandalonePage) {
+ this.authService.clearRedirectUrl();
+ }
+ });
}
getRegisterPath() {
diff --git a/src/app/shared/log-in/methods/password/log-in-password.component.spec.ts b/src/app/shared/log-in/methods/password/log-in-password.component.spec.ts
index cac1052238..5291c16150 100644
--- a/src/app/shared/log-in/methods/password/log-in-password.component.spec.ts
+++ b/src/app/shared/log-in/methods/password/log-in-password.component.spec.ts
@@ -55,6 +55,7 @@ describe('LogInPasswordComponent', () => {
providers: [
{ provide: AuthService, useClass: AuthServiceStub },
{ provide: 'authMethodProvider', useValue: new AuthMethod(AuthMethodType.Password) },
+ { provide: 'isStandalonePage', useValue: true },
{ provide: HardRedirectService, useValue: hardRedirectService },
],
schemas: [
diff --git a/src/app/shared/log-in/methods/password/log-in-password.component.ts b/src/app/shared/log-in/methods/password/log-in-password.component.ts
index 1d144a280e..c72881d3bf 100644
--- a/src/app/shared/log-in/methods/password/log-in-password.component.ts
+++ b/src/app/shared/log-in/methods/password/log-in-password.component.ts
@@ -68,6 +68,7 @@ export class LogInPasswordComponent implements OnInit {
/**
* @constructor
* @param {AuthMethod} injectedAuthMethodModel
+ * @param {boolean} isStandalonePage
* @param {AuthService} authService
* @param {HardRedirectService} hardRedirectService
* @param {FormBuilder} formBuilder
@@ -75,6 +76,7 @@ export class LogInPasswordComponent implements OnInit {
*/
constructor(
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
+ @Inject('isStandalonePage') public isStandalonePage: boolean,
private authService: AuthService,
private hardRedirectService: HardRedirectService,
private formBuilder: FormBuilder,
@@ -140,7 +142,11 @@ export class LogInPasswordComponent implements OnInit {
email.trim();
password.trim();
- this.authService.setRedirectUrlIfNotSet(this.hardRedirectService.getCurrentRoute());
+ if (!this.isStandalonePage) {
+ this.authService.setRedirectUrl(this.hardRedirectService.getCurrentRoute());
+ } else {
+ this.authService.setRedirectUrlIfNotSet('/');
+ }
// dispatch AuthenticationAction
this.store.dispatch(new AuthenticateAction(email, password));
diff --git a/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.spec.ts b/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.spec.ts
index b029ec63f2..1c5698031d 100644
--- a/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.spec.ts
+++ b/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.spec.ts
@@ -62,6 +62,7 @@ describe('LogInShibbolethComponent', () => {
providers: [
{ provide: AuthService, useClass: AuthServiceStub },
{ provide: 'authMethodProvider', useValue: new AuthMethod(AuthMethodType.Shibboleth, location) },
+ { provide: 'isStandalonePage', useValue: true },
{ provide: NativeWindowService, useFactory: NativeWindowMockFactory },
{ provide: Router, useValue: new RouterStub() },
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
diff --git a/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.ts b/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.ts
index bb5791bd60..5cc50e46c6 100644
--- a/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.ts
+++ b/src/app/shared/log-in/methods/shibboleth/log-in-shibboleth.component.ts
@@ -51,6 +51,7 @@ export class LogInShibbolethComponent implements OnInit {
/**
* @constructor
* @param {AuthMethod} injectedAuthMethodModel
+ * @param {boolean} isStandalonePage
* @param {NativeWindowRef} _window
* @param {RouteService} route
* @param {AuthService} authService
@@ -59,6 +60,7 @@ export class LogInShibbolethComponent implements OnInit {
*/
constructor(
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
+ @Inject('isStandalonePage') public isStandalonePage: boolean,
@Inject(NativeWindowService) protected _window: NativeWindowRef,
private route: RouteService,
private authService: AuthService,
@@ -81,7 +83,11 @@ export class LogInShibbolethComponent implements OnInit {
}
redirectToShibboleth() {
- this.authService.setRedirectUrlIfNotSet(this.hardRedirectService.getCurrentRoute())
+ if (!this.isStandalonePage) {
+ this.authService.setRedirectUrl(this.hardRedirectService.getCurrentRoute());
+ } else {
+ this.authService.setRedirectUrlIfNotSet('/');
+ }
let newLocationUrl = this.location;
const currentUrl = this._window.nativeWindow.location.href;
const myRegexp = /\?redirectUrl=(.*)/g;
diff --git a/src/app/shared/testing/auth-service.stub.ts b/src/app/shared/testing/auth-service.stub.ts
index 2f1e9e3bac..f522ce8306 100644
--- a/src/app/shared/testing/auth-service.stub.ts
+++ b/src/app/shared/testing/auth-service.stub.ts
@@ -162,4 +162,8 @@ export class AuthServiceStub {
redirectAfterLoginSuccess() {
return;
}
+
+ clearRedirectUrl() {
+ return;
+ }
}