diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java
index 7b41ee712..c31567030 100644
--- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java
+++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/MergeEmailConfirmationManager.java
@@ -68,12 +68,12 @@ public class MergeEmailConfirmationManager {
public void sendConfirmationEmail(String email, Principal principal, UUID userId) throws HasConfirmedEmailException {
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
- apiContext.getUtilitiesService().getConfirmationEmailService().createConfirmationEmail(
+ apiContext.getUtilitiesService().getConfirmationEmailService().createMergeConfirmationEmail(
databaseRepository.getLoginConfirmationEmailDao(),
apiContext.getUtilitiesService().getMailService(),
email,
userId,
- principal.getId()
+ principal
);
}
diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/ConfirmationEmailService.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/ConfirmationEmailService.java
index 57d02345b..3b9368e64 100644
--- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/ConfirmationEmailService.java
+++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/ConfirmationEmailService.java
@@ -2,6 +2,7 @@ package eu.eudat.logic.services.utilities;
import eu.eudat.data.dao.entities.EmailConfirmationDao;
import eu.eudat.data.entities.EmailConfirmation;
+import eu.eudat.models.data.security.Principal;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -9,7 +10,9 @@ import java.util.concurrent.CompletableFuture;
public interface ConfirmationEmailService {
public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId);
- public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId, UUID anotheruserId);
+ public void createMergeConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService, String email, UUID userId, Principal principal);
public CompletableFuture sentConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService);
+
+ public CompletableFuture sentMergeConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService, String userName);
}
\ No newline at end of file
diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/ConfirmationEmailServiceImpl.java b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/ConfirmationEmailServiceImpl.java
index 6ff0be763..19bfdf3c9 100644
--- a/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/ConfirmationEmailServiceImpl.java
+++ b/dmp-backend/web/src/main/java/eu/eudat/logic/services/utilities/ConfirmationEmailServiceImpl.java
@@ -1,16 +1,16 @@
package eu.eudat.logic.services.utilities;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import eu.eudat.data.dao.entities.EmailConfirmationDao;
import eu.eudat.data.entities.EmailConfirmation;
import eu.eudat.models.data.mail.SimpleMail;
+import eu.eudat.models.data.security.Principal;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-
import java.util.Date;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@@ -67,6 +67,31 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
return content;
}
+ @Override
+ public CompletableFuture sentMergeConfirmationEmail(EmailConfirmation confirmationEmail, MailService mailService, String userName) {
+ return CompletableFuture.runAsync(() -> {
+ SimpleMail mail = new SimpleMail();
+ mail.setSubject(environment.getProperty("conf_email.subject"));
+ mail.setContent(createMergeContent(confirmationEmail.getToken(), mailService, userName));
+ mail.setTo(confirmationEmail.getEmail());
+ try {
+ mailService.sendSimpleMail(mail);
+ } catch (Exception ex) {
+ logger.error(ex.getMessage(), ex);
+ }
+ });
+ }
+
+ private String createMergeContent(UUID confirmationToken, MailService mailService, String userName) {
+ String content = mailService.getMailTemplateContent("classpath:templates/email/emailMergeConfirmation.html");
+ content = content.replace("{userName}", userName);
+ content = content.replace("{confirmationToken}", confirmationToken.toString());
+ content = content.replace("{expiration_time}", secondsToTime(Integer.parseInt(this.environment.getProperty("conf_email.expiration_time_seconds"))));
+ content = content.replace("{host}", this.environment.getProperty("dmp.domain"));
+
+ return content;
+ }
+
private String secondsToTime(int seconds) {
int sec = seconds % 60;
int hour = seconds / 60;
@@ -76,8 +101,8 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
}
@Override
- public void createConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService,
- String email, UUID userId, UUID anotheruserId) {
+ public void createMergeConfirmationEmail(EmailConfirmationDao loginConfirmationEmailDao, MailService mailService,
+ String email, UUID userId, Principal principal) {
EmailConfirmation confirmationEmail = new EmailConfirmation();
confirmationEmail.setEmail(email);
confirmationEmail.setExpiresAt(Date
@@ -88,14 +113,14 @@ public class ConfirmationEmailServiceImpl implements ConfirmationEmailService {
);
confirmationEmail.setUserId(userId);
try {
- confirmationEmail.setData(new ObjectMapper().writeValueAsString(anotheruserId));
+ confirmationEmail.setData(new ObjectMapper().writeValueAsString(principal.getId()));
} catch (JsonProcessingException e) {
logger.error(e.getMessage(), e);
}
confirmationEmail.setIsConfirmed(false);
confirmationEmail.setToken(UUID.randomUUID());
confirmationEmail = loginConfirmationEmailDao.createOrUpdate(confirmationEmail);
- sentConfirmationEmail(confirmationEmail, mailService);
+ sentMergeConfirmationEmail(confirmationEmail, mailService, principal.getName());
}
}
\ No newline at end of file
diff --git a/dmp-backend/web/src/main/resources/templates/email/emailMergeConfirmation.html b/dmp-backend/web/src/main/resources/templates/email/emailMergeConfirmation.html
new file mode 100644
index 000000000..0affa4121
--- /dev/null
+++ b/dmp-backend/web/src/main/resources/templates/email/emailMergeConfirmation.html
@@ -0,0 +1,304 @@
+
+
+
+
+
+ Simple Transactional Email
+
+
+
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ User {userName} have sent you a merge Request.
+ Please confirm that you want to merge your {host} account with that account.
+ The link will expire in {expiration_time}.
+
+ |
+
+
+ |
+
+
+
+
+
+
+
+
+
+
+
+ |
+ |
+
+
+
+
\ No newline at end of file