wip: stuff
This commit is contained in:
parent
b41145b85c
commit
9827f81230
5 changed files with 202 additions and 2 deletions
|
@ -43,4 +43,10 @@ public class AuthController {
|
||||||
|
|
||||||
return ResponseEntity.ok().build();
|
return ResponseEntity.ok().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/recover-password")
|
||||||
|
public ResponseEntity<Void> recoverPassword(@RequestParam("email") String email) throws MessagingException, IOException {
|
||||||
|
authService.recoverPassword(email);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ import org.springframework.security.core.Authentication;
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.swing.text.html.Option;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@ -79,4 +80,16 @@ public class AuthService {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void recoverPassword(String email) {
|
||||||
|
Optional<UserEntity> optionalUser = userService.getUserByEmail(email);
|
||||||
|
|
||||||
|
if (optionalUser.isPresent()) {
|
||||||
|
UserEntity user = optionalUser.get();
|
||||||
|
String token = jwtUtils.generateToken(user.getUsername());
|
||||||
|
user.setVerificationToken(token);
|
||||||
|
userService.saveUser(user);
|
||||||
|
this.emailService.sendPasswordRecoveryEmail(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,23 @@ public class EmailService {
|
||||||
mailSender.send(message);
|
mailSender.send(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendPasswordRecoveryEmail(UserEntity user) throws IOException, MessagingException {
|
||||||
|
String template = loadTemplate("email/recover-password.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.getEmailAddress());
|
||||||
|
helper.setSubject("Zurücksetzen ihres Passworts");
|
||||||
|
helper.setText(htmlContent, true);
|
||||||
|
|
||||||
|
mailSender.send(message);
|
||||||
|
}
|
||||||
|
|
||||||
private String loadTemplate(String templatePath) throws IOException {
|
private String loadTemplate(String templatePath) throws IOException {
|
||||||
ClassPathResource resource = new ClassPathResource("templates/" + templatePath);
|
ClassPathResource resource = new ClassPathResource("templates/" + templatePath);
|
||||||
try (Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) {
|
try (Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8)) {
|
||||||
|
|
|
@ -62,4 +62,8 @@ public class UserService {
|
||||||
|
|
||||||
return optionalUser.get().getEmailVerified();
|
return optionalUser.get().getEmailVerified();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<UserEntity> getUserByEmail(String email) {
|
||||||
|
return userRepository.findByEmail(email);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
160
backend/src/main/resources/templates/email/recover-password.html
Normal file
160
backend/src/main/resources/templates/email/recover-password.html
Normal file
|
@ -0,0 +1,160 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="de">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Passwort zurücksetzen - 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;
|
||||||
|
}
|
||||||
|
.recovery-code {
|
||||||
|
background-color: #1a2835;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 15px;
|
||||||
|
text-align: center;
|
||||||
|
margin: 20px 0;
|
||||||
|
letter-spacing: 5px;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #10b981;
|
||||||
|
}
|
||||||
|
.info-box {
|
||||||
|
background-color: #1a2835;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 15px;
|
||||||
|
margin: 20px 0;
|
||||||
|
}
|
||||||
|
.warning {
|
||||||
|
color: #f59e0b;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
.security-info {
|
||||||
|
background-color: #1a2835;
|
||||||
|
border-radius: 6px;
|
||||||
|
padding: 15px;
|
||||||
|
margin: 20px 0;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
</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>wir haben eine Anfrage zum Zurücksetzen Ihres Passworts für Ihr Trustworthy Casino Konto erhalten. Um Ihr Passwort zurückzusetzen, klicken Sie bitte auf den folgenden Button:</p>
|
||||||
|
|
||||||
|
<div style="text-align: center;">
|
||||||
|
<a href="${feUrl}/reset-password?token=${resetToken}" class="button">Passwort zurücksetzen</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>Alternativ können Sie auch diesen Code verwenden:</p>
|
||||||
|
|
||||||
|
<div class="recovery-code">${resetCode}</div>
|
||||||
|
|
||||||
|
<div class="info-box">
|
||||||
|
<p><span class="warning">Hinweis:</span> Dieser Link und Code sind aus Sicherheitsgründen nur <span class="highlight">60 Minuten</span> gültig.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="divider"></div>
|
||||||
|
|
||||||
|
<div class="security-info">
|
||||||
|
<p>Falls Sie diese Anfrage nicht gestellt haben, ignorieren Sie diese E-Mail bitte. In diesem Fall empfehlen wir Ihnen, Ihr Passwort zu ändern und unseren Kundenservice zu kontaktieren, um die Sicherheit Ihres Kontos zu gewährleisten.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="divider"></div>
|
||||||
|
|
||||||
|
<p>Bei Fragen steht Ihnen unser Support-Team 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>
|
||||||
|
<p>Für Fragen zur Sicherheit Ihres Kontos kontaktieren Sie uns bitte unter <span style="color: #10b981;">security@trustworthycasino.com</span></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Reference in a new issue