mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Modified log-in component to set the redirect url only if one has not been set already.
This commit is contained in:
@@ -118,6 +118,23 @@ describe('LogInComponent', () => {
|
|||||||
expect(authService.setRedirectUrl).toHaveBeenCalled();
|
expect(authService.setRedirectUrl).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not set the redirect url because one already exists', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
const authService: AuthService = TestBed.get(AuthService);
|
||||||
|
authService.setRedirectUrl('/submit')
|
||||||
|
|
||||||
|
// set FormControl values
|
||||||
|
component.form.controls.email.setValue('user');
|
||||||
|
component.form.controls.password.setValue('password');
|
||||||
|
|
||||||
|
spyOn(authService, 'setRedirectUrl');
|
||||||
|
|
||||||
|
component.submit();
|
||||||
|
|
||||||
|
expect(authService.setRedirectUrl).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { filter, map, takeWhile } from 'rxjs/operators';
|
import {filter, map, take, takeWhile, tap} from 'rxjs/operators';
|
||||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
} from '../../core/auth/selectors';
|
} from '../../core/auth/selectors';
|
||||||
import { CoreState } from '../../core/core.reducers';
|
import { CoreState } from '../../core/core.reducers';
|
||||||
|
|
||||||
import { isNotEmpty } from '../empty.util';
|
import {isEmpty, isNotEmpty} from '../empty.util';
|
||||||
import { fadeOut } from '../animations/fade';
|
import { fadeOut } from '../animations/fade';
|
||||||
import { AuthService } from '../../core/auth/auth.service';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
import {Router} from '@angular/router';
|
import {Router} from '@angular/router';
|
||||||
@@ -185,13 +185,17 @@ export class LogInComponent implements OnDestroy, OnInit {
|
|||||||
email.trim();
|
email.trim();
|
||||||
password.trim();
|
password.trim();
|
||||||
|
|
||||||
// add the current url to store for later redirect.
|
this.authService.getRedirectUrl().pipe(
|
||||||
this.authService.setRedirectUrl(this.router.url);
|
take(1)).
|
||||||
|
subscribe((r) => {
|
||||||
// dispatch AuthenticationAction
|
// Set the redirect url if none exists.
|
||||||
this.store.dispatch(new AuthenticateAction(email, password));
|
if (isEmpty(r)) {
|
||||||
|
this.authService.setRedirectUrl(this.router.url)
|
||||||
// clear form
|
}
|
||||||
this.form.reset();
|
// dispatch AuthenticationAction
|
||||||
|
this.store.dispatch(new AuthenticateAction(email, password));
|
||||||
|
// clear form
|
||||||
|
this.form.reset();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,6 +10,7 @@ export class AuthServiceStub {
|
|||||||
|
|
||||||
token: AuthTokenInfo = new AuthTokenInfo('token_test');
|
token: AuthTokenInfo = new AuthTokenInfo('token_test');
|
||||||
private _tokenExpired = false;
|
private _tokenExpired = false;
|
||||||
|
private redirectUrl;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.token.expires = Date.now() + (1000 * 60 * 60);
|
this.token.expires = Date.now() + (1000 * 60 * 60);
|
||||||
@@ -88,7 +89,11 @@ export class AuthServiceStub {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setRedirectUrl(url: string) {
|
setRedirectUrl(url: string) {
|
||||||
return;
|
this.redirectUrl = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
getRedirectUrl() {
|
||||||
|
return observableOf(this.redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public storeToken(token: AuthTokenInfo) {
|
public storeToken(token: AuthTokenInfo) {
|
||||||
|
Reference in New Issue
Block a user