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