diff --git a/src/main/java/ch/floaty/domain/service/AuthenticationService.java b/src/main/java/ch/floaty/domain/service/AuthenticationService.java index a475795..54a60a4 100644 --- a/src/main/java/ch/floaty/domain/service/AuthenticationService.java +++ b/src/main/java/ch/floaty/domain/service/AuthenticationService.java @@ -28,6 +28,8 @@ public class AuthenticationService implements IAuthenticationService{ public static String baseUrl; private static final String EMAIL_REGEX = "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$"; private static final Pattern EMAIL_PATTERN = Pattern.compile(EMAIL_REGEX); + @Value("${email.verification.url}") + private String emailVerificationUrl; BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); IUserRepository userRepository; @@ -60,14 +62,25 @@ public User register(String username, String email, String password) { String hashedPassword = bCryptPasswordEncoder.encode(password); User newUser = new User(username, email, hashedPassword); User storedUser = this.userRepository.save(newUser); + EmailVerificationToken emailVerificationToken = new EmailVerificationToken(storedUser); this.emailVerificationTokenRepository.save(emailVerificationToken); - String eMailText = "Your email verification code: " + emailVerificationToken.getToken(); + + String eMailText = + "Only one step left to start using Floaty! \n\n" + + "Enter the code in the verification page of the app: \n\n" + + emailVerificationToken.getToken() + "\n\n\n\n" + + "If you closed the app, you can also click on the following link to verify your email: \n\n" + + emailVerificationUrl + "\n\n\n\n" + + "Best, Floaty Team"; + String eMailSubject = "Floaty Email Verification"; emailService.sendSimpleEmail(storedUser.getEmail(), eMailSubject, eMailText); + return storedUser; } + private void validateEmailNotTaken(String email) throws EMailAlreadyUsedException { if (this.userRepository.existsByEmail(email)) { throw new EMailAlreadyUsedException(); diff --git a/src/main/resources/application-docker-compose.properties b/src/main/resources/application-docker-compose.properties index 2136d87..ffab0d7 100644 --- a/src/main/resources/application-docker-compose.properties +++ b/src/main/resources/application-docker-compose.properties @@ -30,3 +30,4 @@ spring.mail.properties.mail.debug=false #spring.mail.port=587 #spring.mail.username=apikey #spring.mail.password=${SENDGRID_API_KEY} +email.verification.url=https://app.floatyfly.com/#/email-validation diff --git a/src/main/resources/application-local-h2.properties b/src/main/resources/application-local-h2.properties index 0c3f4ff..f3c3588 100644 --- a/src/main/resources/application-local-h2.properties +++ b/src/main/resources/application-local-h2.properties @@ -22,4 +22,5 @@ spring.mail.password= # No authentication spring.mail.default-encoding=UTF-8 spring.mail.properties.mail.smtp.auth=false spring.mail.properties.mail.smtp.starttls.enable=false -spring.mail.properties.mail.debug=false \ No newline at end of file +spring.mail.properties.mail.debug=false +email.verification.url=http://localhost:8200/#/email-validation \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index cf069cc..653b976 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,4 +4,3 @@ server.address=0.0.0.0 spring.mvc.pathmatch.matching-strategy=ant_path_matcher server.error.include-stacktrace=never -