Change date type to timestamp and add email verification message
This commit is contained in:
parent
93d6c4b3e2
commit
38972f84f9
|
@ -14,6 +14,7 @@ import javax.servlet.http.HttpServlet;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.sql.Timestamp;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -35,7 +36,8 @@ public class ForgotPasswordServlet extends HttpServlet {
|
||||||
@Autowired
|
@Autowired
|
||||||
private VerificationActions verificationActions;
|
private VerificationActions verificationActions;
|
||||||
|
|
||||||
private EmailActions emailActions;
|
@Autowired
|
||||||
|
private EmailSender emailSender;
|
||||||
|
|
||||||
private Logger logger = Logger.getLogger(ForgotPasswordServlet.class);
|
private Logger logger = Logger.getLogger(ForgotPasswordServlet.class);
|
||||||
|
|
||||||
|
@ -50,6 +52,7 @@ public class ForgotPasswordServlet extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String username = ldapActions.getUsername(formEmail);
|
String username = ldapActions.getUsername(formEmail);
|
||||||
|
|
||||||
if (username == null) {
|
if (username == null) {
|
||||||
|
@ -60,14 +63,28 @@ public class ForgotPasswordServlet extends HttpServlet {
|
||||||
UUID verificationCode = UUID.randomUUID();
|
UUID verificationCode = UUID.randomUUID();
|
||||||
Date creationDate = new Date();
|
Date creationDate = new Date();
|
||||||
|
|
||||||
if (verificationActions.verificationEntryExists(username)) {
|
Timestamp timestamp = new Timestamp(creationDate.getTime());
|
||||||
verificationActions.addVerificationEntry(username, verificationCode.toString(), creationDate);
|
|
||||||
|
//logger.info("verificationCode = " + verificationCode);
|
||||||
|
|
||||||
|
if (!verificationActions.verificationEntryExists(username)) {
|
||||||
|
verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp);
|
||||||
|
|
||||||
} else {
|
} 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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue