Merge branch 'main' into task/CAS-75/UpdateFrontendDice
Some checks failed
CI / Get Changed Files (pull_request) Successful in 8s
CI / Checkstyle Main (pull_request) Has been skipped
CI / Docker backend validation (pull_request) Has been skipped
CI / oxlint (pull_request) Successful in 21s
CI / eslint (pull_request) Successful in 30s
CI / prettier (pull_request) Failing after 29s
CI / Docker frontend validation (pull_request) Successful in 1m9s
CI / test-build (pull_request) Successful in 1m12s

This commit is contained in:
Jan-Marlon Leibl 2025-05-21 12:06:41 +00:00
commit ed252696c4
No known key found for this signature in database
GPG key ID: 944223E4D46B7412
25 changed files with 478 additions and 153 deletions

View file

@ -1,12 +1,12 @@
import { Component, HostListener, inject, signal } from '@angular/core';
import { RouterOutlet } from '@angular/router';
import { NavbarComponent } from './shared/components/navbar/navbar.component';
import { FooterComponent } from './shared/components/footer/footer.component';
import { NavbarComponent } from '@shared/components/navbar/navbar.component';
import { FooterComponent } from '@shared/components/footer/footer.component';
import { LoginComponent } from './feature/auth/login/login.component';
import { RegisterComponent } from './feature/auth/register/register.component';
import { RecoverPasswordComponent } from './feature/auth/recover-password/recover-password.component';
import { PlaySoundDirective } from './shared/directives/play-sound.directive';
import { SoundInitializerService } from './shared/services/sound-initializer.service';
import RecoverPasswordComponent from './feature/auth/recover-password/recover-password.component';
import { PlaySoundDirective } from '@shared/directives/play-sound.directive';
import { SoundInitializerService } from '@shared/services/sound-initializer.service';
@Component({
selector: 'app-root',

View file

@ -14,61 +14,68 @@ export const routes: Routes = [
},
{
path: 'verify',
loadComponent: () =>
import('./feature/auth/verify-email/verify-email.component').then(
(m) => m.VerifyEmailComponent
),
loadComponent: () => import('./feature/auth/verify-email/verify-email.component'),
},
{
path: 'recover-password',
loadComponent: () =>
import('./feature/auth/recover-password/recover-password.component').then(
(m) => m.RecoverPasswordComponent
),
loadComponent: () => import('./feature/auth/recover-password/recover-password.component'),
},
{
path: 'reset-password',
loadComponent: () =>
import('./feature/auth/recover-password/recover-password.component').then(
(m) => m.RecoverPasswordComponent
),
loadComponent: () => import('./feature/auth/recover-password/recover-password.component'),
},
{
path: 'oauth2/callback/github',
loadComponent: () =>
import('./feature/auth/oauth2/oauth2-callback.component').then(
(m) => m.OAuth2CallbackComponent
),
path: 'oauth2/callback',
children: [
{
path: 'github',
loadComponent: () => import('./feature/auth/oauth2/oauth2-callback.component'),
data: { provider: 'github' },
},
{
path: 'google',
loadComponent: () => import('./feature/auth/oauth2/oauth2-callback.component'),
data: { provider: 'google' },
},
],
},
{
path: 'game/blackjack',
loadComponent: () => import('./feature/game/blackjack/blackjack.component'),
canActivate: [authGuard],
},
{
path: 'game/coinflip',
loadComponent: () => import('./feature/game/coinflip/coinflip.component'),
canActivate: [authGuard],
},
{
path: 'game/slots',
loadComponent: () => import('./feature/game/slots/slots.component'),
canActivate: [authGuard],
},
{
path: 'game/lootboxes',
loadComponent: () =>
import('./feature/lootboxes/lootbox-selection/lootbox-selection.component'),
canActivate: [authGuard],
},
{
path: 'game/lootboxes/open/:id',
loadComponent: () => import('./feature/lootboxes/lootbox-opening/lootbox-opening.component'),
canActivate: [authGuard],
},
{
path: 'game/dice',
loadComponent: () => import('./feature/game/dice/dice.component').then((m) => m.DiceComponent),
canActivate: [authGuard],
path: 'game',
children: [
{
path: 'blackjack',
loadComponent: () => import('./feature/game/blackjack/blackjack.component'),
canActivate: [authGuard],
},
{
path: 'coinflip',
loadComponent: () => import('./feature/game/coinflip/coinflip.component'),
canActivate: [authGuard],
},
{
path: 'slots',
loadComponent: () => import('./feature/game/slots/slots.component'),
canActivate: [authGuard],
},
{
path: 'lootboxes',
loadComponent: () =>
import('./feature/lootboxes/lootbox-selection/lootbox-selection.component'),
canActivate: [authGuard],
children: [
{
path: 'open/:id',
loadComponent: () =>
import('./feature/lootboxes/lootbox-opening/lootbox-opening.component'),
canActivate: [authGuard],
},
],
},
{
path: 'dice',
loadComponent: () => import('./feature/game/dice/dice.component'),
canActivate: [authGuard],
},
],
},
];

View file

@ -89,7 +89,7 @@
<div class="flex-grow h-px bg-deep-blue-light/30"></div>
</div>
<div class="mb-4">
<div class="space-y-3 mb-4">
<button
(click)="loginWithGithub()"
class="w-full py-2.5 px-4 rounded flex items-center justify-center bg-gray-800 hover:bg-gray-700 text-white transition-colors"
@ -106,6 +106,31 @@
</svg>
Mit GitHub anmelden
</button>
<button
(click)="loginWithGoogle()"
class="w-full py-2.5 px-4 rounded flex items-center justify-center bg-white hover:bg-gray-100 transition-colors !text-black"
>
<svg class="h-5 w-5 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
fill="#EA4335"
d="M5.266 9.765A7.077 7.077 0 0 1 12 4.909c1.69 0 3.218.6 4.418 1.582L19.91 3C17.782 1.145 15.055 0 12 0 7.27 0 3.198 2.698 1.24 6.65l4.026 3.115Z"
/>
<path
fill="#34A853"
d="M16.04 18.013c-1.09.703-2.474 1.078-4.04 1.078a7.077 7.077 0 0 1-6.723-4.823l-4.04 3.067A11.965 11.965 0 0 0 12 24c2.933 0 5.735-1.043 7.834-3l-3.793-2.987Z"
/>
<path
fill="#4A90E2"
d="M19.834 21c2.195-2.048 3.62-5.096 3.62-9 0-.71-.109-1.473-.272-2.182H12v4.637h6.436c-.317 1.559-1.17 2.766-2.395 3.558L19.834 21Z"
/>
<path
fill="#FBBC05"
d="M5.277 14.268A7.12 7.12 0 0 1 4.909 12c0-.782.125-1.533.357-2.235L1.24 6.65A11.934 11.934 0 0 0 0 12c0 1.92.445 3.73 1.237 5.335l4.04-3.067Z"
/>
</svg>
Mit Google anmelden
</button>
</div>
<div class="text-center">

View file

@ -71,6 +71,11 @@ export class LoginComponent {
window.location.href = `${environment.apiUrl}/oauth2/github/authorize`;
}
loginWithGoogle(): void {
this.isLoading.set(true);
window.location.href = `${environment.apiUrl}/oauth2/google/authorize`;
}
switchToForgotPassword() {
this.forgotPassword.emit();
}

View file

@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Component, computed, inject, OnInit, Signal } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
import { AuthService } from '@service/auth.service';
import { Oauth2Service } from './oauth2.service';
@Component({
selector: 'app-oauth2-callback',
@ -10,51 +10,34 @@ import { AuthService } from '@service/auth.service';
template: `
<div class="min-h-screen bg-deep-blue flex items-center justify-center">
<div class="text-center">
<h2 class="text-2xl font-bold text-white mb-4">Finishing authentication...</h2>
<h2 class="text-2xl font-bold text-white mb-4">Authentifizierung...</h2>
<div
class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-emerald mx-auto"
></div>
<p *ngIf="error" class="mt-4 text-accent-red">{{ error }}</p>
<p *ngIf="error()" class="mt-4 text-accent-red">{{ error() }}</p>
</div>
</div>
`,
})
export class OAuth2CallbackComponent implements OnInit {
error: string | null = null;
export default class OAuth2CallbackComponent implements OnInit {
error: Signal<string> = computed(() => this.oauthService.error());
constructor(
private route: ActivatedRoute,
private router: Router,
private authService: AuthService
) {}
private route: ActivatedRoute = inject(ActivatedRoute);
private router: Router = inject(Router);
private oauthService: Oauth2Service = inject(Oauth2Service);
ngOnInit(): void {
// Check for code in URL params
this.route.queryParams.subscribe((params) => {
const code = params['code'];
const provider = this.route.snapshot.data['provider'] || 'github';
if (code) {
// Exchange GitHub code for a JWT token
this.authService.githubAuth(code).subscribe({
next: () => {
// Redirect to home after successful authentication
this.router.navigate(['/home']);
},
error: (err) => {
console.error('GitHub authentication error:', err);
this.error = err.error?.message || 'Authentication failed. Please try again.';
console.log('Error details:', err);
// Redirect back to landing page after showing error
setTimeout(() => {
this.router.navigate(['/']);
}, 3000);
},
});
this.oauthService.oauth(provider, code);
} else {
this.error = 'Authentication failed. No authorization code received.';
this.oauthService.error.set(
'Authentifizierung fehlgeschlagen. Bitte versuchen Sie es erneut.'
);
// Redirect back to landing page after showing error
setTimeout(() => {
this.router.navigate(['/']);
}, 3000);

View file

@ -0,0 +1,36 @@
import { inject, Injectable, signal } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '@service/auth.service';
@Injectable({
providedIn: 'root',
})
export class Oauth2Service {
private router: Router = inject(Router);
private authService: AuthService = inject(AuthService);
private _error = signal<string>('');
oauth(provider: string, code: string) {
const oauth$ =
provider === 'github' ? this.authService.githubAuth(code) : this.authService.googleAuth(code);
oauth$.subscribe({
next: () => {
this.router.navigate(['/home']);
},
error: (err) => {
this._error.set(
err.error?.message || 'Authentifizierung fehlgeschlagen. Bitte versuchen Sie es erneut.'
);
setTimeout(() => {
this.router.navigate(['/']);
}, 3000);
},
});
}
public get error() {
return this._error;
}
}

View file

@ -10,7 +10,7 @@ import { AuthService } from '@service/auth.service';
imports: [CommonModule, ReactiveFormsModule, RouterModule],
templateUrl: './recover-password.component.html',
})
export class RecoverPasswordComponent implements OnInit {
export default class RecoverPasswordComponent implements OnInit {
emailForm: FormGroup;
resetPasswordForm: FormGroup;
errorMessage = signal('');

View file

@ -7,7 +7,7 @@ import { AuthService } from '@service/auth.service';
imports: [],
templateUrl: './verify-email.component.html',
})
export class VerifyEmailComponent implements OnInit {
export default class VerifyEmailComponent implements OnInit {
route: ActivatedRoute = inject(ActivatedRoute);
router: Router = inject(Router);
authService: AuthService = inject(AuthService);

View file

@ -5,13 +5,11 @@
@if (gameResult()) {
<div class="mb-6 text-center result-text">
<h2 class="text-2xl font-bold mb-2" [class]="getResultClass()">
{{ gameResult()?.isWin ? 'You Won!' : 'You Lost' }}
{{ gameResult()?.isWin ? 'Du hast gewonnen!' : 'Du hast verloren' }}
</h2>
<p class="text-lg">
Coin landed on:
<span class="font-bold">{{
gameResult()?.coinSide === 'HEAD' ? 'HEAD' : 'TAILS'
}}</span>
Münze zeigt:
<span class="font-bold">{{ gameResult()?.coinSide === 'HEAD' ? 'KOPF' : 'ZAHL' }}</span>
</p>
@if (gameResult()?.isWin) {
<p class="text-xl mt-2">
@ -35,7 +33,7 @@
<div
class="front coin-side bg-yellow-500 flex items-center justify-center text-2xl font-bold"
>
<div class="coin-text">HEAD</div>
<div class="coin-text">KOPF</div>
</div>
<!-- Tails side with non-mirrored text -->
@ -43,7 +41,7 @@
class="back coin-side bg-gray-700 flex items-center justify-center text-2xl font-bold text-white"
>
<!-- Using direct inline transform to counter the mirroring effect -->
<span style="display: inline-block; transform: scaleX(1)">TAILS</span>
<span style="display: inline-block; transform: scaleX(1)">ZAHL</span>
</div>
</div>
</div>
@ -56,7 +54,7 @@
class="button-primary py-3 px-6 relative text-lg"
[class.opacity-50]="gameInProgress()"
>
Bet TAILS
Auf ZAHL setzen
</button>
<button
(click)="betHeads()"
@ -64,7 +62,7 @@
class="button-primary py-3 px-6 relative text-lg"
[class.opacity-50]="gameInProgress()"
>
Bet HEAD
Auf KOPF setzen
</button>
</div>
</div>
@ -72,11 +70,11 @@
<!-- Game information panel -->
<div class="col-span-1">
<div class="card p-4">
<h3 class="section-heading text-xl mb-4">Game Information</h3>
<h3 class="section-heading text-xl mb-4">Spielinformationen</h3>
<div class="space-y-4">
<!-- Current bet display -->
<div class="flex justify-between items-center">
<span class="text-text-secondary">Current Bet:</span>
<span class="text-text-secondary">Aktueller Einsatz:</span>
<span [class]="currentBet() > 0 ? 'text-accent-red' : 'text-text-secondary'">
<app-animated-number [value]="currentBet()" [duration]="0.5"></app-animated-number>
</span>
@ -84,7 +82,7 @@
<!-- Available balance -->
<div class="flex justify-between items-center">
<span class="text-text-secondary">Your Balance:</span>
<span class="text-text-secondary">Dein Guthaben:</span>
<span class="text-white">
{{ balance() | currency: 'EUR' }}
</span>
@ -103,9 +101,9 @@
<!-- Custom bet input -->
<div class="space-y-1">
<div class="flex justify-between">
<label for="bet" class="text-sm text-text-secondary">Bet Amount</label>
<label for="bet" class="text-sm text-text-secondary">Einsatzbetrag</label>
<span *ngIf="isInvalidBet()" class="text-xs text-accent-red animate-pulse"
>Cannot exceed balance</span
>Darf Guthaben nicht überschreiten</span
>
</div>
<input
@ -129,11 +127,11 @@
<!-- Rules/info section -->
<div class="mt-6 pt-4 border-t border-gray-700">
<h4 class="text-lg font-semibold mb-2">How to Play</h4>
<h4 class="text-lg font-semibold mb-2">Spielregeln</h4>
<ul class="text-sm text-text-secondary space-y-1">
<li>Choose your bet amount</li>
<li>Select Heads or Tails</li>
<li>Win double your bet if correct</li>
<li>Wähle deinen Einsatzbetrag</li>
<li>Wähle Kopf oder Zahl</li>
<li>Gewinne das Doppelte deines Einsatzes bei richtiger Wahl</li>
</ul>
</div>
</div>

View file

@ -44,14 +44,14 @@ export default class CoinflipComponent implements OnInit {
private coinflipSound?: HTMLAudioElement;
ngOnInit(): void {
// Subscribe to user updates for real-time balance changes
// Abonniere Benutzerupdates für Echtzeitaktualisierungen des Guthabens
this.authService.userSubject.subscribe((user) => {
if (user) {
this.balance.set(user.balance);
}
});
// Initialize coinflip sound
// Initialisiere Münzwurf-Sound
this.coinflipSound = new Audio('/sounds/coinflip.mp3');
}
@ -65,26 +65,26 @@ export default class CoinflipComponent implements OnInit {
const inputElement = event.target as HTMLInputElement;
let value = Number(inputElement.value);
// Reset invalid bet state
// Setze ungültigen Einsatz-Status zurück
this.isInvalidBet.set(false);
// Enforce minimum bet of 1
// Erzwinge Mindesteinsatz von 1
if (value <= 0) {
value = 1;
}
// Cap bet at available balance and show feedback
// Begrenze Einsatz auf verfügbares Guthaben und zeige Feedback
if (value > this.balance()) {
value = this.balance();
// Show visual feedback
// Visuelles Feedback anzeigen
this.isInvalidBet.set(true);
// Indicate the error briefly
// Zeige den Fehler kurz an
setTimeout(() => this.isInvalidBet.set(false), 800);
// Update the input field directly to show the user the max value
// Aktualisiere das Eingabefeld direkt, um dem Benutzer den maximalen Wert anzuzeigen
inputElement.value = String(value);
}
// Update signals
// Aktualisiere Signale
this.betInputValue.set(value);
this.currentBet.set(value);
}
@ -100,34 +100,34 @@ export default class CoinflipComponent implements OnInit {
private placeBet(side: 'HEAD' | 'TAILS') {
if (this.gameInProgress() || this.isActionInProgress()) return;
// Reset previous result
// Setze vorheriges Ergebnis zurück
this.gameResult.set(null);
this.errorMessage.set('');
// Set game state
// Setze Spielstatus
this.gameInProgress.set(true);
this.isActionInProgress.set(true);
// Play bet sound
// Spiele Einsatz-Sound
this.audioService.playBetSound();
// Create bet request
// Erstelle Einsatz-Anfrage
const request: CoinflipRequest = {
betAmount: this.currentBet(),
coinSide: side,
};
// Call API
// API aufrufen
this.http
.post<CoinflipGame>('/backend/coinflip', request)
.pipe(
catchError((error) => {
console.error('Error playing coinflip:', error);
console.error('Fehler beim Spielen von Coinflip:', error);
if (error.status === 400 && error.error.message.includes('insufficient')) {
this.errorMessage.set('Insufficient funds');
this.errorMessage.set('Unzureichendes Guthaben');
} else {
this.errorMessage.set('An error occurred. Please try again.');
this.errorMessage.set('Ein Fehler ist aufgetreten. Bitte versuche es erneut.');
}
this.gameInProgress.set(false);
@ -140,37 +140,37 @@ export default class CoinflipComponent implements OnInit {
.subscribe((result) => {
if (!result) return;
console.log('API response:', result);
console.log('API-Antwort:', result);
// Fix potential property naming inconsistency from the backend
// Behebe mögliche Inkonsistenzen bei der Eigenschaftenbenennung vom Backend
const fixedResult: CoinflipGame = {
isWin: result.isWin ?? result.win,
payout: result.payout,
coinSide: result.coinSide,
};
console.log('Fixed result:', fixedResult);
console.log('Korrigiertes Ergebnis:', fixedResult);
// Play coin flip animation and sound
// Spiele Münzwurf-Animation und -Sound
this.playCoinFlipAnimation(fixedResult.coinSide);
// Set result after animation completes
// Setze Ergebnis nach Abschluss der Animation
setTimeout(() => {
this.gameResult.set(fixedResult);
// Update balance with new value from auth service
// Aktualisiere Guthaben mit neuem Wert vom Auth-Service
this.authService.loadCurrentUser();
// Play win sound if player won
// Spiele Gewinn-Sound, wenn der Spieler gewonnen hat
if (fixedResult.isWin) {
this.audioService.playWinSound();
}
// Reset game state after showing result
// Setze Spielstatus nach Anzeigen des Ergebnisses zurück
setTimeout(() => {
this.gameInProgress.set(false);
}, 1500);
}, 1100); // Just after animation ends
}, 1100); // Kurz nach Ende der Animation
});
}
@ -179,48 +179,50 @@ export default class CoinflipComponent implements OnInit {
const coinEl = this.coinElement.nativeElement;
// Reset any existing animations
// Setze bestehende Animationen zurück
coinEl.classList.remove('animate-to-heads', 'animate-to-tails');
// Reset any inline styles from previous animations
// Setze alle Inline-Styles von vorherigen Animationen zurück
coinEl.style.transform = '';
// Force a reflow to restart animation
// Erzwinge Reflow, um Animation neu zu starten
void coinEl.offsetWidth;
// Play flip sound
// Spiele Münzwurf-Sound
if (this.coinflipSound) {
this.coinflipSound.currentTime = 0;
this.coinflipSound.play().catch((err) => console.error('Error playing sound:', err));
this.coinflipSound
.play()
.catch((err) => console.error('Fehler beim Abspielen des Sounds:', err));
}
// Add appropriate animation class based on result
// Füge passende Animationsklasse basierend auf dem Ergebnis hinzu
if (result === 'HEAD') {
coinEl.classList.add('animate-to-heads');
} else {
coinEl.classList.add('animate-to-tails');
}
console.log(`Animation applied for result: ${result}`);
console.log(`Animation angewendet für Ergebnis: ${result}`);
}
/**
* Validates input as the user types to prevent invalid values
* Validiert Eingabe während der Benutzer tippt, um ungültige Werte zu verhindern
*/
validateBetInput(event: KeyboardEvent) {
// Allow navigation keys (arrows, delete, backspace, tab)
// Erlaube Navigationstasten (Pfeile, Entf, Rücktaste, Tab)
const navigationKeys = ['ArrowLeft', 'ArrowRight', 'Delete', 'Backspace', 'Tab'];
if (navigationKeys.includes(event.key)) {
return;
}
// Only allow numbers
// Erlaube nur Zahlen
if (!/^\d$/.test(event.key)) {
event.preventDefault();
return;
}
// Get the value that would result after the keypress
// Ermittle den Wert, der nach dem Tastendruck entstehen würde
const input = event.target as HTMLInputElement;
const currentValue = input.value;
const cursorPosition = input.selectionStart || 0;
@ -230,14 +232,14 @@ export default class CoinflipComponent implements OnInit {
currentValue.substring(input.selectionEnd || cursorPosition);
const numValue = Number(newValue);
// Prevent values greater than balance
// Verhindere Werte, die größer als das Guthaben sind
if (numValue > this.balance()) {
event.preventDefault();
}
}
// We removed the paste handler for simplicity since the updateBet method
// will handle any value that gets into the input field
// Der Paste-Handler wurde der Einfachheit halber entfernt, da die updateBet-Methode
// jeden Wert behandelt, der in das Eingabefeld gelangt
getResultClass() {
if (!this.gameResult()) return '';

View file

@ -27,7 +27,7 @@ type DiceFormGroup = FormGroup<{
imports: [CommonModule, ReactiveFormsModule, PlaySoundDirective, DragSoundDirective],
templateUrl: './dice.component.html',
})
export class DiceComponent implements OnInit {
export default class DiceComponent implements OnInit {
private readonly formBuilder = inject(FormBuilder);
private readonly diceService = inject(DiceService);
private readonly userService = inject(UserService);

View file

@ -11,7 +11,8 @@ import { ActivatedRoute, RouterLink } from '@angular/router';
import { AuthService } from '@service/auth.service';
import { LoginComponent } from '../auth/login/login.component';
import { RegisterComponent } from '../auth/register/register.component';
import { RecoverPasswordComponent } from '../auth/recover-password/recover-password.component';
import '../auth/recover-password/recover-password.component';
import RecoverPasswordComponent from '../auth/recover-password/recover-password.component';
@Component({
selector: 'app-landing-page',

View file

@ -79,6 +79,15 @@ export class AuthService {
);
}
googleAuth(code: string): Observable<AuthResponse> {
return this.http.post<AuthResponse>(`${this.oauthUrl}/google/callback`, { code }).pipe(
tap((response) => {
this.setToken(response.token);
this.loadCurrentUser();
})
);
}
logout(): void {
localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY);