Skip to content

Commit

Permalink
Participants can close the browser and log again when accessing.
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaremagico committed Jun 20, 2024
1 parent d91a941 commit 1a498b6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions frontend/src/app/interceptors/logged-in.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -56,7 +62,7 @@ export class LoggedInService {
});
return true;
}
return false;
return this.whiteListedPages.includes(context);
}
}

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/services/login.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(["/"]);
Expand All @@ -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(["/"]);
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/app/services/rbac/activity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1a498b6

Please sign in to comment.