feat: verify email (CAS-66) #192
3 changed files with 4 additions and 4 deletions
|
@ -36,7 +36,7 @@ public class AuthController {
|
|||
}
|
||||
|
||||
@PostMapping("/verify")
|
||||
public ResponseEntity<Void> verifyEmail(@RequestParam("token") String token) {
|
||||
public ResponseEntity<Void> verifyEmail(@RequestParam("token") String token) throws MessagingException, IOException {
|
||||
if (authService.verifyEmail(token)) {
|
||||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class AuthService {
|
|||
);
|
||||
}
|
||||
|
||||
public Boolean verifyEmail(String token) {
|
||||
public Boolean verifyEmail(String token) throws MessagingException, IOException {
|
||||
Optional<UserEntity> optionalUser = userService.getUserByVerificationToken(token);
|
||||
|
||||
if(!optionalUser.isPresent()) {
|
||||
|
@ -75,6 +75,7 @@ public class AuthService {
|
|||
user.setEmailVerified(true);
|
||||
user.setVerificationToken(null);
|
||||
userService.saveUser(user);
|
||||
this.emailService.sendWelcomeEmail(user);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ 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 {
|
||||
|
@ -53,7 +52,7 @@ public class EmailService {
|
|||
mailSender.send(message);
|
||||
}
|
||||
|
||||
public void sendRegistrationEmail(UserEntity user) throws IOException, MessagingException {
|
||||
public void sendWelcomeEmail(UserEntity user) throws IOException, MessagingException {
|
||||
String template = loadTemplate("email/welcome.html");
|
||||
String htmlContent = template
|
||||
.replace("${username}", user.getUsername())
|
||||
|
|
Reference in a new issue