diff --git a/backend/src/main/java/de/szut/casino/exceptionHandling/GlobalExceptionHandler.java b/backend/src/main/java/de/szut/casino/exceptionHandling/GlobalExceptionHandler.java index 9c185a8..573abb8 100644 --- a/backend/src/main/java/de/szut/casino/exceptionHandling/GlobalExceptionHandler.java +++ b/backend/src/main/java/de/szut/casino/exceptionHandling/GlobalExceptionHandler.java @@ -1,6 +1,5 @@ package de.szut.casino.exceptionHandling; -import de.szut.casino.exceptionHandling.exceptions.EmailNotVerifiedException; import de.szut.casino.exceptionHandling.exceptions.InsufficientFundsException; import de.szut.casino.exceptionHandling.exceptions.UserNotFoundException; import jakarta.persistence.EntityExistsException; @@ -32,10 +31,4 @@ public class GlobalExceptionHandler { ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false)); return new ResponseEntity<>(errorDetails, HttpStatus.CONFLICT); } - - @ExceptionHandler(EmailNotVerifiedException.class) - public ResponseEntity handleEmailNotVerifiedException(EmailNotVerifiedException ex, WebRequest request) { - ErrorDetails errorDetails = new ErrorDetails(new Date(), ex.getMessage(), request.getDescription(false)); - return new ResponseEntity<>(errorDetails, HttpStatus.UNAUTHORIZED); - } } diff --git a/backend/src/main/java/de/szut/casino/exceptionHandling/exceptions/EmailNotVerifiedException.java b/backend/src/main/java/de/szut/casino/exceptionHandling/exceptions/EmailNotVerifiedException.java deleted file mode 100644 index ea08367..0000000 --- a/backend/src/main/java/de/szut/casino/exceptionHandling/exceptions/EmailNotVerifiedException.java +++ /dev/null @@ -1,9 +0,0 @@ -package de.szut.casino.exceptionHandling.exceptions; - -import de.szut.casino.security.service.EmailService; - -public class EmailNotVerifiedException extends Exception { - public EmailNotVerifiedException() { - super("Email not verified"); - } -} diff --git a/backend/src/main/java/de/szut/casino/security/AuthController.java b/backend/src/main/java/de/szut/casino/security/AuthController.java index f833d78..6d99625 100644 --- a/backend/src/main/java/de/szut/casino/security/AuthController.java +++ b/backend/src/main/java/de/szut/casino/security/AuthController.java @@ -1,7 +1,5 @@ package de.szut.casino.security; -import de.szut.casino.exceptionHandling.ErrorDetails; -import de.szut.casino.exceptionHandling.exceptions.EmailNotVerifiedException; import de.szut.casino.security.dto.AuthResponseDto; import de.szut.casino.security.dto.LoginRequestDto; import de.szut.casino.security.service.AuthService; @@ -11,10 +9,12 @@ import jakarta.mail.MessagingException; import jakarta.validation.Valid; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.io.IOException; -import java.util.Date; @RestController @RequestMapping("/auth") @@ -24,7 +24,7 @@ public class AuthController { private AuthService authService; @PostMapping("/login") - public ResponseEntity authenticateUser(@Valid @RequestBody LoginRequestDto loginRequest) throws EmailNotVerifiedException { + public ResponseEntity authenticateUser(@Valid @RequestBody LoginRequestDto loginRequest) { AuthResponseDto response = authService.login(loginRequest); return ResponseEntity.ok(response); } @@ -34,13 +34,4 @@ public class AuthController { GetUserDto response = authService.register(signUpRequest); return ResponseEntity.ok(response); } - - @PostMapping("/verify") - public ResponseEntity verifyEmail(@RequestParam("token") String token) throws MessagingException, IOException { - if (authService.verifyEmail(token)) { - return ResponseEntity.badRequest().build(); - } - - return ResponseEntity.ok().build(); - } } diff --git a/backend/src/main/java/de/szut/casino/security/service/AuthService.java b/backend/src/main/java/de/szut/casino/security/service/AuthService.java index f51ff83..ed2b70c 100644 --- a/backend/src/main/java/de/szut/casino/security/service/AuthService.java +++ b/backend/src/main/java/de/szut/casino/security/service/AuthService.java @@ -1,6 +1,5 @@ package de.szut.casino.security.service; -import de.szut.casino.exceptionHandling.exceptions.EmailNotVerifiedException; import de.szut.casino.security.dto.AuthResponseDto; import de.szut.casino.security.dto.LoginRequestDto; import de.szut.casino.security.jwt.JwtUtils; @@ -17,7 +16,6 @@ import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import java.io.IOException; -import java.util.Optional; @Service public class AuthService { @@ -34,11 +32,7 @@ public class AuthService { @Autowired private EmailService emailService; - public AuthResponseDto login(LoginRequestDto loginRequest) throws EmailNotVerifiedException { - if (!userService.isVerified(loginRequest.getUsernameOrEmail())) { - throw new EmailNotVerifiedException(); - } - + public AuthResponseDto login(LoginRequestDto loginRequest) { Authentication authentication = authenticationManager.authenticate( new UsernamePasswordAuthenticationToken( loginRequest.getUsernameOrEmail(), @@ -53,7 +47,7 @@ public class AuthService { public GetUserDto register(CreateUserDto signUpRequest) throws MessagingException, IOException { UserEntity user = userService.createUser(signUpRequest); - this.emailService.sendEmailVerificationEmail(user); + this.emailService.sendRegistrationEmail(user); return new GetUserDto( user.getId(), @@ -62,21 +56,4 @@ public class AuthService { user.getBalance() ); } - - public Boolean verifyEmail(String token) throws MessagingException, IOException { - Optional optionalUser = userService.getUserByVerificationToken(token); - - if(!optionalUser.isPresent()) { - return false; - } - - UserEntity user = optionalUser.get(); - - user.setEmailVerified(true); - user.setVerificationToken(null); - userService.saveUser(user); - this.emailService.sendWelcomeEmail(user); - - return true; - } } diff --git a/backend/src/main/java/de/szut/casino/security/service/EmailService.java b/backend/src/main/java/de/szut/casino/security/service/EmailService.java index 4d83262..861a0c2 100644 --- a/backend/src/main/java/de/szut/casino/security/service/EmailService.java +++ b/backend/src/main/java/de/szut/casino/security/service/EmailService.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.StandardCharsets; +import java.util.List; @Service public class EmailService { @@ -34,25 +35,7 @@ public class EmailService { } } - public void sendEmailVerificationEmail(UserEntity user) throws IOException, MessagingException { - String template = loadTemplate("email/verify.html"); - String htmlContent = template - .replace("${username}", user.getUsername()) - .replace("${feUrl}", feUrl) - .replace("${token}", user.getVerificationToken()); - - MimeMessage message = mailSender.createMimeMessage(); - MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8"); - - helper.setFrom(mailConfig.fromAddress); - helper.setTo(user.getEmailAddress()); - helper.setSubject("E-Mail Bestätigung"); - helper.setText(htmlContent, true); - - mailSender.send(message); - } - - public void sendWelcomeEmail(UserEntity user) throws IOException, MessagingException { + public void sendRegistrationEmail(UserEntity user) throws IOException, MessagingException { String template = loadTemplate("email/welcome.html"); String htmlContent = template .replace("${username}", user.getUsername()) diff --git a/backend/src/main/java/de/szut/casino/user/UserEntity.java b/backend/src/main/java/de/szut/casino/user/UserEntity.java index 161ce52..270d178 100644 --- a/backend/src/main/java/de/szut/casino/user/UserEntity.java +++ b/backend/src/main/java/de/szut/casino/user/UserEntity.java @@ -30,16 +30,11 @@ public class UserEntity { @Column(precision = 19, scale = 2) private BigDecimal balance; - private Boolean emailVerified = false; - - private String verificationToken; - - public UserEntity(String email, String username, String password, BigDecimal balance, String verificationToken) { + public UserEntity(String email, String username, String password, BigDecimal balance) { this.email = email; this.username = username; this.password = password; this.balance = balance; - this.verificationToken = verificationToken; } public void addBalance(BigDecimal amountToAdd) { diff --git a/backend/src/main/java/de/szut/casino/user/UserRepository.java b/backend/src/main/java/de/szut/casino/user/UserRepository.java index 9eafd54..863e744 100644 --- a/backend/src/main/java/de/szut/casino/user/UserRepository.java +++ b/backend/src/main/java/de/szut/casino/user/UserRepository.java @@ -1,7 +1,6 @@ package de.szut.casino.user; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Service; import java.util.Optional; @@ -15,10 +14,4 @@ public interface UserRepository extends JpaRepository { boolean existsByUsername(String username); boolean existsByEmail(String email); - - @Query("SELECT u FROM UserEntity u WHERE u.verificationToken = ?1") - Optional findOneByVerificationToken(String token); - - @Query("SELECT u FROM UserEntity u WHERE u.username = ?1 OR u.email = ?1") - Optional findOneByUsernameOrEmail(String usernameOrEmail); } diff --git a/backend/src/main/java/de/szut/casino/user/UserService.java b/backend/src/main/java/de/szut/casino/user/UserService.java index 9113864..25fabef 100644 --- a/backend/src/main/java/de/szut/casino/user/UserService.java +++ b/backend/src/main/java/de/szut/casino/user/UserService.java @@ -2,7 +2,6 @@ package de.szut.casino.user; import de.szut.casino.user.dto.CreateUserDto; import jakarta.persistence.EntityExistsException; -import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.password.PasswordEncoder; @@ -32,8 +31,7 @@ public class UserService { createUserDto.getEmail(), createUserDto.getUsername(), passwordEncoder.encode(createUserDto.getPassword()), - BigDecimal.valueOf(100), - RandomStringUtils.randomAlphanumeric(64) + BigDecimal.valueOf(100) // Starting balance ); return userRepository.save(user); @@ -44,22 +42,4 @@ public class UserService { return userRepository.findByUsername(username); } - - public Optional getUserByVerificationToken(String token) { - return this.userRepository.findOneByVerificationToken(token); - } - - public void saveUser(UserEntity user) { - userRepository.save(user); - } - - public boolean isVerified(String usernameOrEmail) { - Optional optionalUser = userRepository.findOneByUsernameOrEmail(usernameOrEmail); - - if (!optionalUser.isPresent()) { - return false; - } - - return optionalUser.get().getEmailVerified(); - } } diff --git a/backend/src/main/resources/templates/email/deposit.html b/backend/src/main/resources/templates/email/deposit.html index be54677..632d7ab 100644 --- a/backend/src/main/resources/templates/email/deposit.html +++ b/backend/src/main/resources/templates/email/deposit.html @@ -128,7 +128,7 @@ Ihr Trustworthy Casino Team

diff --git a/backend/src/main/resources/templates/email/verify.html b/backend/src/main/resources/templates/email/verify.html deleted file mode 100644 index b7dc2a6..0000000 --- a/backend/src/main/resources/templates/email/verify.html +++ /dev/null @@ -1,149 +0,0 @@ - - - - - - E-Mail-Verifizierung - Trustworthy Casino© - - - -
-
-

Trustworthy Casino

-
-
-

Hallo ${username},

- -

vielen Dank für Ihre Registrierung bei Trustworthy Casino. Um Ihr Konto zu aktivieren und Zugang zu allen Funktionen zu erhalten, bestätigen Sie bitte Ihre E-Mail-Adresse.

- -
- -

Klicken Sie auf den folgenden Button, um Ihre E-Mail-Adresse zu bestätigen:

- - - -
-

Hinweis: Der Bestätigungscode könnte nur 24 Stunden gültig sein und kann vielleicht auch nur einmal verwendet werden.

-
- -
- -

Nach der Bestätigung Ihrer E-Mail-Adresse können Sie sofort mit dem Spielen beginnen und alle Vorteile Ihres Kontos nutzen.

- -

Bei Fragen stehen wir Ihnen jederzeit zur Verfügung.

- -

Mit freundlichen Grüßen,
- Ihr Trustworthy Casino Team

-
- -
- - \ No newline at end of file diff --git a/backend/src/main/resources/templates/email/welcome.html b/backend/src/main/resources/templates/email/welcome.html index ed43938..2a10134 100644 --- a/backend/src/main/resources/templates/email/welcome.html +++ b/backend/src/main/resources/templates/email/welcome.html @@ -120,7 +120,7 @@ Ihr Trustworthy Casino Team

diff --git a/frontend/src/app/app.routes.ts b/frontend/src/app/app.routes.ts index 5c57416..3792038 100644 --- a/frontend/src/app/app.routes.ts +++ b/frontend/src/app/app.routes.ts @@ -12,13 +12,6 @@ export const routes: Routes = [ loadComponent: () => import('./feature/home/home.component'), canActivate: [authGuard], }, - { - path: 'verify', - loadComponent: () => - import('./feature/auth/verify-email/verify-email.component').then( - (m) => m.VerifyEmailComponent - ), - }, { path: 'game/blackjack', loadComponent: () => import('./feature/game/blackjack/blackjack.component'), diff --git a/frontend/src/app/feature/auth/register/register.component.ts b/frontend/src/app/feature/auth/register/register.component.ts index a421184..60f289b 100644 --- a/frontend/src/app/feature/auth/register/register.component.ts +++ b/frontend/src/app/feature/auth/register/register.component.ts @@ -56,6 +56,25 @@ export class RegisterComponent { }; this.authService.register(registerRequest).subscribe({ + next: () => { + this.authService + .login({ + usernameOrEmail: registerRequest.email, + password: registerRequest.password, + }) + .subscribe({ + next: () => { + this.closeDialog.emit(); + this.router.navigate(['/home']); + }, + error: () => { + this.isLoading.set(false); + this.errorMessage.set( + 'Registration successful but failed to login automatically. Please log in manually.' + ); + }, + }); + }, error: (err: HttpErrorResponse) => { this.isLoading.set(false); diff --git a/frontend/src/app/feature/auth/verify-email/verify-email.component.html b/frontend/src/app/feature/auth/verify-email/verify-email.component.html deleted file mode 100644 index d7bc11c..0000000 --- a/frontend/src/app/feature/auth/verify-email/verify-email.component.html +++ /dev/null @@ -1 +0,0 @@ -

Verifying...

diff --git a/frontend/src/app/feature/auth/verify-email/verify-email.component.ts b/frontend/src/app/feature/auth/verify-email/verify-email.component.ts deleted file mode 100644 index 5f2814a..0000000 --- a/frontend/src/app/feature/auth/verify-email/verify-email.component.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Component, inject, OnInit } from '@angular/core'; -import { ActivatedRoute, Router } from '@angular/router'; -import { AuthService } from '@service/auth.service'; - -@Component({ - selector: 'app-verify-email', - imports: [], - templateUrl: './verify-email.component.html', -}) -export class VerifyEmailComponent implements OnInit { - route: ActivatedRoute = inject(ActivatedRoute); - router: Router = inject(Router); - authService: AuthService = inject(AuthService); - - ngOnInit(): void { - const token = this.route.snapshot.queryParamMap.get('token'); - - if (!token) { - this.router.navigate(['']); - console.log('no token'); - return; - } - - this.authService.verifyEmail(token).subscribe(() => { - this.router.navigate([''], { - queryParams: { login: true }, - }); - }); - } -} diff --git a/frontend/src/app/feature/landing/landing.component.ts b/frontend/src/app/feature/landing/landing.component.ts index 5cfe0c5..d4d6078 100644 --- a/frontend/src/app/feature/landing/landing.component.ts +++ b/frontend/src/app/feature/landing/landing.component.ts @@ -7,7 +7,7 @@ import { signal, } from '@angular/core'; import { NgFor } from '@angular/common'; -import { ActivatedRoute, RouterLink } from '@angular/router'; +import { RouterLink } from '@angular/router'; import { AuthService } from '@service/auth.service'; import { LoginComponent } from '../auth/login/login.component'; import { RegisterComponent } from '../auth/register/register.component'; @@ -23,16 +23,12 @@ export class LandingComponent implements OnInit, OnDestroy { currentSlide = 0; private autoplayInterval: ReturnType | undefined; authService: AuthService = inject(AuthService); - route: ActivatedRoute = inject(ActivatedRoute); showLogin = signal(false); showRegister = signal(false); ngOnInit() { this.startAutoplay(); document.body.style.overflow = 'auto'; - if (this.route.snapshot.queryParamMap.get('login') === 'true') { - this.showLoginForm(); - } } ngOnDestroy() { diff --git a/frontend/src/app/service/auth.service.ts b/frontend/src/app/service/auth.service.ts index 657067f..1066008 100644 --- a/frontend/src/app/service/auth.service.ts +++ b/frontend/src/app/service/auth.service.ts @@ -74,10 +74,6 @@ export class AuthService { }); } - public verifyEmail(token: string): Observable { - return this.http.post(`${this.authUrl}/verify?token=${token}`, null); - } - private setToken(token: string): void { localStorage.setItem(TOKEN_KEY, token); }