Allow splash to send contact emails

This commit is contained in:
George Kalampokis 2020-06-25 19:39:10 +03:00
parent 6d27abaca8
commit d81d6e8568
4 changed files with 102 additions and 33 deletions

View File

@ -2,6 +2,7 @@ package eu.eudat.controllers;
import eu.eudat.logic.managers.ContactEmailManager;
import eu.eudat.models.data.ContactEmail.ContactEmailModel;
import eu.eudat.models.data.ContactEmail.PublicContactEmailModel;
import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.security.Principal;
import eu.eudat.types.ApiMessageCode;
@ -38,4 +39,18 @@ public class ContactEmail {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
}
}
@Transactional
@RequestMapping(method = RequestMethod.POST, path = "public", consumes = "application/x-www-form-urlencoded", produces = "application/json")
public @ResponseBody
ResponseEntity sendContactEmailNoAuth(@ModelAttribute PublicContactEmailModel contactEmailModel) {
logger.info(contactEmailModel.toString());
try {
this.contactEmailManager.sendContactEmailNoAuth(contactEmailModel);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) {
logger.error(ex.getMessage(), ex);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
}
}
}

View File

@ -3,6 +3,7 @@ package eu.eudat.logic.managers;
import eu.eudat.data.entities.UserInfo;
import eu.eudat.logic.services.ApiContext;
import eu.eudat.models.data.ContactEmail.ContactEmailModel;
import eu.eudat.models.data.ContactEmail.PublicContactEmailModel;
import eu.eudat.models.data.mail.SimpleMail;
import eu.eudat.models.data.security.Principal;
import org.springframework.core.env.Environment;
@ -35,6 +36,17 @@ public class ContactEmailManager {
apiContext.getUtilitiesService().getMailService().sendSimpleMail(mail);
}
public void sendContactEmailNoAuth(PublicContactEmailModel contactEmailModel) throws MessagingException {
SimpleMail mail = new SimpleMail();
String enrichedMail = contactEmailModel.getMessage() + "\n\n" + "Send by user: " + contactEmailModel.getEmail() ;
mail.setSubject(contactEmailModel.getAffiliation());
mail.setTo(environment.getProperty("contact_email.mail"));
mail.setContent(enrichedMail);
mail.setFrom(contactEmailModel.getEmail());
apiContext.getUtilitiesService().getMailService().sendSimpleMail(mail);
}
public void emailValidation(ContactEmailModel contactEmailModel) throws Exception {
if (contactEmailModel.getSubject() == null || contactEmailModel.getSubject().trim().isEmpty()) {
throw new Exception("Subject is empty");

View File

@ -0,0 +1,41 @@
package eu.eudat.models.data.ContactEmail;
public class PublicContactEmailModel {
private String fullName;
private String email;
private String affiliation;
private String message;
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAffiliation() {
return affiliation;
}
public void setAffiliation(String affiliation) {
this.affiliation = affiliation;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -61,38 +61,39 @@
<div class="container">
<div class="col ">
<div class="page-title">Contact</div>
</div>
<div class="main-contact">
<div class="col page-subtitle">
<div>Contact us to learn more</div>
</div>
<div class="col required">
<div>* Required fields</div>
</div>
<form class="form">
<!-- Full Name -->
<div class="col d-flex flex-direction-row pb-2">
<div class="form-title">Full name</div>&nbsp;<div class="required">*</div>
</div>
<div class="col pb-4"><input type="text" id="fullName" placeholder="Type your full name"></div>
<!-- E-mail -->
<div class="col d-flex flex-direction-row pb-2">
<div class="form-title">E-mail</div>&nbsp;<div class="required">*</div>
</div>
<div class="col pb-4"><input type="email" id="email" placeholder="Type your E-mail"></div>
<!-- Affiliation -->
<div class="col d-flex flex-direction-row pb-2">
<div class="form-title">Affiliation</div>&nbsp;<div class="required">*</div>
</div>
<div class="col pb-4"><input type="email" id="email" placeholder="Type your E-mail"></div>
<!-- Message -->
<div class="col d-flex flex-direction-row pb-2">
<div class="form-title">Message</div>&nbsp;<div class="required">*</div>
</div>
<div class="col pb-4"><textarea name="message" placeholder="Type your message here..."></textarea>
</form>
</div>
<button type="button" class="normal-btn ml-3">Send</button>
</div>
<form class="form" method="POST" action="http://localhost:8081/api/contactEmail/public">
<div class="main-contact">
<div class="col page-subtitle">
<div>Contact us to learn more</div>
</div>
<div class="col required">
<div>* Required fields</div>
</div>
<!-- Full Name -->
<div class="col d-flex flex-direction-row pb-2">
<div class="form-title">Full name</div>&nbsp;<div class="required">*</div>
</div>
<div class="col pb-4"><input type="text" id="fullName" name="fullName" placeholder="Type your full name"></div>
<!-- E-mail -->
<div class="col d-flex flex-direction-row pb-2">
<div class="form-title">E-mail</div>&nbsp;<div class="required">*</div>
</div>
<div class="col pb-4"><input type="email" id="email" name="email" placeholder="Type your E-mail"></div>
<!-- Affiliation -->
<div class="col d-flex flex-direction-row pb-2">
<div class="form-title">Affiliation</div>&nbsp;<div class="required">*</div>
</div>
<div class="col pb-4"><input type="email" id="affiliation" name="affiliation" placeholder="Type your E-mail"></div>
<!-- Message -->
<div class="col d-flex flex-direction-row pb-2">
<div class="form-title">Message</div>&nbsp;<div class="required">*</div>
</div>
<div class="col pb-4"><textarea name="message" id="message" placeholder="Type your message here..."></textarea>
</div>
<button type="submit" class="normal-btn ml-3">Send</button>
</form>
</div>
</section>
<!-- Footer-->
@ -143,4 +144,4 @@
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>
</body>
</html>
</html>