mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 10:34:15 +00:00
72699: Additional fixes for maintaining and clearing the redirect url on login components
This commit is contained in:
@@ -436,6 +436,10 @@ export class AuthService {
|
|||||||
this.store.dispatch(new SetRedirectUrlAction(isNotUndefined(url) ? url : ''));
|
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) {
|
setRedirectUrlIfNotSet(newRedirectUrl: string) {
|
||||||
this.getRedirectUrl().pipe(
|
this.getRedirectUrl().pipe(
|
||||||
take(1))
|
take(1))
|
||||||
|
@@ -15,6 +15,12 @@ export class LogInContainerComponent implements OnInit {
|
|||||||
|
|
||||||
@Input() authMethod: AuthMethod;
|
@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
|
* Injector to inject a section component with the @Input parameters
|
||||||
* @type {Injector}
|
* @type {Injector}
|
||||||
@@ -36,6 +42,7 @@ export class LogInContainerComponent implements OnInit {
|
|||||||
this.objectInjector = Injector.create({
|
this.objectInjector = Injector.create({
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: 'authMethodProvider', useFactory: () => (this.authMethod), deps: [] },
|
{ provide: 'authMethodProvider', useFactory: () => (this.authMethod), deps: [] },
|
||||||
|
{ provide: 'isStandalonePage', useFactory: () => (this.isStandalonePage), deps: [] },
|
||||||
],
|
],
|
||||||
parent: this.injector
|
parent: this.injector
|
||||||
});
|
});
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
<div *ngIf="i === 1" class="text-center mt-2">
|
<div *ngIf="i === 1" class="text-center mt-2">
|
||||||
<span class="align-middle">{{"login.form.or-divider" | translate}}</span>
|
<span class="align-middle">{{"login.form.or-divider" | translate}}</span>
|
||||||
</div>
|
</div>
|
||||||
<ds-log-in-container [authMethod]="authMethod"></ds-log-in-container>
|
<ds-log-in-container [authMethod]="authMethod" [isStandalonePage]="isStandalonePage"></ds-log-in-container>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<div class="dropdown-divider"></div>
|
<div class="dropdown-divider"></div>
|
||||||
|
@@ -2,9 +2,16 @@ import { Component, Input, OnInit } from '@angular/core';
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { select, Store } from '@ngrx/store';
|
import { select, Store } from '@ngrx/store';
|
||||||
import { AuthMethod } from '../../core/auth/models/auth.method';
|
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 { CoreState } from '../../core/core.reducers';
|
||||||
import { getForgotPasswordPath, getRegisterPath } from '../../app-routing.module';
|
import { getForgotPasswordPath, getRegisterPath } from '../../app-routing.module';
|
||||||
|
import { hasValue } from '../empty.util';
|
||||||
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* /users/sign-in
|
* /users/sign-in
|
||||||
@@ -41,7 +48,8 @@ export class LogInComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
public loading: Observable<boolean>;
|
public loading: Observable<boolean>;
|
||||||
|
|
||||||
constructor(private store: Store<CoreState>) {
|
constructor(private store: Store<CoreState>,
|
||||||
|
private authService: AuthService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@@ -55,6 +63,13 @@ export class LogInComponent implements OnInit {
|
|||||||
|
|
||||||
// set isAuthenticated
|
// set isAuthenticated
|
||||||
this.isAuthenticated = this.store.pipe(select(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() {
|
getRegisterPath() {
|
||||||
|
@@ -55,6 +55,7 @@ describe('LogInPasswordComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
{ provide: AuthService, useClass: AuthServiceStub },
|
{ provide: AuthService, useClass: AuthServiceStub },
|
||||||
{ provide: 'authMethodProvider', useValue: new AuthMethod(AuthMethodType.Password) },
|
{ provide: 'authMethodProvider', useValue: new AuthMethod(AuthMethodType.Password) },
|
||||||
|
{ provide: 'isStandalonePage', useValue: true },
|
||||||
{ provide: HardRedirectService, useValue: hardRedirectService },
|
{ provide: HardRedirectService, useValue: hardRedirectService },
|
||||||
],
|
],
|
||||||
schemas: [
|
schemas: [
|
||||||
|
@@ -68,6 +68,7 @@ export class LogInPasswordComponent implements OnInit {
|
|||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {AuthMethod} injectedAuthMethodModel
|
* @param {AuthMethod} injectedAuthMethodModel
|
||||||
|
* @param {boolean} isStandalonePage
|
||||||
* @param {AuthService} authService
|
* @param {AuthService} authService
|
||||||
* @param {HardRedirectService} hardRedirectService
|
* @param {HardRedirectService} hardRedirectService
|
||||||
* @param {FormBuilder} formBuilder
|
* @param {FormBuilder} formBuilder
|
||||||
@@ -75,6 +76,7 @@ export class LogInPasswordComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
|
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
|
||||||
|
@Inject('isStandalonePage') public isStandalonePage: boolean,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private hardRedirectService: HardRedirectService,
|
private hardRedirectService: HardRedirectService,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
@@ -140,7 +142,11 @@ export class LogInPasswordComponent implements OnInit {
|
|||||||
email.trim();
|
email.trim();
|
||||||
password.trim();
|
password.trim();
|
||||||
|
|
||||||
this.authService.setRedirectUrlIfNotSet(this.hardRedirectService.getCurrentRoute());
|
if (!this.isStandalonePage) {
|
||||||
|
this.authService.setRedirectUrl(this.hardRedirectService.getCurrentRoute());
|
||||||
|
} else {
|
||||||
|
this.authService.setRedirectUrlIfNotSet('/');
|
||||||
|
}
|
||||||
|
|
||||||
// dispatch AuthenticationAction
|
// dispatch AuthenticationAction
|
||||||
this.store.dispatch(new AuthenticateAction(email, password));
|
this.store.dispatch(new AuthenticateAction(email, password));
|
||||||
|
@@ -62,6 +62,7 @@ describe('LogInShibbolethComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
{ provide: AuthService, useClass: AuthServiceStub },
|
{ provide: AuthService, useClass: AuthServiceStub },
|
||||||
{ provide: 'authMethodProvider', useValue: new AuthMethod(AuthMethodType.Shibboleth, location) },
|
{ provide: 'authMethodProvider', useValue: new AuthMethod(AuthMethodType.Shibboleth, location) },
|
||||||
|
{ provide: 'isStandalonePage', useValue: true },
|
||||||
{ provide: NativeWindowService, useFactory: NativeWindowMockFactory },
|
{ provide: NativeWindowService, useFactory: NativeWindowMockFactory },
|
||||||
{ provide: Router, useValue: new RouterStub() },
|
{ provide: Router, useValue: new RouterStub() },
|
||||||
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
|
{ provide: ActivatedRoute, useValue: new ActivatedRouteStub() },
|
||||||
|
@@ -51,6 +51,7 @@ export class LogInShibbolethComponent implements OnInit {
|
|||||||
/**
|
/**
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {AuthMethod} injectedAuthMethodModel
|
* @param {AuthMethod} injectedAuthMethodModel
|
||||||
|
* @param {boolean} isStandalonePage
|
||||||
* @param {NativeWindowRef} _window
|
* @param {NativeWindowRef} _window
|
||||||
* @param {RouteService} route
|
* @param {RouteService} route
|
||||||
* @param {AuthService} authService
|
* @param {AuthService} authService
|
||||||
@@ -59,6 +60,7 @@ export class LogInShibbolethComponent implements OnInit {
|
|||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
|
@Inject('authMethodProvider') public injectedAuthMethodModel: AuthMethod,
|
||||||
|
@Inject('isStandalonePage') public isStandalonePage: boolean,
|
||||||
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
@Inject(NativeWindowService) protected _window: NativeWindowRef,
|
||||||
private route: RouteService,
|
private route: RouteService,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
@@ -81,7 +83,11 @@ export class LogInShibbolethComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
redirectToShibboleth() {
|
redirectToShibboleth() {
|
||||||
this.authService.setRedirectUrlIfNotSet(this.hardRedirectService.getCurrentRoute())
|
if (!this.isStandalonePage) {
|
||||||
|
this.authService.setRedirectUrl(this.hardRedirectService.getCurrentRoute());
|
||||||
|
} else {
|
||||||
|
this.authService.setRedirectUrlIfNotSet('/');
|
||||||
|
}
|
||||||
let newLocationUrl = this.location;
|
let newLocationUrl = this.location;
|
||||||
const currentUrl = this._window.nativeWindow.location.href;
|
const currentUrl = this._window.nativeWindow.location.href;
|
||||||
const myRegexp = /\?redirectUrl=(.*)/g;
|
const myRegexp = /\?redirectUrl=(.*)/g;
|
||||||
|
@@ -162,4 +162,8 @@ export class AuthServiceStub {
|
|||||||
redirectAfterLoginSuccess() {
|
redirectAfterLoginSuccess() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearRedirectUrl() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user