mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
fixed redirect after login
This commit is contained in:
@@ -56,7 +56,6 @@ export class SearchFiltersComponent {
|
|||||||
* @returns {Observable<boolean>} Emits true whenever a given filter config should be shown
|
* @returns {Observable<boolean>} Emits true whenever a given filter config should be shown
|
||||||
*/
|
*/
|
||||||
isActive(filter: SearchFilterConfig): Observable<boolean> {
|
isActive(filter: SearchFilterConfig): Observable<boolean> {
|
||||||
// console.log(filter.name);
|
|
||||||
return this.filterService.getSelectedValuesForFilter(filter)
|
return this.filterService.getSelectedValuesForFilter(filter)
|
||||||
.flatMap((isActive) => {
|
.flatMap((isActive) => {
|
||||||
if (isNotEmpty(isActive)) {
|
if (isNotEmpty(isActive)) {
|
||||||
|
@@ -54,7 +54,7 @@ export class AuthService {
|
|||||||
protected storage: CookieService,
|
protected storage: CookieService,
|
||||||
protected store: Store<AppState>,
|
protected store: Store<AppState>,
|
||||||
protected rdbService: RemoteDataBuildService
|
protected rdbService: RemoteDataBuildService
|
||||||
) {
|
) {
|
||||||
this.store.select(isAuthenticated)
|
this.store.select(isAuthenticated)
|
||||||
.startWith(false)
|
.startWith(false)
|
||||||
.subscribe((authenticated: boolean) => this._authenticated = authenticated);
|
.subscribe((authenticated: boolean) => this._authenticated = authenticated);
|
||||||
@@ -107,7 +107,7 @@ export class AuthService {
|
|||||||
if (status.authenticated) {
|
if (status.authenticated) {
|
||||||
return status;
|
return status;
|
||||||
} else {
|
} else {
|
||||||
Observable.throw(new Error('Invalid email or password'));
|
throw(new Error('Invalid email or password'));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@ export class AuthService {
|
|||||||
const person$ = this.rdbService.buildSingle<NormalizedEPerson, EPerson>(status.eperson.toString());
|
const person$ = this.rdbService.buildSingle<NormalizedEPerson, EPerson>(status.eperson.toString());
|
||||||
return person$.pipe(map((eperson) => eperson.payload));
|
return person$.pipe(map((eperson) => eperson.payload));
|
||||||
} else {
|
} else {
|
||||||
Observable.throw(new Error('Not authenticated'));
|
throw(new Error('Not authenticated'));
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -216,7 +216,7 @@ export class AuthService {
|
|||||||
// Send a request that sign end the session
|
// Send a request that sign end the session
|
||||||
let headers = new HttpHeaders();
|
let headers = new HttpHeaders();
|
||||||
headers = headers.append('Content-Type', 'application/x-www-form-urlencoded');
|
headers = headers.append('Content-Type', 'application/x-www-form-urlencoded');
|
||||||
const options: HttpOptions = Object.create({headers, responseType: 'text'});
|
const options: HttpOptions = Object.create({ headers, responseType: 'text' });
|
||||||
return this.authRequestService.getRequest('logout', options)
|
return this.authRequestService.getRequest('logout', options)
|
||||||
.map((status: AuthStatus) => {
|
.map((status: AuthStatus) => {
|
||||||
if (!status.authenticated) {
|
if (!status.authenticated) {
|
||||||
@@ -225,7 +225,6 @@ export class AuthService {
|
|||||||
throw(new Error('auth.errors.invalid-user'));
|
throw(new Error('auth.errors.invalid-user'));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -246,6 +245,7 @@ export class AuthService {
|
|||||||
public getToken(): AuthTokenInfo {
|
public getToken(): AuthTokenInfo {
|
||||||
let token: AuthTokenInfo;
|
let token: AuthTokenInfo;
|
||||||
this.store.select(getAuthenticationToken)
|
this.store.select(getAuthenticationToken)
|
||||||
|
.first()
|
||||||
.subscribe((authTokenInfo: AuthTokenInfo) => {
|
.subscribe((authTokenInfo: AuthTokenInfo) => {
|
||||||
// Retrieve authentication token info and check if is valid
|
// Retrieve authentication token info and check if is valid
|
||||||
token = authTokenInfo || null;
|
token = authTokenInfo || null;
|
||||||
@@ -291,7 +291,7 @@ export class AuthService {
|
|||||||
|
|
||||||
// Set the cookie expire date
|
// Set the cookie expire date
|
||||||
const expires = new Date(expireDate);
|
const expires = new Date(expireDate);
|
||||||
const options: CookieAttributes = {expires: expires};
|
const options: CookieAttributes = { expires: expires };
|
||||||
|
|
||||||
// Save cookie with the token
|
// Save cookie with the token
|
||||||
return this.storage.set(TOKENITEM, token, options);
|
return this.storage.set(TOKENITEM, token, options);
|
||||||
@@ -349,8 +349,10 @@ export class AuthService {
|
|||||||
this.router.navigated = false;
|
this.router.navigated = false;
|
||||||
const url = decodeURIComponent(redirectUrl);
|
const url = decodeURIComponent(redirectUrl);
|
||||||
this.router.navigateByUrl(url);
|
this.router.navigateByUrl(url);
|
||||||
|
this._window.nativeWindow.location.href = url;
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
|
this._window.nativeWindow.location.href = '/';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -386,7 +388,7 @@ export class AuthService {
|
|||||||
|
|
||||||
// Set the cookie expire date
|
// Set the cookie expire date
|
||||||
const expires = new Date(expireDate);
|
const expires = new Date(expireDate);
|
||||||
const options: CookieAttributes = {expires: expires};
|
const options: CookieAttributes = { expires: expires };
|
||||||
this.storage.set(REDIRECT_COOKIE, url, options);
|
this.storage.set(REDIRECT_COOKIE, url, options);
|
||||||
this.store.dispatch(new SetRedirectUrlAction(isNotUndefined(url) ? url : ''));
|
this.store.dispatch(new SetRedirectUrlAction(isNotUndefined(url) ? url : ''));
|
||||||
}
|
}
|
||||||
|
@@ -44,7 +44,7 @@ export class ServerAuthService extends AuthService {
|
|||||||
// person$.subscribe(() => console.log('test'));
|
// person$.subscribe(() => console.log('test'));
|
||||||
return person$.pipe(map((eperson) => eperson.payload));
|
return person$.pipe(map((eperson) => eperson.payload));
|
||||||
} else {
|
} else {
|
||||||
Observable.throw(new Error('Not authenticated'));
|
throw(new Error('Not authenticated'));
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@@ -71,8 +71,10 @@ export class ServerAuthService extends AuthService {
|
|||||||
this.router.navigated = false;
|
this.router.navigated = false;
|
||||||
const url = decodeURIComponent(redirectUrl);
|
const url = decodeURIComponent(redirectUrl);
|
||||||
this.router.navigateByUrl(url);
|
this.router.navigateByUrl(url);
|
||||||
|
this._window.nativeWindow.location.href = url;
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
|
this._window.nativeWindow.location.href = '/';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@ import { HostWindowServiceStub } from '../shared/testing/host-window-service-stu
|
|||||||
import { RouterStub } from '../shared/testing/router-stub';
|
import { RouterStub } from '../shared/testing/router-stub';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
|
|
||||||
let comp: HeaderComponent;
|
let comp: HeaderComponent;
|
||||||
let fixture: ComponentFixture<HeaderComponent>;
|
let fixture: ComponentFixture<HeaderComponent>;
|
||||||
@@ -35,11 +36,12 @@ describe('HeaderComponent', () => {
|
|||||||
NgbCollapseModule.forRoot(),
|
NgbCollapseModule.forRoot(),
|
||||||
NoopAnimationsModule,
|
NoopAnimationsModule,
|
||||||
ReactiveFormsModule],
|
ReactiveFormsModule],
|
||||||
declarations: [HeaderComponent, AuthNavMenuComponent, LoadingComponent, LogInComponent, LogOutComponent],
|
declarations: [HeaderComponent],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
|
||||||
{ provide: Router, useClass: RouterStub },
|
{ provide: Router, useClass: RouterStub },
|
||||||
]
|
],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
})
|
})
|
||||||
.compileComponents(); // compile template and css
|
.compileComponents(); // compile template and css
|
||||||
}));
|
}));
|
||||||
|
@@ -13,7 +13,7 @@ import { HostWindowServiceStub } from '../testing/host-window-service-stub';
|
|||||||
import { HostWindowService } from '../host-window.service';
|
import { HostWindowService } from '../host-window.service';
|
||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
|
import { AuthTokenInfo } from '../../core/auth/models/auth-token-info.model';
|
||||||
import { EPerson } from '../../core/eperson/models/eperson.model';
|
import { AuthService } from '../../core/auth/auth.service';
|
||||||
|
|
||||||
describe('AuthNavMenuComponent', () => {
|
describe('AuthNavMenuComponent', () => {
|
||||||
|
|
||||||
@@ -54,6 +54,7 @@ describe('AuthNavMenuComponent', () => {
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: HostWindowService, useValue: window},
|
{provide: HostWindowService, useValue: window},
|
||||||
|
{provide: AuthService, useValue: {setRedirectUrl: () => {}}}
|
||||||
],
|
],
|
||||||
schemas: [
|
schemas: [
|
||||||
CUSTOM_ELEMENTS_SCHEMA
|
CUSTOM_ELEMENTS_SCHEMA
|
||||||
@@ -223,6 +224,7 @@ describe('AuthNavMenuComponent', () => {
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{provide: HostWindowService, useValue: window},
|
{provide: HostWindowService, useValue: window},
|
||||||
|
{provide: AuthService, useValue: {setRedirectUrl: () => {}}}
|
||||||
],
|
],
|
||||||
schemas: [
|
schemas: [
|
||||||
CUSTOM_ELEMENTS_SCHEMA
|
CUSTOM_ELEMENTS_SCHEMA
|
||||||
|
@@ -7,10 +7,14 @@ 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 { getAuthenticatedUser, isAuthenticated, isAuthenticationLoading } from '../../core/auth/selectors';
|
import {
|
||||||
|
getAuthenticatedUser,
|
||||||
|
isAuthenticated,
|
||||||
|
isAuthenticationLoading
|
||||||
|
} from '../../core/auth/selectors';
|
||||||
import { EPerson } from '../../core/eperson/models/eperson.model';
|
import { EPerson } from '../../core/eperson/models/eperson.model';
|
||||||
import { LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service';
|
import { AuthService, LOGIN_ROUTE, LOGOUT_ROUTE } from '../../core/auth/auth.service';
|
||||||
import { RemoteData } from '../../core/data/remote-data';
|
import { Subscription } from 'rxjs/Subscription';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-auth-nav-menu',
|
selector: 'ds-auth-nav-menu',
|
||||||
@@ -37,8 +41,12 @@ export class AuthNavMenuComponent implements OnInit {
|
|||||||
|
|
||||||
public user: Observable<EPerson>;
|
public user: Observable<EPerson>;
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +62,12 @@ export class AuthNavMenuComponent implements OnInit {
|
|||||||
this.showAuth = this.store.select(routerStateSelector)
|
this.showAuth = this.store.select(routerStateSelector)
|
||||||
.filter((router: RouterReducerState) => isNotUndefined(router) && isNotUndefined(router.state))
|
.filter((router: RouterReducerState) => isNotUndefined(router) && isNotUndefined(router.state))
|
||||||
.map((router: RouterReducerState) => {
|
.map((router: RouterReducerState) => {
|
||||||
return !router.state.url.startsWith(LOGIN_ROUTE) && !router.state.url.startsWith(LOGOUT_ROUTE);
|
const url = router.state.url;
|
||||||
|
const show = !router.state.url.startsWith(LOGIN_ROUTE) && !router.state.url.startsWith(LOGOUT_ROUTE);
|
||||||
|
if (show) {
|
||||||
|
this.authService.setRedirectUrl(url);
|
||||||
|
}
|
||||||
|
return show;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user