diff --git a/README.md b/README.md index 6ae46095..4f25b8c5 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![GitHub commit activity](https://img.shields.io/github/commit-activity/y/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager) [![GitHub last commit](https://img.shields.io/github/last-commit/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager) [![CircleCI](https://circleci.com/gh/softwaremagico/KendoTournamentManager.svg?style=shield)](https://circleci.com/gh/softwaremagico/KendoTournamentManager) -[![Time](https://img.shields.io/badge/development-635h-blueviolet.svg)]() +[![Time](https://img.shields.io/badge/development-636.5h-blueviolet.svg)]() [![Powered by](https://img.shields.io/badge/powered%20by%20java-orange.svg?logo=OpenJDK&logoColor=white)]() [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=kendo-tournament-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=kendo-tournament-backend) diff --git a/frontend/src/app/interceptors/logged-in.service.ts b/frontend/src/app/interceptors/logged-in.service.ts index 8771f5d5..923bd947 100644 --- a/frontend/src/app/interceptors/logged-in.service.ts +++ b/frontend/src/app/interceptors/logged-in.service.ts @@ -20,13 +20,13 @@ export class LoggedInService { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { const context: string = state.url.substring(0, state.url.indexOf('?') > 0 ? state.url.indexOf('?') : state.url.length); + const params: string = state.url.indexOf('?') > 0 ? state.url.substring(state.url.indexOf('?') + 1) : ""; if (this.loginService.getJwtValue() || this.whiteListedPages.includes(context)) { //Read roles from JWT if it is a returning user. this.loginService.refreshDataFormJwt(); // JWT Token exists, is a registered participant. this.isUserLoggedIn.next(true); - //return this.userLoginPageDependingOnRoles(context); - return true; + return this.userLoginPageDependingOnRoles(context, params); } // Not logged in so redirect to login page with the return url @@ -35,8 +35,14 @@ export class LoggedInService { return false; } - userLoginPageDependingOnRoles(context: string): boolean { + userLoginPageDependingOnRoles(context: string, params: string): boolean { if (this.loginService.getJwtValue()) { + //Participant users must redirect to their statistcs. + if (localStorage.getItem('account') == 'participant' && !context.startsWith('/participants/statistics')) { + this.router.navigate(['/participants/statistics']); + } else if (localStorage.getItem('account') == 'guest' && !context.startsWith('/tournaments/fights')) { + this.router.navigate(['/tournaments/fights']); + } this.loginService.getUserRoles().subscribe((_roles: String[]): void => { if (_roles.includes("viewer") || _roles.includes("editor") || _roles.includes("admin")) { // Do nothing and navigate as usual. @@ -56,7 +62,7 @@ export class LoggedInService { }); return true; } - return false; + return this.whiteListedPages.includes(context); } } diff --git a/frontend/src/app/services/login.service.ts b/frontend/src/app/services/login.service.ts index bb6de70c..71a05cfe 100644 --- a/frontend/src/app/services/login.service.ts +++ b/frontend/src/app/services/login.service.ts @@ -79,6 +79,7 @@ export class LoginService { this.loginAsGuest(tournamentId).subscribe({ next: (authenticatedUser: AuthenticatedUser): void => { this.setAuthenticatedUser(authenticatedUser, callback); + localStorage.setItem('account', 'guest'); }, error: (): void => { this.router.navigate(["/"]); @@ -90,6 +91,7 @@ export class LoginService { this.loginAsParticipant(temporalToken).subscribe({ next: (authenticatedUser: AuthenticatedUser): void => { this.setAuthenticatedUser(authenticatedUser, callback); + localStorage.setItem('account', 'participant'); }, error: (): void => { this.router.navigate(["/"]); diff --git a/frontend/src/app/services/rbac/activity.service.ts b/frontend/src/app/services/rbac/activity.service.ts index 1fbded9c..3113b453 100644 --- a/frontend/src/app/services/rbac/activity.service.ts +++ b/frontend/src/app/services/rbac/activity.service.ts @@ -105,7 +105,8 @@ export class ActivityService { RbacActivity.CHANGE_LANGUAGE, RbacActivity.CHECK_TOURNAMENT_BRACKETS, RbacActivity.READ_TEAMS_RANKINGS, - RbacActivity.READ_COMPETITORS_RANKINGS + RbacActivity.READ_COMPETITORS_RANKINGS, + RbacActivity.CAN_LOGOUT ]; } diff --git a/frontend/src/app/views/participant-statistics/participant-statistics.component.ts b/frontend/src/app/views/participant-statistics/participant-statistics.component.ts index ddad93cf..eb376894 100644 --- a/frontend/src/app/views/participant-statistics/participant-statistics.component.ts +++ b/frontend/src/app/views/participant-statistics/participant-statistics.component.ts @@ -67,6 +67,9 @@ export class ParticipantStatisticsComponent extends RbacBasedComponent implement //Gets participant from URL parameter (from QR codes). this.participantId = Number(this.activatedRoute.snapshot.queryParamMap.get('participantId')); this.temporalToken = this.activatedRoute.snapshot.queryParamMap.get('temporalToken'); + if (this.temporalToken) { + this.loginService.logout() + } if (!this.participantId || isNaN(this.participantId)) { this.goBackToUsers(); } @@ -96,6 +99,7 @@ export class ParticipantStatisticsComponent extends RbacBasedComponent implement if (this.temporalToken) { this.loginService.setParticipantUserSession(this.temporalToken, (): void => { this.initializeData(); + this.router.navigate([]); }); } else { this.goBackToUsers();