Compare commits
6 commits
893939a081
...
88b68f0547
Author | SHA1 | Date | |
---|---|---|---|
88b68f0547 |
|||
d449af9732 |
|||
|
73710a1542 | ||
|
e6c34ffe90 | ||
|
13b3443127 | ||
110dacb6dd |
9 changed files with 255 additions and 3 deletions
|
@ -54,6 +54,7 @@ dependencies {
|
|||
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
|
||||
runtimeOnly("io.jsonwebtoken:jjwt-impl:0.11.5")
|
||||
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
|
||||
compileOnly("org.springframework.boot:spring-boot-starter-mail")
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
|
|
|
@ -8,6 +8,10 @@ import org.springframework.boot.CommandLineRunner;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.mail.MailException;
|
||||
import org.springframework.mail.MailSender;
|
||||
import org.springframework.mail.SimpleMailMessage;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
@ -26,6 +30,11 @@ public class CasinoApplication {
|
|||
return new RestTemplate();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public static JavaMailSenderImpl javaMailSenderImpl() {
|
||||
return new JavaMailSenderImpl();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public CommandLineRunner initData(LootBoxRepository lootBoxRepository, RewardRepository rewardRepository) {
|
||||
return _ -> {
|
||||
|
|
|
@ -5,6 +5,7 @@ import de.szut.casino.security.dto.LoginRequestDto;
|
|||
import de.szut.casino.security.service.AuthService;
|
||||
import de.szut.casino.user.dto.CreateUserDto;
|
||||
import de.szut.casino.user.dto.GetUserDto;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -13,6 +14,8 @@ 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;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/auth")
|
||||
public class AuthController {
|
||||
|
@ -27,7 +30,7 @@ public class AuthController {
|
|||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public ResponseEntity<GetUserDto> registerUser(@Valid @RequestBody CreateUserDto signUpRequest) {
|
||||
public ResponseEntity<GetUserDto> registerUser(@Valid @RequestBody CreateUserDto signUpRequest) throws MessagingException, IOException {
|
||||
GetUserDto response = authService.register(signUpRequest);
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import de.szut.casino.user.UserEntity;
|
|||
import de.szut.casino.user.UserService;
|
||||
import de.szut.casino.user.dto.CreateUserDto;
|
||||
import de.szut.casino.user.dto.GetUserDto;
|
||||
import jakarta.mail.MessagingException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
|
@ -14,6 +15,8 @@ import org.springframework.security.core.Authentication;
|
|||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Service
|
||||
public class AuthService {
|
||||
|
||||
|
@ -26,6 +29,9 @@ public class AuthService {
|
|||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
public AuthResponseDto login(LoginRequestDto loginRequest) {
|
||||
Authentication authentication = authenticationManager.authenticate(
|
||||
new UsernamePasswordAuthenticationToken(
|
||||
|
@ -38,8 +44,11 @@ public class AuthService {
|
|||
return new AuthResponseDto(jwt);
|
||||
}
|
||||
|
||||
public GetUserDto register(CreateUserDto signUpRequest) {
|
||||
public GetUserDto register(CreateUserDto signUpRequest) throws MessagingException, IOException {
|
||||
UserEntity user = userService.createUser(signUpRequest);
|
||||
|
||||
this.emailService.sendRegistrationEmail(user);
|
||||
|
||||
return new GetUserDto(
|
||||
user.getId(),
|
||||
user.getEmail(),
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package de.szut.casino.security.service;
|
||||
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@Service
|
||||
public class EmailService {
|
||||
private JavaMailSenderImpl mailSender;
|
||||
private MailConfig mailConfig;
|
||||
@Value("${app.frontend-host}")
|
||||
private String feUrl;
|
||||
|
||||
public EmailService(JavaMailSenderImpl mailSender, MailConfig mailConfig) {
|
||||
this.mailSender = mailSender;
|
||||
this.mailConfig = mailConfig;
|
||||
this.mailSender.setHost(mailConfig.host);
|
||||
this.mailSender.setPort(mailConfig.port);
|
||||
if (mailConfig.authenticationEnabled) {
|
||||
this.mailSender.setUsername(mailConfig.username);
|
||||
this.mailSender.setPassword(mailConfig.password);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendRegistrationEmail(UserEntity user) throws IOException, MessagingException {
|
||||
String template = loadTemplate("email/welcome.html");
|
||||
String htmlContent = template
|
||||
.replace("${username}", user.getUsername())
|
||||
.replace("${feUrl}", feUrl);
|
||||
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = new MimeMessageHelper(message, true, "UTF-8");
|
||||
|
||||
helper.setFrom(mailConfig.fromAddress);
|
||||
helper.setTo(user.getEmail());
|
||||
helper.setSubject("Willkommen bei Trustworthy Casino©");
|
||||
helper.setText(htmlContent, true);
|
||||
|
||||
mailSender.send(message);
|
||||
}
|
||||
|
||||
private String loadTemplate(String templatePath) throws IOException {
|
||||
ClassPathResource resource = new ClassPathResource("templates/" + templatePath);
|
||||
try (Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) {
|
||||
return FileCopyUtils.copyToString(reader);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package de.szut.casino.security.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MailConfig {
|
||||
@Value("${app.mail.host}")
|
||||
public String host;
|
||||
|
||||
@Value("${app.mail.port}")
|
||||
public Integer port;
|
||||
|
||||
@Value("${app.mail.authentication}")
|
||||
public Boolean authenticationEnabled;
|
||||
|
||||
@Value("${app.mail.username}")
|
||||
public String username;
|
||||
|
||||
@Value("${app.mail.password}")
|
||||
public String password;
|
||||
|
||||
@Value("${app.mail.from-address}")
|
||||
public String fromAddress;
|
||||
}
|
|
@ -5,8 +5,16 @@ server.port=${HTTP_PORT:8080}
|
|||
spring.jpa.hibernate.ddl-auto=update
|
||||
stripe.secret.key=${STRIPE_SECRET_KEY:sk_test_51QrePYIvCfqz7ANgqam8rEwWcMeKiLOof3j6SCMgu2sl4sESP45DJxca16mWcYo1sQaiBv32CMR6Z4AAAGQPCJo300ubuZKO8I}
|
||||
stripe.webhook.secret=${STRIPE_WEBHOOK_SECRET:whsec_746b6a488665f6057118bdb4a2b32f4916f16c277109eeaed5e8f8e8b81b8c15}
|
||||
|
||||
app.frontend-host=${FE_URL:http://localhost:4200}
|
||||
|
||||
app.mail.authentication=${MAIL_AUTHENTICATION:false}
|
||||
app.mail.host=${MAIL_HOST:localhost}
|
||||
app.mail.port=${MAIL_PORT:1025}
|
||||
app.mail.username=${MAIL_USER:null}
|
||||
app.mail.password=${MAIL_PASS:null}
|
||||
app.mail.from-address=${MAIL_FROM:casino@localhost}
|
||||
|
||||
spring.application.name=casino
|
||||
|
||||
# JWT Configuration
|
||||
|
|
128
backend/src/main/resources/templates/email/welcome.html
Normal file
128
backend/src/main/resources/templates/email/welcome.html
Normal file
|
@ -0,0 +1,128 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Willkommen bei Trustworthy Casino©</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: 'Arial', sans-serif;
|
||||
line-height: 1.6;
|
||||
background-color: #f8fafc;
|
||||
color: #64748b;
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
.container {
|
||||
background-color: #0a1219;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
.header {
|
||||
background-color: #1a2835;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.header h1 {
|
||||
color: #ffffff;
|
||||
margin: 0;
|
||||
font-size: 28px;
|
||||
}
|
||||
.content {
|
||||
background-color: #121e27;
|
||||
padding: 30px;
|
||||
color: #ffffff;
|
||||
}
|
||||
.footer {
|
||||
background-color: #1a2835;
|
||||
color: #94a3b8;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
background-color: #10b981;
|
||||
color: #ffffff;
|
||||
padding: 12px 24px;
|
||||
margin: 20px 0;
|
||||
text-decoration: none;
|
||||
border-radius: 6px;
|
||||
font-weight: bold;
|
||||
text-align: center;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
.button:hover {
|
||||
background-color: #059669;
|
||||
}
|
||||
h2 {
|
||||
color: #ffffff;
|
||||
padding-bottom: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
ul {
|
||||
padding-left: 20px;
|
||||
margin: 20px 0;
|
||||
}
|
||||
li {
|
||||
margin-bottom: 8px;
|
||||
color: #94a3b8;
|
||||
}
|
||||
li::marker {
|
||||
color: #34d399;
|
||||
}
|
||||
.highlight {
|
||||
color: #10b981;
|
||||
font-weight: bold;
|
||||
}
|
||||
.divider {
|
||||
height: 1px;
|
||||
background-color: #1a2835;
|
||||
margin: 20px 0;
|
||||
}
|
||||
p {
|
||||
margin: 16px 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="header">
|
||||
<h1>Trustworthy Casino</h1>
|
||||
</div>
|
||||
<div class="content">
|
||||
<h2>Hallo <span class="highlight">${username}</span>,</h2>
|
||||
|
||||
<p>Herzlich willkommen bei Trustworthy Casino! Wir freuen uns, Sie an Bord zu haben.</p>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<p>Bei uns erwarten Sie:</p>
|
||||
<ul>
|
||||
<li>Spannende Casino-Spiele</li>
|
||||
<li>Sichere Transaktionen</li>
|
||||
<li>Exklusive Boni und Aktionen</li>
|
||||
</ul>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<p>Melden Sie sich jetzt an und beginnen Sie Ihr Spielerlebnis!</p>
|
||||
|
||||
<div style="text-align: center;">
|
||||
<a href="${feUrl}/home" class="button">Jetzt Spielen</a>
|
||||
</div>
|
||||
|
||||
<p>Bei Fragen stehen wir Ihnen jederzeit zur Verfügung.</p>
|
||||
|
||||
<p>Mit freundlichen Grüßen,<br>
|
||||
Ihr <span style="color: #10b981;">Trustworthy Casino</span> Team</p>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>2025 Trustworthy Casino - Alle Rechte vorbehalten</p>
|
||||
<p>Diese E-Mail wurde automatisch generiert. Bitte antworten Sie nicht darauf.</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
12
compose.yml
12
compose.yml
|
@ -15,4 +15,14 @@ services:
|
|||
healthcheck:
|
||||
test: "exit 0"
|
||||
ports:
|
||||
- "5432:5432"
|
||||
- "5432:5432"
|
||||
mailpit:
|
||||
image: axllent/mailpit
|
||||
container_name: casino-mailpit
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- 8025:8025
|
||||
- 1025:1025
|
||||
environment:
|
||||
MP_SMTP_AUTH_ACCEPT_ANY: 1
|
||||
MP_SMTP_AUTH_ALLOW_INSECURE: 1
|
||||
|
|
Reference in a new issue