Improved redirect url management

This commit is contained in:
Giuseppe Digilio
2019-01-23 13:01:11 +01:00
parent b561bf69e7
commit 1b820ea8ed
2 changed files with 18 additions and 22 deletions

View File

@@ -1,5 +1,6 @@
import { ServerResponseService } from '../shared/services/server-response.service'; import { ServerResponseService } from '../shared/services/server-response.service';
import { Component, ChangeDetectionStrategy } from '@angular/core'; import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { AuthService } from '../core/auth/auth.service';
@Component({ @Component({
selector: 'ds-pagenotfound', selector: 'ds-pagenotfound',
@@ -7,8 +8,13 @@ import { Component, ChangeDetectionStrategy } from '@angular/core';
templateUrl: './pagenotfound.component.html', templateUrl: './pagenotfound.component.html',
changeDetection: ChangeDetectionStrategy.Default changeDetection: ChangeDetectionStrategy.Default
}) })
export class PageNotFoundComponent { export class PageNotFoundComponent implements OnInit {
constructor(responseService: ServerResponseService) { constructor(private authservice: AuthService, private responseService: ServerResponseService) {
responseService.setNotFound(); this.responseService.setNotFound();
} }
ngOnInit(): void {
this.authservice.clearRedirectUrl();
}
} }

View File

@@ -1,6 +1,6 @@
import { of as observableOf, Observable , Subscription } from 'rxjs'; import { Observable, of as observableOf, Subscription } from 'rxjs';
import { map, filter } from 'rxjs/operators'; import { filter, map } from 'rxjs/operators';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { RouterReducerState } from '@ngrx/router-store'; import { RouterReducerState } from '@ngrx/router-store';
import { select, Store } from '@ngrx/store'; import { select, Store } from '@ngrx/store';
@@ -9,13 +9,9 @@ import { fadeInOut, fadeOut } from '../animations/fade';
import { HostWindowService } from '../host-window.service'; import { HostWindowService } from '../host-window.service';
import { AppState, routerStateSelector } from '../../app.reducer'; import { AppState, routerStateSelector } from '../../app.reducer';
import { isNotUndefined } from '../empty.util'; import { isNotUndefined } from '../empty.util';
import { import { getAuthenticatedUser, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors';
getAuthenticatedUser,
isAuthenticated,
isAuthenticationLoading
} from '../../core/auth/selectors';
import { EPerson } from '../../core/eperson/models/eperson.model'; import { EPerson } from '../../core/eperson/models/eperson.model';
import { AuthService, LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service'; import { LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service';
@Component({ @Component({
selector: 'ds-auth-nav-menu', selector: 'ds-auth-nav-menu',
@@ -45,8 +41,7 @@ export class AuthNavMenuComponent implements OnInit {
public sub: Subscription; public sub: Subscription;
constructor(private store: Store<AppState>, constructor(private store: Store<AppState>,
private windowService: HostWindowService, private windowService: HostWindowService
private authService: AuthService
) { ) {
this.isXsOrSm$ = this.windowService.isXsOrSm(); this.isXsOrSm$ = this.windowService.isXsOrSm();
} }
@@ -63,14 +58,9 @@ export class AuthNavMenuComponent implements OnInit {
this.showAuth = this.store.pipe( this.showAuth = this.store.pipe(
select(routerStateSelector), select(routerStateSelector),
filter((router: RouterReducerState) => isNotUndefined(router) && isNotUndefined(router.state)), filter((router: RouterReducerState) => isNotUndefined(router) && isNotUndefined(router.state)),
map((router: RouterReducerState) => { map((router: RouterReducerState) => (!router.state.url.startsWith(LOGIN_ROUTE)
const url = router.state.url; && !router.state.url.startsWith(LOGOUT_ROUTE))
const show = !router.state.url.startsWith(LOGIN_ROUTE) && !router.state.url.startsWith(LOGOUT_ROUTE); )
if (show) {
this.authService.setRedirectUrl(url);
}
return show;
})
); );
} }
} }