[Library | Trunk]: Add Error interceptor
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59856 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
parent
a9a0d270cb
commit
6bc598a8ac
|
@ -55,13 +55,15 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.updateLists();
|
this.updateLists();
|
||||||
this.userManagementService.getUserInfo().subscribe(user => {
|
this.userManagementService.getUserInfo().subscribe(user => {
|
||||||
if(!Session.isPortalAdministrator(user) && !Session.isCurator(this.type, user) && !Session.isManager(this.type, this.id, user)) {
|
if(user) {
|
||||||
this.router.navigate(['/user-info'], {
|
if(!Session.isPortalAdministrator(user) && !Session.isCurator(this.type, user) && !Session.isManager(this.type, this.id, user)) {
|
||||||
queryParams: {
|
this.router.navigate(['/user-info'], {
|
||||||
"errorCode": LoginErrorCodes.NOT_AUTHORIZED,
|
queryParams: {
|
||||||
"redirectUrl": this.router.url
|
"errorCode": LoginErrorCodes.NOT_AUTHORIZED,
|
||||||
}
|
"redirectUrl": this.router.url
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -92,7 +94,6 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges {
|
||||||
if(error.status === 404) {
|
if(error.status === 404) {
|
||||||
this.exists = false;
|
this.exists = false;
|
||||||
} else {
|
} else {
|
||||||
this.error = error.error.response;
|
|
||||||
}
|
}
|
||||||
this.loadActive = false;
|
this.loadActive = false;
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
import {Injectable} from "@angular/core";
|
||||||
|
import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http";
|
||||||
|
import {Observable, throwError} from "rxjs";
|
||||||
|
import {catchError} from "rxjs/operators";
|
||||||
|
import {Session} from "./login/utils/helper.class";
|
||||||
|
import {Router} from "@angular/router";
|
||||||
|
import {LoginErrorCodes} from "./login/utils/guardHelper.class";
|
||||||
|
import {properties} from "../../environments/environment";
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class ErrorInterceptorService implements HttpInterceptor {
|
||||||
|
|
||||||
|
constructor(private router: Router) {
|
||||||
|
}
|
||||||
|
|
||||||
|
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||||||
|
return next.handle(req).pipe(catchError(err => {
|
||||||
|
if ((err.status === 0 && this.isRegistryService(req)) || err.status === 401 || err.status === 403) {
|
||||||
|
this.logOut();
|
||||||
|
}
|
||||||
|
return throwError(err);
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
isRegistryService(req: HttpRequest<any>):boolean {
|
||||||
|
return req.url.indexOf(properties.registryUrl) !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
logOut() {
|
||||||
|
Session.removeUser();
|
||||||
|
this.router.navigate(['/user-info'], {
|
||||||
|
queryParams: {
|
||||||
|
'errorCode': LoginErrorCodes.NOT_LOGIN,
|
||||||
|
'redirectUrl': this.router.url
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,9 +5,7 @@ import { tap } from 'rxjs/operators';
|
||||||
import { TransferState, makeStateKey, StateKey } from '@angular/platform-browser';
|
import { TransferState, makeStateKey, StateKey } from '@angular/platform-browser';
|
||||||
import { isPlatformServer } from '@angular/common';
|
import { isPlatformServer } from '@angular/common';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable()
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class HttpInterceptorService implements HttpInterceptor {
|
export class HttpInterceptorService implements HttpInterceptor {
|
||||||
constructor(private transferState: TransferState, @Inject(PLATFORM_ID) private platformId: any) {}
|
constructor(private transferState: TransferState, @Inject(PLATFORM_ID) private platformId: any) {}
|
||||||
|
|
||||||
|
@ -40,4 +38,4 @@ export class HttpInterceptorService implements HttpInterceptor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,74 +1,76 @@
|
||||||
<div [id]="(mainComponent)?'tm-main':''" [class]="(mainComponent)?'uk-section uk-padding-remove-top tm-middle':''">
|
<div>
|
||||||
<div uk-grid uk-grid>
|
<div [id]="(mainComponent)?'tm-main':''" [class]="(mainComponent)?'uk-section uk-padding-remove-top tm-middle':''">
|
||||||
<div class="tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first ">
|
<div uk-grid uk-grid>
|
||||||
|
<div class="tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first ">
|
||||||
|
|
||||||
<div *ngIf="!server" class="uk-container uk-container-small uk-position-relative">
|
<div *ngIf="!server" class="uk-container uk-container-small uk-position-relative">
|
||||||
|
|
||||||
<div *ngIf="loggedIn && !errorCode" class="">
|
<div *ngIf="loggedIn && !errorCode" class="">
|
||||||
<div class="uk-h2 uk-text-center">User Information</div>
|
<div class="uk-h2 uk-text-center">User Information</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="uk-text-muted"> Full name </span> <span> {{user.fullname}} </span>
|
<span class="uk-text-muted"> Full name </span> <span> {{user.fullname}} </span>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<span class="uk-text-muted"> E-mail </span> <span> {{user.email}} </span>
|
<span class="uk-text-muted"> E-mail </span> <span> {{user.email}} </span>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="user.role.length > 1">
|
<div *ngIf="user.role.length > 1">
|
||||||
<span class="uk-text-muted"> Roles </span> <span> {{getTheRolesFormatted(user.role)}} </span>
|
<span class="uk-text-muted"> Roles </span> <span> {{getTheRolesFormatted(user.role)}} </span>
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-margin-top " *ngIf="user.role.length > 1">
|
<div class="uk-margin-top " *ngIf="user.role.length > 1">
|
||||||
<a class="uk-button uk-button-primary" href="https://aai.openaire.eu/roles/index.php"
|
<a class="uk-button uk-button-primary" href="https://aai.openaire.eu/roles/index.php"
|
||||||
target="_blank">Manage your roles</a> {{" "}}
|
target="_blank">Manage your roles</a> {{" "}}
|
||||||
<a *ngIf="user && isUserManager()" class="uk-button uk-button-primary"
|
<a *ngIf="user && isUserManager()" class="uk-button uk-button-primary"
|
||||||
href="https://aai.openaire.eu/roles/admin.php"
|
href="https://aai.openaire.eu/roles/admin.php"
|
||||||
target="_blank">Manage role requests</a>{{" "}}
|
target="_blank">Manage role requests</a>{{" "}}
|
||||||
<a *ngIf="user && isUserManager()" class="uk-button uk-button-primary"
|
<a *ngIf="user && isUserManager()" class="uk-button uk-button-primary"
|
||||||
href="https://aai.openaire.eu/registry"
|
href="https://aai.openaire.eu/registry"
|
||||||
target="_blank">Manage users</a>
|
target="_blank">Manage users</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- <button (click)="logout()" class=" uk-button uk-button-default">Log out</button> -->
|
||||||
</div>
|
</div>
|
||||||
|
<!--form *ngIf="!loggedIn" class=" ">
|
||||||
|
|
||||||
|
<h3>Welcome to OpenAIRE's Discover Portal</h3>
|
||||||
|
|
||||||
<!-- <button (click)="logout()" class=" uk-button uk-button-default">Log out</button> -->
|
<p>This service uses the same ldap sign-in as the OpenAIRE services so you can use the same
|
||||||
</div>
|
credentials.</p>
|
||||||
<!--form *ngIf="!loggedIn" class=" ">
|
|
||||||
|
|
||||||
<h3>Welcome to OpenAIRE's Discover Portal</h3>
|
<p>Login in. To see it in action.</p>
|
||||||
|
<div class="uk-margin">
|
||||||
|
<input class="uk-input uk-form-width-medium" placeholder="Username" type="text" name="username" [(ngModel)]="username">
|
||||||
|
</div>
|
||||||
|
|
||||||
<p>This service uses the same ldap sign-in as the OpenAIRE services so you can use the same
|
|
||||||
credentials.</p>
|
|
||||||
|
|
||||||
<p>Login in. To see it in action.</p>
|
|
||||||
<div class="uk-margin">
|
<div class="uk-margin">
|
||||||
<input class="uk-input uk-form-width-medium" placeholder="Username" type="text" name="username" [(ngModel)]="username">
|
<input placeholder="Password" class="uk-input uk-form-width-medium" type="password" name="password" [(ngModel)]="password">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="uk-margin">
|
||||||
<div class="uk-margin">
|
<button (click)="login()" class=" uk-button uk-button-primary">Login</button>
|
||||||
<input placeholder="Password" class="uk-input uk-form-width-medium" type="password" name="password" [(ngModel)]="password">
|
</div>
|
||||||
</div>
|
</form-->
|
||||||
<div class="uk-margin">
|
<div *ngIf="errorCode == '1'" class="uk-alert uk-alert-warning">
|
||||||
<button (click)="login()" class=" uk-button uk-button-primary">Login</button>
|
The requested page requires authentication.
|
||||||
</div>
|
<span *ngIf="!loggedIn">
|
||||||
</form-->
|
|
||||||
<div *ngIf="errorCode == '1'" class="uk-alert uk-alert-warning">
|
|
||||||
The requested page requires authentication.
|
|
||||||
<span *ngIf="!loggedIn">
|
|
||||||
Please <a class="" (click)="logIn()"> sign in</a> to continue.
|
Please <a class="" (click)="logIn()"> sign in</a> to continue.
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="errorCode == '2' || errorCode == '4' || errorCode == '8'" class="uk-alert uk-alert-warning">
|
<div *ngIf="errorCode == '2' || errorCode == '4' || errorCode == '8'" class="uk-alert uk-alert-warning">
|
||||||
You are not authorized to use the requested page.
|
You are not authorized to use the requested page.
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="errorCode == '3'" class="uk-alert uk-alert-warning">
|
<div *ngIf="errorCode == '3'" class="uk-alert uk-alert-warning">
|
||||||
The session has expired. Please <a class="" (click)="logIn()">sign in</a> again or continue <a class=""
|
The session has expired. Please <a class="" (click)="logIn()">sign in</a> again or continue <a class=""
|
||||||
(click)="redirect();">browsing
|
(click)="redirect();">browsing
|
||||||
as a guest</a>.
|
as a guest</a>.
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="errorCode == '5'" class="uk-alert uk-alert-warning">
|
<div *ngIf="errorCode == '5'" class="uk-alert uk-alert-warning">
|
||||||
There is no research community selected.
|
There is no research community selected.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="!loggedIn && errorMessage.length > 0" class="uk-alert uk-alert-danger">{{errorMessage}}</div>
|
<div *ngIf="!loggedIn && errorMessage.length > 0" class="uk-alert uk-alert-danger">{{errorMessage}}</div>
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -91,6 +91,7 @@ export class UserComponent {
|
||||||
paramsArray.push(queryParamsArray[i].split("=")[0]);
|
paramsArray.push(queryParamsArray[i].split("=")[0]);
|
||||||
valuesArray.push(queryParamsArray[i].split("=")[1]);
|
valuesArray.push(queryParamsArray[i].split("=")[1]);
|
||||||
}
|
}
|
||||||
|
console.debug('here');
|
||||||
this.router.navigate([route], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)});
|
this.router.navigate([route], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)});
|
||||||
} else {
|
} else {
|
||||||
this.router.navigate([route]);
|
this.router.navigate([route]);
|
||||||
|
|
Loading…
Reference in New Issue