Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Participants can close the browser and log again when accessing. #480

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading