feat: whoops
All checks were successful
CI / Get Changed Files (pull_request) Successful in 7s
CI / eslint (pull_request) Has been skipped
CI / oxlint (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
CI / Docker frontend validation (pull_request) Successful in 45s
CI / Docker backend validation (pull_request) Successful in 1m2s
CI / Checkstyle Main (pull_request) Successful in 1m1s
All checks were successful
CI / Get Changed Files (pull_request) Successful in 7s
CI / eslint (pull_request) Has been skipped
CI / oxlint (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
CI / Docker frontend validation (pull_request) Successful in 45s
CI / Docker backend validation (pull_request) Successful in 1m2s
CI / Checkstyle Main (pull_request) Successful in 1m1s
This commit is contained in:
parent
e6c34ffe90
commit
73710a1542
4 changed files with 36 additions and 44 deletions
|
@ -1,8 +1,5 @@
|
|||
package de.szut.casino.health;
|
||||
|
||||
import de.szut.casino.security.service.EmailService;
|
||||
import de.szut.casino.user.UserEntity;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
@ -11,17 +8,8 @@ import java.util.Map;
|
|||
@RestController
|
||||
public class HealthController {
|
||||
|
||||
@Autowired
|
||||
private EmailService emailService;
|
||||
|
||||
@GetMapping("/health")
|
||||
public Map<String, String> healthCheck() {
|
||||
UserEntity user = new UserEntity();
|
||||
user.setEmail("user@mail.com");
|
||||
user.setUsername("user");
|
||||
|
||||
this.emailService.sendRegistrationEmail(user);
|
||||
|
||||
return Map.of("status", "UP");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -23,7 +23,6 @@ public class EmailService {
|
|||
private String feUrl;
|
||||
|
||||
public EmailService(JavaMailSenderImpl mailSender, MailConfig mailConfig) {
|
||||
try {
|
||||
this.mailSender = mailSender;
|
||||
this.mailConfig = mailConfig;
|
||||
this.mailSender.setHost(mailConfig.host);
|
||||
|
@ -32,13 +31,9 @@ public class EmailService {
|
|||
this.mailSender.setUsername(mailConfig.username);
|
||||
this.mailSender.setPassword(mailConfig.password);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void sendRegistrationEmail(UserEntity user) {
|
||||
try {
|
||||
public void sendRegistrationEmail(UserEntity user) throws IOException, MessagingException {
|
||||
String template = loadTemplate("email/welcome.html");
|
||||
String htmlContent = template
|
||||
.replace("${username}", user.getUsername())
|
||||
|
@ -53,9 +48,6 @@ public class EmailService {
|
|||
helper.setText(htmlContent, true);
|
||||
|
||||
mailSender.send(message);
|
||||
} catch (MessagingException | IOException e) {
|
||||
System.err.println("Failed to send registration email: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private String loadTemplate(String templatePath) throws IOException {
|
||||
|
|
Reference in a new issue