mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 07:23:03 +00:00
Added i18n label and fixes
This commit is contained in:
@@ -49,7 +49,7 @@ export class AuthService {
|
||||
// and is not the login route, clear redirect url and messages
|
||||
const routeUrlObs = this.store.select(routerStateSelector)
|
||||
.filter((routerState: RouterReducerState) => isNotUndefined(routerState) && isNotUndefined(routerState.state))
|
||||
.filter((routerState: RouterReducerState) => (routerState.state.url !== LOGIN_ROUTE))
|
||||
.filter((routerState: RouterReducerState) => !this.isLoginRoute(routerState.state.url))
|
||||
.map((routerState: RouterReducerState) => routerState.state.url);
|
||||
const redirectUrlObs = this.getRedirectUrl();
|
||||
routeUrlObs.pipe(
|
||||
@@ -57,10 +57,23 @@ export class AuthService {
|
||||
map(([routeUrl, redirectUrl]) => [routeUrl, redirectUrl])
|
||||
).filter(([routeUrl, redirectUrl]) => isNotEmpty(redirectUrl) && (routeUrl !== redirectUrl))
|
||||
.subscribe(() => {
|
||||
this.setRedirectUrl(undefined);
|
||||
this.clearRedirectUrl();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if is a login page route
|
||||
*
|
||||
* @param {string} url
|
||||
* @returns {Boolean}.
|
||||
*/
|
||||
protected isLoginRoute(url: string) {
|
||||
const urlTree: UrlTree = this.router.parseUrl(url);
|
||||
const g: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
||||
const segment = '/' + g.toString();
|
||||
return segment === LOGIN_ROUTE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate the user
|
||||
*
|
||||
@@ -175,7 +188,7 @@ export class AuthService {
|
||||
if (!status.authenticated) {
|
||||
return true;
|
||||
} else {
|
||||
throw(new Error('Invalid email or password'));
|
||||
throw(new Error('auth.errors.invalid-user'));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -264,7 +277,7 @@ export class AuthService {
|
||||
*/
|
||||
public redirectToLogin() {
|
||||
// Hard redirect to login page, so that all state is definitely lost
|
||||
this._window.nativeWindow.location.href = LOGIN_ROUTE;
|
||||
this._window.nativeWindow.location.href = LOGIN_ROUTE + '?expired=true';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,9 +288,7 @@ export class AuthService {
|
||||
.first()
|
||||
.subscribe((redirectUrl) => {
|
||||
if (isNotEmpty(redirectUrl)) {
|
||||
// Clear redirect url
|
||||
this.setRedirectUrl(undefined);
|
||||
this.storage.remove(REDIRECT_COOKIE);
|
||||
this.clearRedirectUrl();
|
||||
|
||||
const urlTree: UrlTree = this.router.parseUrl(redirectUrl);
|
||||
const g: UrlSegmentGroup = urlTree.root.children[PRIMARY_OUTLET];
|
||||
@@ -327,4 +338,12 @@ export class AuthService {
|
||||
this.storage.set(REDIRECT_COOKIE, url);
|
||||
this.store.dispatch(new SetRedirectUrlAction(isNotUndefined(url) ? url : ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear redirect url
|
||||
*/
|
||||
clearRedirectUrl() {
|
||||
this.store.dispatch(new SetRedirectUrlAction(''));
|
||||
this.storage.remove(REDIRECT_COOKIE);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user