diff --git a/dashboard/users/role-users/role-users.component.ts b/dashboard/users/role-users/role-users.component.ts index 2bd62aae..e114b43f 100644 --- a/dashboard/users/role-users/role-users.component.ts +++ b/dashboard/users/role-users/role-users.component.ts @@ -55,13 +55,15 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { ngOnInit() { this.updateLists(); this.userManagementService.getUserInfo().subscribe(user => { - if(!Session.isPortalAdministrator(user) && !Session.isCurator(this.type, user) && !Session.isManager(this.type, this.id, user)) { - this.router.navigate(['/user-info'], { - queryParams: { - "errorCode": LoginErrorCodes.NOT_AUTHORIZED, - "redirectUrl": this.router.url - } - }); + if(user) { + if(!Session.isPortalAdministrator(user) && !Session.isCurator(this.type, user) && !Session.isManager(this.type, this.id, user)) { + this.router.navigate(['/user-info'], { + queryParams: { + "errorCode": LoginErrorCodes.NOT_AUTHORIZED, + "redirectUrl": this.router.url + } + }); + } } }); } @@ -92,7 +94,6 @@ export class RoleUsersComponent implements OnInit, OnDestroy, OnChanges { if(error.status === 404) { this.exists = false; } else { - this.error = error.error.response; } this.loadActive = false; })); diff --git a/error-interceptor.service.ts b/error-interceptor.service.ts new file mode 100644 index 00000000..0c27810d --- /dev/null +++ b/error-interceptor.service.ts @@ -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, next: HttpHandler): Observable> { + 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):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 + } + }); + } +} diff --git a/http-interceptor.service.ts b/http-interceptor.service.ts index 66b655fe..a2d3ae12 100644 --- a/http-interceptor.service.ts +++ b/http-interceptor.service.ts @@ -5,9 +5,7 @@ import { tap } from 'rxjs/operators'; import { TransferState, makeStateKey, StateKey } from '@angular/platform-browser'; import { isPlatformServer } from '@angular/common'; -@Injectable({ - providedIn: 'root' -}) +@Injectable() export class HttpInterceptorService implements HttpInterceptor { constructor(private transferState: TransferState, @Inject(PLATFORM_ID) private platformId: any) {} @@ -40,4 +38,4 @@ export class HttpInterceptorService implements HttpInterceptor { } } } -} \ No newline at end of file +} diff --git a/login/user.component.html b/login/user.component.html index 98b90626..7602cc76 100644 --- a/login/user.component.html +++ b/login/user.component.html @@ -1,74 +1,76 @@ -
-
-
+
+
+
+
-
+
-
-
User Information
-
- Full name {{user.fullname}} -
-
- E-mail {{user.email}} -
-
- Roles {{getTheRolesFormatted(user.role)}} -
-
- Manage your roles {{" "}} - Manage role requests{{" "}} - Manage users +
+
User Information
+
+ Full name {{user.fullname}} +
+
+ E-mail {{user.email}} +
+
+ Roles {{getTheRolesFormatted(user.role)}} +
+ + + +
+ -
- -
- The requested page requires authentication. - + +
+
+ +
+ +
+ The requested page requires authentication. + Please sign in to continue. -
-
- You are not authorized to use the requested page. -
-
- The session has expired. Please sign in again or continue browsing - as a guest. -
-
- There is no research community selected. -
+
+
+ You are not authorized to use the requested page. +
+
+ The session has expired. Please sign in again or continue browsing + as a guest. +
+
+ There is no research community selected. +
-
{{errorMessage}}
+
{{errorMessage}}
+
diff --git a/login/user.component.ts b/login/user.component.ts index 6f73773d..0b38317f 100644 --- a/login/user.component.ts +++ b/login/user.component.ts @@ -91,6 +91,7 @@ export class UserComponent { paramsArray.push(queryParamsArray[i].split("=")[0]); valuesArray.push(queryParamsArray[i].split("=")[1]); } + console.debug('here'); this.router.navigate([route], {queryParams: this.routerHelper.createQueryParams(paramsArray, valuesArray)}); } else { this.router.navigate([route]);