From 2cdccc4dd8b84b609004679a1f9e6cec667579f8 Mon Sep 17 00:00:00 2001 From: Michel ten Voorde Date: Wed, 8 Oct 2025 22:15:41 +0200 Subject: [PATCH] Cleanup --- src/app/auth/auth.service.ts | 1 - .../authentication/authentication.service.ts | 35 ---------- src/app/authentication/authguard.ts | 22 ------ src/app/authentication/errorInterceptor.ts | 31 --------- src/app/authentication/ip.service.ts | 14 ---- src/app/authentication/loginCredentials.ts | 6 -- src/app/authentication/tokenInterceptor.ts | 27 -------- src/app/authentication/tokenModel.ts | 11 --- src/app/authentication/user.service.ts | 69 ------------------- src/app/authentication/user.ts | 8 --- src/app/components/login/login.component.ts | 17 ++--- .../tournament-manage.component.ts | 1 - .../tournament-players.component.ts | 5 -- 13 files changed, 4 insertions(+), 243 deletions(-) delete mode 100644 src/app/authentication/authentication.service.ts delete mode 100644 src/app/authentication/authguard.ts delete mode 100644 src/app/authentication/errorInterceptor.ts delete mode 100644 src/app/authentication/ip.service.ts delete mode 100644 src/app/authentication/loginCredentials.ts delete mode 100644 src/app/authentication/tokenInterceptor.ts delete mode 100644 src/app/authentication/tokenModel.ts delete mode 100644 src/app/authentication/user.service.ts delete mode 100644 src/app/authentication/user.ts diff --git a/src/app/auth/auth.service.ts b/src/app/auth/auth.service.ts index 4de0fcb..9fcabf1 100644 --- a/src/app/auth/auth.service.ts +++ b/src/app/auth/auth.service.ts @@ -79,7 +79,6 @@ export class AuthService { const decodedToken = jwtDecode(token); return decodedToken.sub || null; // 'sub' is the standard JWT claim for subject/username } catch (error) { - console.error('Error decoding token:', error); return null; } } diff --git a/src/app/authentication/authentication.service.ts b/src/app/authentication/authentication.service.ts deleted file mode 100644 index 5d99fca..0000000 --- a/src/app/authentication/authentication.service.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; -import {environment} from "../../environments/environment"; -import {LoginCredentials} from "./loginCredentials"; -import {TokenModel} from "./tokenModel"; - -@Injectable({ - providedIn: 'root' -}) -export class AuthenticationService { - - private readonly authUrl: string - - constructor(private http: HttpClient) { - this.authUrl = `${environment.backendUrl}` - } - - public login(loginCredentials: LoginCredentials) { - return this.http.post(`${this.authUrl}/authenticate`, loginCredentials); - } - - public logout(tokenModel: TokenModel) { - return this.http.post( - `${this.authUrl}/logout`, - tokenModel - ); - } - - public logoutEverywhere() { - return this.http.post( - `${this.authUrl}/logout-everywhere`, - undefined - ); - } -} diff --git a/src/app/authentication/authguard.ts b/src/app/authentication/authguard.ts deleted file mode 100644 index d04bd5a..0000000 --- a/src/app/authentication/authguard.ts +++ /dev/null @@ -1,22 +0,0 @@ -import {Injectable} from "@angular/core"; -import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from "@angular/router"; -import {UserService} from "./user.service"; -import {delay, map, Observable, of} from "rxjs"; - -@Injectable() -export class AuthGuard implements CanActivate { - - constructor( - private router: Router, - private userService: UserService - ) {} - - canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { - if (this.userService.getUser()) { - return true; - } - this.router.navigate(['/auth/login'], { queryParams: { returnUrl: state.url } }); - return false; - } - -} diff --git a/src/app/authentication/errorInterceptor.ts b/src/app/authentication/errorInterceptor.ts deleted file mode 100644 index cdb85c0..0000000 --- a/src/app/authentication/errorInterceptor.ts +++ /dev/null @@ -1,31 +0,0 @@ -import {Injectable} from "@angular/core"; -import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http"; -import {catchError, Observable, throwError} from "rxjs"; -import {UserService} from "./user.service"; - -@Injectable({ - providedIn: 'root' -}) -export class ErrorInterceptor implements HttpInterceptor { - - constructor(private userService: UserService) { } - - intercept( - request: HttpRequest, - next: HttpHandler - ): Observable> { - - return next.handle(request).pipe(catchError(error=>{ - if((error.status == 401 || error.status == 403) && !this.isLoginPage(request)){ - this.userService.removeUser(); - } - // const errMsg = error.error.message || error.statusText; - return throwError(() => error); - // return throwError(()=> errMsg); - })); - } - - private isLoginPage(request: HttpRequest){ - return request.url.includes("/authenticate") - } -} diff --git a/src/app/authentication/ip.service.ts b/src/app/authentication/ip.service.ts deleted file mode 100644 index 3d736ba..0000000 --- a/src/app/authentication/ip.service.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { HttpClient } from '@angular/common/http'; -import { Injectable } from '@angular/core'; - -@Injectable({ - providedIn: 'root' -}) -export class IpService { - - constructor(private http: HttpClient) { } - - public getIPAddress() { - return this.http.get("http://api.ipify.org/?format=json"); - } -} diff --git a/src/app/authentication/loginCredentials.ts b/src/app/authentication/loginCredentials.ts deleted file mode 100644 index 7be03df..0000000 --- a/src/app/authentication/loginCredentials.ts +++ /dev/null @@ -1,6 +0,0 @@ -export class LoginCredentials { - username: string; - password: string; - // ipAddress: string; - // recaptcha: string; -} diff --git a/src/app/authentication/tokenInterceptor.ts b/src/app/authentication/tokenInterceptor.ts deleted file mode 100644 index 6077430..0000000 --- a/src/app/authentication/tokenInterceptor.ts +++ /dev/null @@ -1,27 +0,0 @@ -import {Injectable} from "@angular/core"; -import {HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from "@angular/common/http"; -import {Observable} from "rxjs"; -import {UserService} from "./user.service"; - -@Injectable({ - providedIn: 'root' -}) -export class TokenInterceptor implements HttpInterceptor { - - constructor(private userService: UserService) { } - - intercept( - request: HttpRequest, - next: HttpHandler - ): Observable> { - if (this.userService.isLoggedIn()) { - let newRequest = request.clone({ - setHeaders: { - Authorization: `Bearer ${this.userService.getUser()?.accessToken}`, - }, - }); - return next.handle(newRequest); - } - return next.handle(request); - } -} diff --git a/src/app/authentication/tokenModel.ts b/src/app/authentication/tokenModel.ts deleted file mode 100644 index 9574a4a..0000000 --- a/src/app/authentication/tokenModel.ts +++ /dev/null @@ -1,11 +0,0 @@ -export class TokenModel { - constructor(token: string, refreshToken: string, ipAddress: string) { - this.token = token; - this.refreshToken = refreshToken; - this.ipAddress = ipAddress; - } - - token: string; - refreshToken: string; - ipAddress: string; -} \ No newline at end of file diff --git a/src/app/authentication/user.service.ts b/src/app/authentication/user.service.ts deleted file mode 100644 index cbc9248..0000000 --- a/src/app/authentication/user.service.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { Injectable } from "@angular/core"; -import { SsrCookieService } from "ngx-cookie-service-ssr"; -import { Router } from "@angular/router"; -import { User } from "./user"; -import { BehaviorSubject } from "rxjs"; - -@Injectable({ - providedIn: 'root' -}) -export class UserService { - private user?: User; - private userEmitter = new BehaviorSubject(''); - private initialized = false; - - currentUser = this.userEmitter.asObservable(); - - constructor( - private cookieService: SsrCookieService, - private router: Router, - ) {} - - initializeUser() { - if (this.initialized) return; - - try { - const userCookie = this.cookieService.get('swissuser'); - if (userCookie && userCookie.trim() !== '') { - this.user = JSON.parse(userCookie); - if (this.user?.username) { - this.userEmitter.next(this.user.username); - } else { - this.userEmitter.next(''); - } - } else { - this.user = undefined; - this.userEmitter.next(''); - } - } catch (error) { - console.error('Error parsing user cookie:', error); - this.user = undefined; - this.userEmitter.next(''); - } - - this.initialized = true; - } - - public getUser(): User | undefined { - this.initializeUser(); - return this.user; - } - - public isLoggedIn(): boolean { - this.initializeUser(); - return !!this.user; - } - - public setUser(user: User) { - this.cookieService.set('swissuser', JSON.stringify(user)); - this.user = user; - this.userEmitter.next(this.user.username); - } - - public removeUser() { - this.cookieService.delete('swissuser'); - this.user = undefined; - this.router.navigate(['/tournaments']); - this.userEmitter.next(''); - } -} diff --git a/src/app/authentication/user.ts b/src/app/authentication/user.ts deleted file mode 100644 index 1e32bfc..0000000 --- a/src/app/authentication/user.ts +++ /dev/null @@ -1,8 +0,0 @@ -export class User { - accessToken: string; - username: string; - // passwordHash: string; - // email: string; - // token: string; - // refreshToken: string; -} diff --git a/src/app/components/login/login.component.ts b/src/app/components/login/login.component.ts index 694e014..06b83b3 100644 --- a/src/app/components/login/login.component.ts +++ b/src/app/components/login/login.component.ts @@ -1,15 +1,10 @@ -import {FormBuilder, FormGroup, FormsModule, ReactiveFormsModule, Validators} from '@angular/forms'; +import {FormGroup, FormsModule, ReactiveFormsModule} from '@angular/forms'; import {Component, OnInit} from '@angular/core'; -import {ActivatedRoute, Router, RouterLink} from '@angular/router'; -import {MatCard, MatCardContent, MatCardHeader, MatCardTitle} from "@angular/material/card"; -import {MatError, MatFormField, MatLabel} from "@angular/material/form-field"; +import {ActivatedRoute, Router} from '@angular/router'; +import {MatCard, MatCardContent} from "@angular/material/card"; +import {MatFormField, MatLabel} from "@angular/material/form-field"; import {MatButton} from "@angular/material/button"; import {MatInput} from "@angular/material/input"; -import {NgIf} from "@angular/common"; -import {AuthenticationService} from "../../authentication/authentication.service"; -import {UserService} from "../../authentication/user.service"; -import {LoginCredentials} from "../../authentication/loginCredentials"; -import {User} from "../../authentication/user"; import {jwtDecode, JwtPayload} from "jwt-decode"; import {AuthService} from "../../auth/auth.service"; import {MatSnackBar} from "@angular/material/snack-bar"; @@ -52,13 +47,11 @@ export class LoginComponent implements OnInit { } public login(): void { - console.log('Na inloggen door naar' + this.returnUrl); sessionStorage.removeItem("app.token"); this.authService.login(this.username, this.password) .subscribe({ next: (token) => { - console.log('Login successful'); sessionStorage.setItem("app.token", token); const decodedToken = jwtDecode(token); @@ -66,13 +59,11 @@ export class LoginComponent implements OnInit { sessionStorage.setItem("app.roles", decodedToken.scope); // this.router.navigateByUrl("/persons"); - console.log('Let us go to {url}', this.returnUrl); // this.router.navigate([this.returnUrl]); this.router.navigate([this.route.snapshot.queryParams['returnUrl'] || '/']); }, error: (error) => { - console.log('Login unsuccesful'); this.snackBar.open(`Login failed: ${error.status}`, "OK") } }); diff --git a/src/app/components/tournament-manage/tournament-manage.component.ts b/src/app/components/tournament-manage/tournament-manage.component.ts index a43288a..dd81212 100644 --- a/src/app/components/tournament-manage/tournament-manage.component.ts +++ b/src/app/components/tournament-manage/tournament-manage.component.ts @@ -213,7 +213,6 @@ export class TournamentManageComponent implements OnInit, OnDestroy { minHeight: '250px' }).afterClosed().subscribe(result => { if (result != undefined) { - console.log('Start match on court ' + result.court + ' with counter ' + result.counter.name); this.tournamentService.startMatch(this.tournament.id, match.id, result.court, result.counter.playerId).subscribe(data => { this.tournament = data; }); diff --git a/src/app/components/tournament-players/tournament-players.component.ts b/src/app/components/tournament-players/tournament-players.component.ts index 2f74d64..99718da 100644 --- a/src/app/components/tournament-players/tournament-players.component.ts +++ b/src/app/components/tournament-players/tournament-players.component.ts @@ -67,13 +67,8 @@ export class TournamentPlayersComponent { minHeight: '250px' }).afterClosed().subscribe(result => { if (result != undefined) { - console.log('Substitutes selected for ' + player.name + ': '); - console.log(result.substitutions); - console.log(result.substitutions[0].event + ': ' + result.substitutions[0].substitute); - console.log(result.substitutions[1].event + ': ' + result.substitutions[1].substitute); this.tournamentService.playerSubstitute(this.tournament.id, player.playerId, result.substitutions).subscribe(data => { this.tournament = data; - console.log(this.tournament); }); } });