Date: Wed, 14 May 2025 12:02:38 +0200
Subject: [PATCH 006/199] style: fix comment formatting in HTML file
---
frontend/src/app/app.component.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/src/app/app.component.html b/frontend/src/app/app.component.html
index 42c3678..3adc99f 100644
--- a/frontend/src/app/app.component.html
+++ b/frontend/src/app/app.component.html
@@ -5,7 +5,7 @@
- Auth Forms Overlay -->
+ Auth Forms Overlay -->
@if (showLogin() || showRegister()) {
Date: Wed, 14 May 2025 12:12:33 +0200
Subject: [PATCH 007/199] feat(auth): emit closeDialog on successful
registration
---
frontend/src/app/feature/auth/register/register.component.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/frontend/src/app/feature/auth/register/register.component.ts b/frontend/src/app/feature/auth/register/register.component.ts
index 7a3e381..60f289b 100644
--- a/frontend/src/app/feature/auth/register/register.component.ts
+++ b/frontend/src/app/feature/auth/register/register.component.ts
@@ -64,6 +64,7 @@ export class RegisterComponent {
})
.subscribe({
next: () => {
+ this.closeDialog.emit();
this.router.navigate(['/home']);
},
error: () => {
From 59aa8319818efa633211f210fbf1a6cc66768631 Mon Sep 17 00:00:00 2001
From: csimonis
Date: Thu, 15 May 2025 10:02:41 +0200
Subject: [PATCH 008/199] feat(auth): add email verification functionality
---
.../casino/security/service/AuthService.java | 2 +-
.../casino/security/service/EmailService.java | 18 +++
.../java/de/szut/casino/user/UserEntity.java | 7 +-
.../java/de/szut/casino/user/UserService.java | 4 +-
.../resources/templates/email/deposit.html | 2 +-
.../resources/templates/email/verify.html | 149 ++++++++++++++++++
.../resources/templates/email/welcome.html | 2 +-
7 files changed, 179 insertions(+), 5 deletions(-)
create mode 100644 backend/src/main/resources/templates/email/verify.html
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 ed2b70c..c4d324d 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
@@ -47,7 +47,7 @@ public class AuthService {
public GetUserDto register(CreateUserDto signUpRequest) throws MessagingException, IOException {
UserEntity user = userService.createUser(signUpRequest);
- this.emailService.sendRegistrationEmail(user);
+ this.emailService.sendEmailVerificationEmail(user);
return new GetUserDto(
user.getId(),
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 861a0c2..348fafd 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
@@ -35,6 +35,24 @@ 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 sendRegistrationEmail(UserEntity user) throws IOException, MessagingException {
String template = loadTemplate("email/welcome.html");
String htmlContent = template
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 270d178..161ce52 100644
--- a/backend/src/main/java/de/szut/casino/user/UserEntity.java
+++ b/backend/src/main/java/de/szut/casino/user/UserEntity.java
@@ -30,11 +30,16 @@ public class UserEntity {
@Column(precision = 19, scale = 2)
private BigDecimal balance;
- public UserEntity(String email, String username, String password, BigDecimal balance) {
+ private Boolean emailVerified = false;
+
+ private String verificationToken;
+
+ public UserEntity(String email, String username, String password, BigDecimal balance, String verificationToken) {
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/UserService.java b/backend/src/main/java/de/szut/casino/user/UserService.java
index 25fabef..6855619 100644
--- a/backend/src/main/java/de/szut/casino/user/UserService.java
+++ b/backend/src/main/java/de/szut/casino/user/UserService.java
@@ -2,6 +2,7 @@ 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;
@@ -31,7 +32,8 @@ public class UserService {
createUserDto.getEmail(),
createUserDto.getUsername(),
passwordEncoder.encode(createUserDto.getPassword()),
- BigDecimal.valueOf(100) // Starting balance
+ BigDecimal.valueOf(100),
+ RandomStringUtils.randomAlphanumeric(64)
);
return userRepository.save(user);
diff --git a/backend/src/main/resources/templates/email/deposit.html b/backend/src/main/resources/templates/email/deposit.html
index 632d7ab..be54677 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
new file mode 100644
index 0000000..008236d
--- /dev/null
+++ b/backend/src/main/resources/templates/email/verify.html
@@ -0,0 +1,149 @@
+
+
+
+
+
+
+
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 2a10134..ed43938 100644
--- a/backend/src/main/resources/templates/email/welcome.html
+++ b/backend/src/main/resources/templates/email/welcome.html
@@ -120,7 +120,7 @@
Ihr