Compare commits
No commits in common. "ed252696c468a1eb5fab4ee780d4cd415223876e" and "a1997537eb268978caf3dada7dcab25171a97d09" have entirely different histories.
ed252696c4
...
a1997537eb
25 changed files with 154 additions and 479 deletions
|
@ -1,6 +1,7 @@
|
||||||
package de.szut.casino.security.oauth2.github;
|
package de.szut.casino.security;
|
||||||
|
|
||||||
import de.szut.casino.security.dto.AuthResponseDto;
|
import de.szut.casino.security.dto.AuthResponseDto;
|
||||||
|
import de.szut.casino.security.dto.GithubCallbackDto;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@ -1,10 +1,12 @@
|
||||||
package de.szut.casino.security.oauth2.github;
|
package de.szut.casino.security;
|
||||||
|
|
||||||
import de.szut.casino.security.dto.AuthResponseDto;
|
import de.szut.casino.security.dto.AuthResponseDto;
|
||||||
import de.szut.casino.security.jwt.JwtUtils;
|
import de.szut.casino.security.jwt.JwtUtils;
|
||||||
import de.szut.casino.user.AuthProvider;
|
import de.szut.casino.user.AuthProvider;
|
||||||
import de.szut.casino.user.UserEntity;
|
import de.szut.casino.user.UserEntity;
|
||||||
import de.szut.casino.user.UserRepository;
|
import de.szut.casino.user.UserRepository;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpEntity;
|
import org.springframework.http.HttpEntity;
|
|
@ -1,4 +1,4 @@
|
||||||
package de.szut.casino.security.oauth2.github;
|
package de.szut.casino.security.dto;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
package de.szut.casino.security.oauth2.github;
|
package de.szut.casino.security.oauth2;
|
||||||
|
|
||||||
import de.szut.casino.security.oauth2.OAuth2UserInfo;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package de.szut.casino.security.oauth2;
|
package de.szut.casino.security.oauth2;
|
||||||
|
|
||||||
import de.szut.casino.exceptionHandling.exceptions.OAuth2AuthenticationProcessingException;
|
import de.szut.casino.exceptionHandling.exceptions.OAuth2AuthenticationProcessingException;
|
||||||
import de.szut.casino.security.oauth2.github.GitHubOAuth2UserInfo;
|
|
||||||
import de.szut.casino.security.oauth2.google.GoogleOAuth2UserInfo;
|
|
||||||
import de.szut.casino.user.AuthProvider;
|
import de.szut.casino.user.AuthProvider;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -12,8 +10,6 @@ public class OAuth2UserInfoFactory {
|
||||||
public static OAuth2UserInfo getOAuth2UserInfo(String registrationId, Map<String, Object> attributes) {
|
public static OAuth2UserInfo getOAuth2UserInfo(String registrationId, Map<String, Object> attributes) {
|
||||||
if (registrationId.equalsIgnoreCase(AuthProvider.GITHUB.toString())) {
|
if (registrationId.equalsIgnoreCase(AuthProvider.GITHUB.toString())) {
|
||||||
return new GitHubOAuth2UserInfo(attributes);
|
return new GitHubOAuth2UserInfo(attributes);
|
||||||
} else if (registrationId.equalsIgnoreCase(AuthProvider.GOOGLE.toString())) {
|
|
||||||
return new GoogleOAuth2UserInfo(attributes);
|
|
||||||
} else {
|
} else {
|
||||||
throw new OAuth2AuthenticationProcessingException("Sorry! Login with " + registrationId + " is not supported yet.");
|
throw new OAuth2AuthenticationProcessingException("Sorry! Login with " + registrationId + " is not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
package de.szut.casino.security.oauth2.google;
|
|
||||||
|
|
||||||
import de.szut.casino.security.dto.AuthResponseDto;
|
|
||||||
import de.szut.casino.security.oauth2.github.GithubCallbackDto;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
import org.springframework.web.servlet.view.RedirectView;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/oauth2/google")
|
|
||||||
public class GoogleController {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GoogleController.class);
|
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.client.registration.google.client-id}")
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.client.provider.google.authorization-uri}")
|
|
||||||
private String authorizationUri;
|
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.client.registration.google.redirect-uri}")
|
|
||||||
private String redirectUri;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private GoogleService googleService;
|
|
||||||
|
|
||||||
@GetMapping("/authorize")
|
|
||||||
public RedirectView authorizeGoogle() {
|
|
||||||
logger.info("Redirecting to Google for authorization");
|
|
||||||
|
|
||||||
String authUrl = authorizationUri +
|
|
||||||
"?client_id=" + clientId +
|
|
||||||
"&redirect_uri=" + redirectUri +
|
|
||||||
"&response_type=code" +
|
|
||||||
"&scope=email profile";
|
|
||||||
|
|
||||||
return new RedirectView(authUrl);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/callback")
|
|
||||||
public ResponseEntity<AuthResponseDto> googleCallback(@RequestBody GithubCallbackDto callbackDto) {
|
|
||||||
String code = callbackDto.getCode();
|
|
||||||
AuthResponseDto response = googleService.processGoogleCode(code);
|
|
||||||
return ResponseEntity.ok(response);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package de.szut.casino.security.oauth2.google;
|
|
||||||
|
|
||||||
import de.szut.casino.security.oauth2.OAuth2UserInfo;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class GoogleOAuth2UserInfo extends OAuth2UserInfo {
|
|
||||||
|
|
||||||
public GoogleOAuth2UserInfo(Map<String, Object> attributes) {
|
|
||||||
super(attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getId() {
|
|
||||||
return (String) attributes.get("sub");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return (String) attributes.get("name");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getEmail() {
|
|
||||||
return (String) attributes.get("email");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,164 +0,0 @@
|
||||||
package de.szut.casino.security.oauth2.google;
|
|
||||||
|
|
||||||
import de.szut.casino.security.dto.AuthResponseDto;
|
|
||||||
import de.szut.casino.security.jwt.JwtUtils;
|
|
||||||
import de.szut.casino.user.AuthProvider;
|
|
||||||
import de.szut.casino.user.UserEntity;
|
|
||||||
import de.szut.casino.user.UserRepository;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
|
||||||
import org.springframework.http.HttpEntity;
|
|
||||||
import org.springframework.http.HttpHeaders;
|
|
||||||
import org.springframework.http.HttpMethod;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
|
||||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
|
||||||
import org.springframework.util.MultiValueMap;
|
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class GoogleService {
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GoogleService.class);
|
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.client.registration.google.client-id}")
|
|
||||||
private String clientId;
|
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.client.registration.google.client-secret}")
|
|
||||||
private String clientSecret;
|
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.client.registration.google.redirect-uri}")
|
|
||||||
private String redirectUri;
|
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.client.provider.google.token-uri}")
|
|
||||||
private String tokenUri;
|
|
||||||
|
|
||||||
@Value("${spring.security.oauth2.client.provider.google.user-info-uri}")
|
|
||||||
private String userInfoUri;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AuthenticationManager authenticationManager;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private UserRepository userRepository;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private JwtUtils jwtUtils;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PasswordEncoder oauth2PasswordEncoder;
|
|
||||||
|
|
||||||
public AuthResponseDto processGoogleCode(String code) {
|
|
||||||
try {
|
|
||||||
RestTemplate restTemplate = new RestTemplate();
|
|
||||||
|
|
||||||
HttpHeaders tokenHeaders = new HttpHeaders();
|
|
||||||
tokenHeaders.set("Content-Type", "application/x-www-form-urlencoded");
|
|
||||||
|
|
||||||
MultiValueMap<String, String> tokenRequestBody = new LinkedMultiValueMap<>();
|
|
||||||
tokenRequestBody.add("client_id", clientId);
|
|
||||||
tokenRequestBody.add("client_secret", clientSecret);
|
|
||||||
tokenRequestBody.add("code", code);
|
|
||||||
tokenRequestBody.add("redirect_uri", redirectUri);
|
|
||||||
tokenRequestBody.add("grant_type", "authorization_code");
|
|
||||||
|
|
||||||
HttpEntity<MultiValueMap<String, String>> tokenRequestEntity = new HttpEntity<>(tokenRequestBody, tokenHeaders);
|
|
||||||
|
|
||||||
ResponseEntity<Map> tokenResponse = restTemplate.exchange(
|
|
||||||
tokenUri,
|
|
||||||
HttpMethod.POST,
|
|
||||||
tokenRequestEntity,
|
|
||||||
Map.class
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, Object> tokenResponseBody = tokenResponse.getBody();
|
|
||||||
|
|
||||||
if (tokenResponseBody == null || tokenResponseBody.containsKey("error")) {
|
|
||||||
String error = tokenResponseBody != null ? (String) tokenResponseBody.get("error") : "Unknown error";
|
|
||||||
throw new RuntimeException("Google OAuth error: " + error);
|
|
||||||
}
|
|
||||||
|
|
||||||
String accessToken = (String) tokenResponseBody.get("access_token");
|
|
||||||
if (accessToken == null || accessToken.isEmpty()) {
|
|
||||||
throw new RuntimeException("Failed to receive access token from Google");
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpHeaders userInfoHeaders = new HttpHeaders();
|
|
||||||
userInfoHeaders.set("Authorization", "Bearer " + accessToken);
|
|
||||||
|
|
||||||
HttpEntity<String> userInfoRequestEntity = new HttpEntity<>(null, userInfoHeaders);
|
|
||||||
|
|
||||||
ResponseEntity<Map> userResponse = restTemplate.exchange(
|
|
||||||
userInfoUri,
|
|
||||||
HttpMethod.GET,
|
|
||||||
userInfoRequestEntity,
|
|
||||||
Map.class
|
|
||||||
);
|
|
||||||
|
|
||||||
Map<String, Object> userAttributes = userResponse.getBody();
|
|
||||||
if (userAttributes == null) {
|
|
||||||
throw new RuntimeException("Failed to fetch user data from Google");
|
|
||||||
}
|
|
||||||
|
|
||||||
String googleId = (String) userAttributes.get("sub");
|
|
||||||
String email = (String) userAttributes.get("email");
|
|
||||||
String name = (String) userAttributes.get("name");
|
|
||||||
Boolean emailVerified = (Boolean) userAttributes.getOrDefault("email_verified", false);
|
|
||||||
|
|
||||||
if (email == null) {
|
|
||||||
throw new RuntimeException("Google account does not have an email");
|
|
||||||
}
|
|
||||||
|
|
||||||
String username = name != null ? name.replaceAll("\\s+", "") : email.split("@")[0];
|
|
||||||
|
|
||||||
Optional<UserEntity> userOptional = userRepository.findByProviderId(googleId);
|
|
||||||
UserEntity user;
|
|
||||||
|
|
||||||
if (userOptional.isPresent()) {
|
|
||||||
user = userOptional.get();
|
|
||||||
} else {
|
|
||||||
userOptional = userRepository.findByEmail(email);
|
|
||||||
|
|
||||||
if (userOptional.isPresent()) {
|
|
||||||
user = userOptional.get();
|
|
||||||
user.setProvider(AuthProvider.GOOGLE);
|
|
||||||
user.setProviderId(googleId);
|
|
||||||
} else {
|
|
||||||
user = new UserEntity();
|
|
||||||
user.setEmail(email);
|
|
||||||
user.setUsername(username);
|
|
||||||
user.setProvider(AuthProvider.GOOGLE);
|
|
||||||
user.setProviderId(googleId);
|
|
||||||
user.setEmailVerified(emailVerified);
|
|
||||||
|
|
||||||
user.setBalance(new BigDecimal("100.00"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String randomPassword = UUID.randomUUID().toString();
|
|
||||||
user.setPassword(oauth2PasswordEncoder.encode(randomPassword));
|
|
||||||
|
|
||||||
userRepository.save(user);
|
|
||||||
|
|
||||||
Authentication authentication = authenticationManager.authenticate(
|
|
||||||
new UsernamePasswordAuthenticationToken(user.getEmail(), randomPassword)
|
|
||||||
);
|
|
||||||
|
|
||||||
String token = jwtUtils.generateToken(authentication);
|
|
||||||
|
|
||||||
return new AuthResponseDto(token);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("Failed to process Google authentication", e);
|
|
||||||
throw new RuntimeException("Failed to process Google authentication", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,7 +28,6 @@ public class EmailService {
|
||||||
this.mailConfig = mailConfig;
|
this.mailConfig = mailConfig;
|
||||||
this.mailSender.setHost(mailConfig.host);
|
this.mailSender.setHost(mailConfig.host);
|
||||||
this.mailSender.setPort(mailConfig.port);
|
this.mailSender.setPort(mailConfig.port);
|
||||||
this.mailSender.setProtocol(mailConfig.protocol);
|
|
||||||
if (mailConfig.authenticationEnabled) {
|
if (mailConfig.authenticationEnabled) {
|
||||||
this.mailSender.setUsername(mailConfig.username);
|
this.mailSender.setUsername(mailConfig.username);
|
||||||
this.mailSender.setPassword(mailConfig.password);
|
this.mailSender.setPassword(mailConfig.password);
|
||||||
|
|
|
@ -22,7 +22,4 @@ public class MailConfig {
|
||||||
|
|
||||||
@Value("${app.mail.from-address}")
|
@Value("${app.mail.from-address}")
|
||||||
public String fromAddress;
|
public String fromAddress;
|
||||||
|
|
||||||
@Value("${app.mail.protocol}")
|
|
||||||
public String protocol;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,5 @@ package de.szut.casino.user;
|
||||||
|
|
||||||
public enum AuthProvider {
|
public enum AuthProvider {
|
||||||
LOCAL,
|
LOCAL,
|
||||||
GITHUB,
|
GITHUB
|
||||||
GOOGLE
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,6 @@ app.mail.port=${MAIL_PORT:1025}
|
||||||
app.mail.username=${MAIL_USER:null}
|
app.mail.username=${MAIL_USER:null}
|
||||||
app.mail.password=${MAIL_PASS:null}
|
app.mail.password=${MAIL_PASS:null}
|
||||||
app.mail.from-address=${MAIL_FROM:casino@localhost}
|
app.mail.from-address=${MAIL_FROM:casino@localhost}
|
||||||
app.mail.protocol=${MAIL_PROTOCOL:smtp}
|
|
||||||
|
|
||||||
spring.application.name=casino
|
spring.application.name=casino
|
||||||
|
|
||||||
|
@ -42,13 +41,3 @@ spring.security.oauth2.client.provider.github.user-name-attribute=login
|
||||||
# OAuth Success and Failure URLs
|
# OAuth Success and Failure URLs
|
||||||
app.oauth2.authorizedRedirectUris=${app.frontend-host}/auth/oauth2/callback
|
app.oauth2.authorizedRedirectUris=${app.frontend-host}/auth/oauth2/callback
|
||||||
|
|
||||||
# Google OAuth2 Configuration
|
|
||||||
spring.security.oauth2.client.registration.google.client-id=${GOOGLE_CLIENT_ID:350791038883-c1r7v4o793itq8a0rh7dut7itm7uneam.apps.googleusercontent.com}
|
|
||||||
spring.security.oauth2.client.registration.google.client-secret=${GOOGLE_CLIENT_SECRET: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}
|
|
||||||
spring.security.oauth2.client.registration.google.redirect-uri=${app.frontend-host}/oauth2/callback/google
|
|
||||||
spring.security.oauth2.client.registration.google.scope=email,profile
|
|
||||||
spring.security.oauth2.client.provider.google.authorization-uri=https://accounts.google.com/o/oauth2/v2/auth
|
|
||||||
spring.security.oauth2.client.provider.google.token-uri=https://oauth2.googleapis.com/token
|
|
||||||
spring.security.oauth2.client.provider.google.user-info-uri=https://www.googleapis.com/oauth2/v3/userinfo
|
|
||||||
spring.security.oauth2.client.provider.google.user-name-attribute=sub
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
import { Component, HostListener, inject, signal } from '@angular/core';
|
import { Component, HostListener, inject, signal } from '@angular/core';
|
||||||
import { RouterOutlet } from '@angular/router';
|
import { RouterOutlet } from '@angular/router';
|
||||||
import { NavbarComponent } from '@shared/components/navbar/navbar.component';
|
import { NavbarComponent } from './shared/components/navbar/navbar.component';
|
||||||
import { FooterComponent } from '@shared/components/footer/footer.component';
|
import { FooterComponent } from './shared/components/footer/footer.component';
|
||||||
import { LoginComponent } from './feature/auth/login/login.component';
|
import { LoginComponent } from './feature/auth/login/login.component';
|
||||||
import { RegisterComponent } from './feature/auth/register/register.component';
|
import { RegisterComponent } from './feature/auth/register/register.component';
|
||||||
import RecoverPasswordComponent from './feature/auth/recover-password/recover-password.component';
|
import { RecoverPasswordComponent } from './feature/auth/recover-password/recover-password.component';
|
||||||
import { PlaySoundDirective } from '@shared/directives/play-sound.directive';
|
import { PlaySoundDirective } from './shared/directives/play-sound.directive';
|
||||||
import { SoundInitializerService } from '@shared/services/sound-initializer.service';
|
import { SoundInitializerService } from './shared/services/sound-initializer.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-root',
|
selector: 'app-root',
|
||||||
|
|
|
@ -14,68 +14,61 @@ export const routes: Routes = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'verify',
|
path: 'verify',
|
||||||
loadComponent: () => import('./feature/auth/verify-email/verify-email.component'),
|
loadComponent: () =>
|
||||||
|
import('./feature/auth/verify-email/verify-email.component').then(
|
||||||
|
(m) => m.VerifyEmailComponent
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'recover-password',
|
path: 'recover-password',
|
||||||
loadComponent: () => import('./feature/auth/recover-password/recover-password.component'),
|
loadComponent: () =>
|
||||||
|
import('./feature/auth/recover-password/recover-password.component').then(
|
||||||
|
(m) => m.RecoverPasswordComponent
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'reset-password',
|
path: 'reset-password',
|
||||||
loadComponent: () => import('./feature/auth/recover-password/recover-password.component'),
|
loadComponent: () =>
|
||||||
|
import('./feature/auth/recover-password/recover-password.component').then(
|
||||||
|
(m) => m.RecoverPasswordComponent
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'oauth2/callback',
|
path: 'oauth2/callback/github',
|
||||||
children: [
|
loadComponent: () =>
|
||||||
{
|
import('./feature/auth/oauth2/oauth2-callback.component').then(
|
||||||
path: 'github',
|
(m) => m.OAuth2CallbackComponent
|
||||||
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',
|
path: 'game/blackjack',
|
||||||
children: [
|
loadComponent: () => import('./feature/game/blackjack/blackjack.component'),
|
||||||
{
|
canActivate: [authGuard],
|
||||||
path: 'blackjack',
|
},
|
||||||
loadComponent: () => import('./feature/game/blackjack/blackjack.component'),
|
{
|
||||||
canActivate: [authGuard],
|
path: 'game/coinflip',
|
||||||
},
|
loadComponent: () => import('./feature/game/coinflip/coinflip.component'),
|
||||||
{
|
canActivate: [authGuard],
|
||||||
path: 'coinflip',
|
},
|
||||||
loadComponent: () => import('./feature/game/coinflip/coinflip.component'),
|
{
|
||||||
canActivate: [authGuard],
|
path: 'game/slots',
|
||||||
},
|
loadComponent: () => import('./feature/game/slots/slots.component'),
|
||||||
{
|
canActivate: [authGuard],
|
||||||
path: 'slots',
|
},
|
||||||
loadComponent: () => import('./feature/game/slots/slots.component'),
|
{
|
||||||
canActivate: [authGuard],
|
path: 'game/lootboxes',
|
||||||
},
|
loadComponent: () =>
|
||||||
{
|
import('./feature/lootboxes/lootbox-selection/lootbox-selection.component'),
|
||||||
path: 'lootboxes',
|
canActivate: [authGuard],
|
||||||
loadComponent: () =>
|
},
|
||||||
import('./feature/lootboxes/lootbox-selection/lootbox-selection.component'),
|
{
|
||||||
canActivate: [authGuard],
|
path: 'game/lootboxes/open/:id',
|
||||||
children: [
|
loadComponent: () => import('./feature/lootboxes/lootbox-opening/lootbox-opening.component'),
|
||||||
{
|
canActivate: [authGuard],
|
||||||
path: 'open/:id',
|
},
|
||||||
loadComponent: () =>
|
{
|
||||||
import('./feature/lootboxes/lootbox-opening/lootbox-opening.component'),
|
path: 'game/dice',
|
||||||
canActivate: [authGuard],
|
loadComponent: () => import('./feature/game/dice/dice.component').then((m) => m.DiceComponent),
|
||||||
},
|
canActivate: [authGuard],
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'dice',
|
|
||||||
loadComponent: () => import('./feature/game/dice/dice.component'),
|
|
||||||
canActivate: [authGuard],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
<div class="flex-grow h-px bg-deep-blue-light/30"></div>
|
<div class="flex-grow h-px bg-deep-blue-light/30"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="space-y-3 mb-4">
|
<div class="mb-4">
|
||||||
<button
|
<button
|
||||||
(click)="loginWithGithub()"
|
(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"
|
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,31 +106,6 @@
|
||||||
</svg>
|
</svg>
|
||||||
Mit GitHub anmelden
|
Mit GitHub anmelden
|
||||||
</button>
|
</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>
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
|
|
|
@ -71,11 +71,6 @@ export class LoginComponent {
|
||||||
window.location.href = `${environment.apiUrl}/oauth2/github/authorize`;
|
window.location.href = `${environment.apiUrl}/oauth2/github/authorize`;
|
||||||
}
|
}
|
||||||
|
|
||||||
loginWithGoogle(): void {
|
|
||||||
this.isLoading.set(true);
|
|
||||||
window.location.href = `${environment.apiUrl}/oauth2/google/authorize`;
|
|
||||||
}
|
|
||||||
|
|
||||||
switchToForgotPassword() {
|
switchToForgotPassword() {
|
||||||
this.forgotPassword.emit();
|
this.forgotPassword.emit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Component, computed, inject, OnInit, Signal } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { Oauth2Service } from './oauth2.service';
|
import { AuthService } from '@service/auth.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-oauth2-callback',
|
selector: 'app-oauth2-callback',
|
||||||
|
@ -10,34 +10,51 @@ import { Oauth2Service } from './oauth2.service';
|
||||||
template: `
|
template: `
|
||||||
<div class="min-h-screen bg-deep-blue flex items-center justify-center">
|
<div class="min-h-screen bg-deep-blue flex items-center justify-center">
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2 class="text-2xl font-bold text-white mb-4">Authentifizierung...</h2>
|
<h2 class="text-2xl font-bold text-white mb-4">Finishing authentication...</h2>
|
||||||
<div
|
<div
|
||||||
class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-emerald mx-auto"
|
class="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-emerald mx-auto"
|
||||||
></div>
|
></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>
|
||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
export default class OAuth2CallbackComponent implements OnInit {
|
export class OAuth2CallbackComponent implements OnInit {
|
||||||
error: Signal<string> = computed(() => this.oauthService.error());
|
error: string | null = null;
|
||||||
|
|
||||||
private route: ActivatedRoute = inject(ActivatedRoute);
|
constructor(
|
||||||
private router: Router = inject(Router);
|
private route: ActivatedRoute,
|
||||||
private oauthService: Oauth2Service = inject(Oauth2Service);
|
private router: Router,
|
||||||
|
private authService: AuthService
|
||||||
|
) {}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
// Check for code in URL params
|
||||||
this.route.queryParams.subscribe((params) => {
|
this.route.queryParams.subscribe((params) => {
|
||||||
const code = params['code'];
|
const code = params['code'];
|
||||||
const provider = this.route.snapshot.data['provider'] || 'github';
|
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
this.oauthService.oauth(provider, code);
|
// Exchange GitHub code for a JWT token
|
||||||
} else {
|
this.authService.githubAuth(code).subscribe({
|
||||||
this.oauthService.error.set(
|
next: () => {
|
||||||
'Authentifizierung fehlgeschlagen. Bitte versuchen Sie es erneut.'
|
// 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);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.error = 'Authentication failed. No authorization code received.';
|
||||||
|
|
||||||
|
// Redirect back to landing page after showing error
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.router.navigate(['/']);
|
this.router.navigate(['/']);
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,7 +10,7 @@ import { AuthService } from '@service/auth.service';
|
||||||
imports: [CommonModule, ReactiveFormsModule, RouterModule],
|
imports: [CommonModule, ReactiveFormsModule, RouterModule],
|
||||||
templateUrl: './recover-password.component.html',
|
templateUrl: './recover-password.component.html',
|
||||||
})
|
})
|
||||||
export default class RecoverPasswordComponent implements OnInit {
|
export class RecoverPasswordComponent implements OnInit {
|
||||||
emailForm: FormGroup;
|
emailForm: FormGroup;
|
||||||
resetPasswordForm: FormGroup;
|
resetPasswordForm: FormGroup;
|
||||||
errorMessage = signal('');
|
errorMessage = signal('');
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { AuthService } from '@service/auth.service';
|
||||||
imports: [],
|
imports: [],
|
||||||
templateUrl: './verify-email.component.html',
|
templateUrl: './verify-email.component.html',
|
||||||
})
|
})
|
||||||
export default class VerifyEmailComponent implements OnInit {
|
export class VerifyEmailComponent implements OnInit {
|
||||||
route: ActivatedRoute = inject(ActivatedRoute);
|
route: ActivatedRoute = inject(ActivatedRoute);
|
||||||
router: Router = inject(Router);
|
router: Router = inject(Router);
|
||||||
authService: AuthService = inject(AuthService);
|
authService: AuthService = inject(AuthService);
|
||||||
|
|
|
@ -5,11 +5,13 @@
|
||||||
@if (gameResult()) {
|
@if (gameResult()) {
|
||||||
<div class="mb-6 text-center result-text">
|
<div class="mb-6 text-center result-text">
|
||||||
<h2 class="text-2xl font-bold mb-2" [class]="getResultClass()">
|
<h2 class="text-2xl font-bold mb-2" [class]="getResultClass()">
|
||||||
{{ gameResult()?.isWin ? 'Du hast gewonnen!' : 'Du hast verloren' }}
|
{{ gameResult()?.isWin ? 'You Won!' : 'You Lost' }}
|
||||||
</h2>
|
</h2>
|
||||||
<p class="text-lg">
|
<p class="text-lg">
|
||||||
Münze zeigt:
|
Coin landed on:
|
||||||
<span class="font-bold">{{ gameResult()?.coinSide === 'HEAD' ? 'KOPF' : 'ZAHL' }}</span>
|
<span class="font-bold">{{
|
||||||
|
gameResult()?.coinSide === 'HEAD' ? 'HEAD' : 'TAILS'
|
||||||
|
}}</span>
|
||||||
</p>
|
</p>
|
||||||
@if (gameResult()?.isWin) {
|
@if (gameResult()?.isWin) {
|
||||||
<p class="text-xl mt-2">
|
<p class="text-xl mt-2">
|
||||||
|
@ -33,7 +35,7 @@
|
||||||
<div
|
<div
|
||||||
class="front coin-side bg-yellow-500 flex items-center justify-center text-2xl font-bold"
|
class="front coin-side bg-yellow-500 flex items-center justify-center text-2xl font-bold"
|
||||||
>
|
>
|
||||||
<div class="coin-text">KOPF</div>
|
<div class="coin-text">HEAD</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Tails side with non-mirrored text -->
|
<!-- Tails side with non-mirrored text -->
|
||||||
|
@ -41,7 +43,7 @@
|
||||||
class="back coin-side bg-gray-700 flex items-center justify-center text-2xl font-bold text-white"
|
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 -->
|
<!-- Using direct inline transform to counter the mirroring effect -->
|
||||||
<span style="display: inline-block; transform: scaleX(1)">ZAHL</span>
|
<span style="display: inline-block; transform: scaleX(1)">TAILS</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -54,7 +56,7 @@
|
||||||
class="button-primary py-3 px-6 relative text-lg"
|
class="button-primary py-3 px-6 relative text-lg"
|
||||||
[class.opacity-50]="gameInProgress()"
|
[class.opacity-50]="gameInProgress()"
|
||||||
>
|
>
|
||||||
Auf ZAHL setzen
|
Bet TAILS
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
(click)="betHeads()"
|
(click)="betHeads()"
|
||||||
|
@ -62,7 +64,7 @@
|
||||||
class="button-primary py-3 px-6 relative text-lg"
|
class="button-primary py-3 px-6 relative text-lg"
|
||||||
[class.opacity-50]="gameInProgress()"
|
[class.opacity-50]="gameInProgress()"
|
||||||
>
|
>
|
||||||
Auf KOPF setzen
|
Bet HEAD
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -70,11 +72,11 @@
|
||||||
<!-- Game information panel -->
|
<!-- Game information panel -->
|
||||||
<div class="col-span-1">
|
<div class="col-span-1">
|
||||||
<div class="card p-4">
|
<div class="card p-4">
|
||||||
<h3 class="section-heading text-xl mb-4">Spielinformationen</h3>
|
<h3 class="section-heading text-xl mb-4">Game Information</h3>
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<!-- Current bet display -->
|
<!-- Current bet display -->
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<span class="text-text-secondary">Aktueller Einsatz:</span>
|
<span class="text-text-secondary">Current Bet:</span>
|
||||||
<span [class]="currentBet() > 0 ? 'text-accent-red' : 'text-text-secondary'">
|
<span [class]="currentBet() > 0 ? 'text-accent-red' : 'text-text-secondary'">
|
||||||
<app-animated-number [value]="currentBet()" [duration]="0.5"></app-animated-number> €
|
<app-animated-number [value]="currentBet()" [duration]="0.5"></app-animated-number> €
|
||||||
</span>
|
</span>
|
||||||
|
@ -82,7 +84,7 @@
|
||||||
|
|
||||||
<!-- Available balance -->
|
<!-- Available balance -->
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
<span class="text-text-secondary">Dein Guthaben:</span>
|
<span class="text-text-secondary">Your Balance:</span>
|
||||||
<span class="text-white">
|
<span class="text-white">
|
||||||
{{ balance() | currency: 'EUR' }}
|
{{ balance() | currency: 'EUR' }}
|
||||||
</span>
|
</span>
|
||||||
|
@ -101,9 +103,9 @@
|
||||||
<!-- Custom bet input -->
|
<!-- Custom bet input -->
|
||||||
<div class="space-y-1">
|
<div class="space-y-1">
|
||||||
<div class="flex justify-between">
|
<div class="flex justify-between">
|
||||||
<label for="bet" class="text-sm text-text-secondary">Einsatzbetrag</label>
|
<label for="bet" class="text-sm text-text-secondary">Bet Amount</label>
|
||||||
<span *ngIf="isInvalidBet()" class="text-xs text-accent-red animate-pulse"
|
<span *ngIf="isInvalidBet()" class="text-xs text-accent-red animate-pulse"
|
||||||
>Darf Guthaben nicht überschreiten</span
|
>Cannot exceed balance</span
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
<input
|
<input
|
||||||
|
@ -127,11 +129,11 @@
|
||||||
|
|
||||||
<!-- Rules/info section -->
|
<!-- Rules/info section -->
|
||||||
<div class="mt-6 pt-4 border-t border-gray-700">
|
<div class="mt-6 pt-4 border-t border-gray-700">
|
||||||
<h4 class="text-lg font-semibold mb-2">Spielregeln</h4>
|
<h4 class="text-lg font-semibold mb-2">How to Play</h4>
|
||||||
<ul class="text-sm text-text-secondary space-y-1">
|
<ul class="text-sm text-text-secondary space-y-1">
|
||||||
<li>• Wähle deinen Einsatzbetrag</li>
|
<li>• Choose your bet amount</li>
|
||||||
<li>• Wähle Kopf oder Zahl</li>
|
<li>• Select Heads or Tails</li>
|
||||||
<li>• Gewinne das Doppelte deines Einsatzes bei richtiger Wahl</li>
|
<li>• Win double your bet if correct</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -44,14 +44,14 @@ export default class CoinflipComponent implements OnInit {
|
||||||
private coinflipSound?: HTMLAudioElement;
|
private coinflipSound?: HTMLAudioElement;
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
// Abonniere Benutzerupdates für Echtzeitaktualisierungen des Guthabens
|
// Subscribe to user updates for real-time balance changes
|
||||||
this.authService.userSubject.subscribe((user) => {
|
this.authService.userSubject.subscribe((user) => {
|
||||||
if (user) {
|
if (user) {
|
||||||
this.balance.set(user.balance);
|
this.balance.set(user.balance);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialisiere Münzwurf-Sound
|
// Initialize coinflip sound
|
||||||
this.coinflipSound = new Audio('/sounds/coinflip.mp3');
|
this.coinflipSound = new Audio('/sounds/coinflip.mp3');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,26 +65,26 @@ export default class CoinflipComponent implements OnInit {
|
||||||
const inputElement = event.target as HTMLInputElement;
|
const inputElement = event.target as HTMLInputElement;
|
||||||
let value = Number(inputElement.value);
|
let value = Number(inputElement.value);
|
||||||
|
|
||||||
// Setze ungültigen Einsatz-Status zurück
|
// Reset invalid bet state
|
||||||
this.isInvalidBet.set(false);
|
this.isInvalidBet.set(false);
|
||||||
|
|
||||||
// Erzwinge Mindesteinsatz von 1
|
// Enforce minimum bet of 1
|
||||||
if (value <= 0) {
|
if (value <= 0) {
|
||||||
value = 1;
|
value = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Begrenze Einsatz auf verfügbares Guthaben und zeige Feedback
|
// Cap bet at available balance and show feedback
|
||||||
if (value > this.balance()) {
|
if (value > this.balance()) {
|
||||||
value = this.balance();
|
value = this.balance();
|
||||||
// Visuelles Feedback anzeigen
|
// Show visual feedback
|
||||||
this.isInvalidBet.set(true);
|
this.isInvalidBet.set(true);
|
||||||
// Zeige den Fehler kurz an
|
// Indicate the error briefly
|
||||||
setTimeout(() => this.isInvalidBet.set(false), 800);
|
setTimeout(() => this.isInvalidBet.set(false), 800);
|
||||||
// Aktualisiere das Eingabefeld direkt, um dem Benutzer den maximalen Wert anzuzeigen
|
// Update the input field directly to show the user the max value
|
||||||
inputElement.value = String(value);
|
inputElement.value = String(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Aktualisiere Signale
|
// Update signals
|
||||||
this.betInputValue.set(value);
|
this.betInputValue.set(value);
|
||||||
this.currentBet.set(value);
|
this.currentBet.set(value);
|
||||||
}
|
}
|
||||||
|
@ -100,34 +100,34 @@ export default class CoinflipComponent implements OnInit {
|
||||||
private placeBet(side: 'HEAD' | 'TAILS') {
|
private placeBet(side: 'HEAD' | 'TAILS') {
|
||||||
if (this.gameInProgress() || this.isActionInProgress()) return;
|
if (this.gameInProgress() || this.isActionInProgress()) return;
|
||||||
|
|
||||||
// Setze vorheriges Ergebnis zurück
|
// Reset previous result
|
||||||
this.gameResult.set(null);
|
this.gameResult.set(null);
|
||||||
this.errorMessage.set('');
|
this.errorMessage.set('');
|
||||||
|
|
||||||
// Setze Spielstatus
|
// Set game state
|
||||||
this.gameInProgress.set(true);
|
this.gameInProgress.set(true);
|
||||||
this.isActionInProgress.set(true);
|
this.isActionInProgress.set(true);
|
||||||
|
|
||||||
// Spiele Einsatz-Sound
|
// Play bet sound
|
||||||
this.audioService.playBetSound();
|
this.audioService.playBetSound();
|
||||||
|
|
||||||
// Erstelle Einsatz-Anfrage
|
// Create bet request
|
||||||
const request: CoinflipRequest = {
|
const request: CoinflipRequest = {
|
||||||
betAmount: this.currentBet(),
|
betAmount: this.currentBet(),
|
||||||
coinSide: side,
|
coinSide: side,
|
||||||
};
|
};
|
||||||
|
|
||||||
// API aufrufen
|
// Call API
|
||||||
this.http
|
this.http
|
||||||
.post<CoinflipGame>('/backend/coinflip', request)
|
.post<CoinflipGame>('/backend/coinflip', request)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError((error) => {
|
catchError((error) => {
|
||||||
console.error('Fehler beim Spielen von Coinflip:', error);
|
console.error('Error playing coinflip:', error);
|
||||||
|
|
||||||
if (error.status === 400 && error.error.message.includes('insufficient')) {
|
if (error.status === 400 && error.error.message.includes('insufficient')) {
|
||||||
this.errorMessage.set('Unzureichendes Guthaben');
|
this.errorMessage.set('Insufficient funds');
|
||||||
} else {
|
} else {
|
||||||
this.errorMessage.set('Ein Fehler ist aufgetreten. Bitte versuche es erneut.');
|
this.errorMessage.set('An error occurred. Please try again.');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gameInProgress.set(false);
|
this.gameInProgress.set(false);
|
||||||
|
@ -140,37 +140,37 @@ export default class CoinflipComponent implements OnInit {
|
||||||
.subscribe((result) => {
|
.subscribe((result) => {
|
||||||
if (!result) return;
|
if (!result) return;
|
||||||
|
|
||||||
console.log('API-Antwort:', result);
|
console.log('API response:', result);
|
||||||
|
|
||||||
// Behebe mögliche Inkonsistenzen bei der Eigenschaftenbenennung vom Backend
|
// Fix potential property naming inconsistency from the backend
|
||||||
const fixedResult: CoinflipGame = {
|
const fixedResult: CoinflipGame = {
|
||||||
isWin: result.isWin ?? result.win,
|
isWin: result.isWin ?? result.win,
|
||||||
payout: result.payout,
|
payout: result.payout,
|
||||||
coinSide: result.coinSide,
|
coinSide: result.coinSide,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('Korrigiertes Ergebnis:', fixedResult);
|
console.log('Fixed result:', fixedResult);
|
||||||
|
|
||||||
// Spiele Münzwurf-Animation und -Sound
|
// Play coin flip animation and sound
|
||||||
this.playCoinFlipAnimation(fixedResult.coinSide);
|
this.playCoinFlipAnimation(fixedResult.coinSide);
|
||||||
|
|
||||||
// Setze Ergebnis nach Abschluss der Animation
|
// Set result after animation completes
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.gameResult.set(fixedResult);
|
this.gameResult.set(fixedResult);
|
||||||
|
|
||||||
// Aktualisiere Guthaben mit neuem Wert vom Auth-Service
|
// Update balance with new value from auth service
|
||||||
this.authService.loadCurrentUser();
|
this.authService.loadCurrentUser();
|
||||||
|
|
||||||
// Spiele Gewinn-Sound, wenn der Spieler gewonnen hat
|
// Play win sound if player won
|
||||||
if (fixedResult.isWin) {
|
if (fixedResult.isWin) {
|
||||||
this.audioService.playWinSound();
|
this.audioService.playWinSound();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setze Spielstatus nach Anzeigen des Ergebnisses zurück
|
// Reset game state after showing result
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.gameInProgress.set(false);
|
this.gameInProgress.set(false);
|
||||||
}, 1500);
|
}, 1500);
|
||||||
}, 1100); // Kurz nach Ende der Animation
|
}, 1100); // Just after animation ends
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,50 +179,48 @@ export default class CoinflipComponent implements OnInit {
|
||||||
|
|
||||||
const coinEl = this.coinElement.nativeElement;
|
const coinEl = this.coinElement.nativeElement;
|
||||||
|
|
||||||
// Setze bestehende Animationen zurück
|
// Reset any existing animations
|
||||||
coinEl.classList.remove('animate-to-heads', 'animate-to-tails');
|
coinEl.classList.remove('animate-to-heads', 'animate-to-tails');
|
||||||
|
|
||||||
// Setze alle Inline-Styles von vorherigen Animationen zurück
|
// Reset any inline styles from previous animations
|
||||||
coinEl.style.transform = '';
|
coinEl.style.transform = '';
|
||||||
|
|
||||||
// Erzwinge Reflow, um Animation neu zu starten
|
// Force a reflow to restart animation
|
||||||
void coinEl.offsetWidth;
|
void coinEl.offsetWidth;
|
||||||
|
|
||||||
// Spiele Münzwurf-Sound
|
// Play flip sound
|
||||||
if (this.coinflipSound) {
|
if (this.coinflipSound) {
|
||||||
this.coinflipSound.currentTime = 0;
|
this.coinflipSound.currentTime = 0;
|
||||||
this.coinflipSound
|
this.coinflipSound.play().catch((err) => console.error('Error playing sound:', err));
|
||||||
.play()
|
|
||||||
.catch((err) => console.error('Fehler beim Abspielen des Sounds:', err));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Füge passende Animationsklasse basierend auf dem Ergebnis hinzu
|
// Add appropriate animation class based on result
|
||||||
if (result === 'HEAD') {
|
if (result === 'HEAD') {
|
||||||
coinEl.classList.add('animate-to-heads');
|
coinEl.classList.add('animate-to-heads');
|
||||||
} else {
|
} else {
|
||||||
coinEl.classList.add('animate-to-tails');
|
coinEl.classList.add('animate-to-tails');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Animation angewendet für Ergebnis: ${result}`);
|
console.log(`Animation applied for result: ${result}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validiert Eingabe während der Benutzer tippt, um ungültige Werte zu verhindern
|
* Validates input as the user types to prevent invalid values
|
||||||
*/
|
*/
|
||||||
validateBetInput(event: KeyboardEvent) {
|
validateBetInput(event: KeyboardEvent) {
|
||||||
// Erlaube Navigationstasten (Pfeile, Entf, Rücktaste, Tab)
|
// Allow navigation keys (arrows, delete, backspace, tab)
|
||||||
const navigationKeys = ['ArrowLeft', 'ArrowRight', 'Delete', 'Backspace', 'Tab'];
|
const navigationKeys = ['ArrowLeft', 'ArrowRight', 'Delete', 'Backspace', 'Tab'];
|
||||||
if (navigationKeys.includes(event.key)) {
|
if (navigationKeys.includes(event.key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Erlaube nur Zahlen
|
// Only allow numbers
|
||||||
if (!/^\d$/.test(event.key)) {
|
if (!/^\d$/.test(event.key)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ermittle den Wert, der nach dem Tastendruck entstehen würde
|
// Get the value that would result after the keypress
|
||||||
const input = event.target as HTMLInputElement;
|
const input = event.target as HTMLInputElement;
|
||||||
const currentValue = input.value;
|
const currentValue = input.value;
|
||||||
const cursorPosition = input.selectionStart || 0;
|
const cursorPosition = input.selectionStart || 0;
|
||||||
|
@ -232,14 +230,14 @@ export default class CoinflipComponent implements OnInit {
|
||||||
currentValue.substring(input.selectionEnd || cursorPosition);
|
currentValue.substring(input.selectionEnd || cursorPosition);
|
||||||
const numValue = Number(newValue);
|
const numValue = Number(newValue);
|
||||||
|
|
||||||
// Verhindere Werte, die größer als das Guthaben sind
|
// Prevent values greater than balance
|
||||||
if (numValue > this.balance()) {
|
if (numValue > this.balance()) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Der Paste-Handler wurde der Einfachheit halber entfernt, da die updateBet-Methode
|
// We removed the paste handler for simplicity since the updateBet method
|
||||||
// jeden Wert behandelt, der in das Eingabefeld gelangt
|
// will handle any value that gets into the input field
|
||||||
|
|
||||||
getResultClass() {
|
getResultClass() {
|
||||||
if (!this.gameResult()) return '';
|
if (!this.gameResult()) return '';
|
||||||
|
|
|
@ -27,7 +27,7 @@ type DiceFormGroup = FormGroup<{
|
||||||
imports: [CommonModule, ReactiveFormsModule, PlaySoundDirective, DragSoundDirective],
|
imports: [CommonModule, ReactiveFormsModule, PlaySoundDirective, DragSoundDirective],
|
||||||
templateUrl: './dice.component.html',
|
templateUrl: './dice.component.html',
|
||||||
})
|
})
|
||||||
export default class DiceComponent implements OnInit {
|
export class DiceComponent implements OnInit {
|
||||||
private readonly formBuilder = inject(FormBuilder);
|
private readonly formBuilder = inject(FormBuilder);
|
||||||
private readonly diceService = inject(DiceService);
|
private readonly diceService = inject(DiceService);
|
||||||
private readonly userService = inject(UserService);
|
private readonly userService = inject(UserService);
|
||||||
|
|
|
@ -11,8 +11,7 @@ import { ActivatedRoute, RouterLink } from '@angular/router';
|
||||||
import { AuthService } from '@service/auth.service';
|
import { AuthService } from '@service/auth.service';
|
||||||
import { LoginComponent } from '../auth/login/login.component';
|
import { LoginComponent } from '../auth/login/login.component';
|
||||||
import { RegisterComponent } from '../auth/register/register.component';
|
import { RegisterComponent } from '../auth/register/register.component';
|
||||||
import '../auth/recover-password/recover-password.component';
|
import { RecoverPasswordComponent } from '../auth/recover-password/recover-password.component';
|
||||||
import RecoverPasswordComponent from '../auth/recover-password/recover-password.component';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-landing-page',
|
selector: 'app-landing-page',
|
||||||
|
|
|
@ -79,15 +79,6 @@ 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 {
|
logout(): void {
|
||||||
localStorage.removeItem(TOKEN_KEY);
|
localStorage.removeItem(TOKEN_KEY);
|
||||||
localStorage.removeItem(USER_KEY);
|
localStorage.removeItem(USER_KEY);
|
||||||
|
|
Reference in a new issue