mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-18 15:33:04 +00:00
Added i18n label and fixes
This commit is contained in:
@@ -165,5 +165,13 @@
|
||||
"header": "Log out from DSpace",
|
||||
"submit": "Log out"
|
||||
}
|
||||
},
|
||||
"auth": {
|
||||
"messages": {
|
||||
"expired": "Your session has expired. Please log in again."
|
||||
},
|
||||
"errors": {
|
||||
"invalid-user": "Invalid email or password."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -142,7 +142,7 @@ export class AuthInterceptor implements HttpInterceptor {
|
||||
} else if (this.isUnauthorized(error)) {
|
||||
// The access token provided is expired, revoked, malformed, or invalid for other reasons
|
||||
// Redirect to the login route
|
||||
this.store.dispatch(new RedirectWhenTokenExpiredAction('Your session has expired. Please log in again.'));
|
||||
this.store.dispatch(new RedirectWhenTokenExpiredAction('auth.messages.expired'));
|
||||
}
|
||||
}
|
||||
// Return error response as is.
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -17,8 +17,8 @@
|
||||
formControlName="password"
|
||||
required
|
||||
type="password">
|
||||
<div *ngIf="platform.isBrowser && (error | async) && hasError" class="alert alert-danger" role="alert" @fadeOut>{{ error | async }}</div>
|
||||
<div *ngIf="(message | async) && hasMessage" class="alert alert-info" role="alert" @fadeOut>{{ message | async }}</div>
|
||||
<div *ngIf="platform.isBrowser && (error | async) && hasError" class="alert alert-danger" role="alert" @fadeOut>{{ (error | async) | translate }}</div>
|
||||
<div *ngIf="(message | async) && hasMessage" class="alert alert-info" role="alert" @fadeOut>{{ (message | async) | translate }}</div>
|
||||
<button class="btn btn-lg btn-primary btn-block mt-3" type="submit" [disabled]="!form.valid">{{"login.form.submit" | translate}}</button>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item" href="#">{{"login.form.new-user" | translate}}</a>
|
||||
|
Reference in New Issue
Block a user