Adds backend email validation for contact email. (Issue #128)

This commit is contained in:
gkolokythas 2019-08-22 10:36:53 +03:00
parent 934702a734
commit 1f97eaf349
2 changed files with 12 additions and 1 deletions

View File

@ -27,10 +27,12 @@ public class ContactEmail {
public @ResponseBody
ResponseEntity sendContactEmail(@RequestBody ContactEmailModel contactEmailModel, Principal principal) {
try {
this.contactEmailManager.emailValidation(contactEmailModel);
this.contactEmailManager.sendContactEmail(contactEmailModel, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE));
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()));
}
}
}

View File

@ -34,4 +34,13 @@ public class ContactEmailManager {
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");
}
if (contactEmailModel.getDescription() == null || contactEmailModel.getDescription().trim().isEmpty()) {
throw new Exception("Description is empty");
}
}
}