Change date type to timestamp and add email verification message

This commit is contained in:
Sofia Baltzi 2017-10-09 12:02:54 +00:00
parent 93d6c4b3e2
commit 38972f84f9
1 changed files with 22 additions and 5 deletions

View File

@ -14,6 +14,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.UUID;
@ -35,7 +36,8 @@ public class ForgotPasswordServlet extends HttpServlet {
@Autowired
private VerificationActions verificationActions;
private EmailActions emailActions;
@Autowired
private EmailSender emailSender;
private Logger logger = Logger.getLogger(ForgotPasswordServlet.class);
@ -50,6 +52,7 @@ public class ForgotPasswordServlet extends HttpServlet {
}
try {
String username = ldapActions.getUsername(formEmail);
if (username == null) {
@ -60,14 +63,28 @@ public class ForgotPasswordServlet extends HttpServlet {
UUID verificationCode = UUID.randomUUID();
Date creationDate = new Date();
if (verificationActions.verificationEntryExists(username)) {
verificationActions.addVerificationEntry(username, verificationCode.toString(), creationDate);
Timestamp timestamp = new Timestamp(creationDate.getTime());
//logger.info("verificationCode = " + verificationCode);
if (!verificationActions.verificationEntryExists(username)) {
verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp);
} else {
verificationActions.updateVerificationEntry(username, verificationCode.toString(), creationDate);
verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
}
emailActions.sendVerificationCode(formEmail);
String verificationCodeMsg = "Hello,\n" +
"\n" +
"A request has been made to reset your OpenAIRE account password. To reset your\n" +
"password, you will need to submit this verification code in order to verify that the\n" +
"request was legitimate.\n" +
"\n" +
"The verification code is" + verificationCode.toString() + "\n Thank you";
verificationCodeSubject = "Your OpenAIRE password reset request";
emailSender.sendEmail(formEmail, verificationCodeSubject, verificationCodeMsg)
}