Add verificationCode in email's verificationLink for registration and forgot password

This commit is contained in:
Sofia Baltzi 2018-04-12 14:28:18 +00:00
parent 8e18caf18c
commit c4f860225a
3 changed files with 19 additions and 8 deletions

View File

@ -86,25 +86,27 @@ public class ForgotPasswordServlet extends HttpServlet {
} else {
UUID verificationCode = UUID.randomUUID();
Date creationDate = new Date();
String vCode = verificationCode.toString();
Timestamp timestamp = new Timestamp(creationDate.getTime());
if (!verificationActions.verificationEntryExists(username)) {
verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp);
verificationActions.addVerificationEntry(username, vCode, timestamp);
} else {
verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
verificationActions.updateVerificationEntry(username, vCode, timestamp);
}
String resultPath = UrlConstructor.getRedirectUrl(request, "verify.jsp");
String resultPathWithVCode = UrlConstructor.getVerificationLink(resultPath, vCode);
String verificationCodeMsg = "<p>Hello,</p>" +
"<p> A request has been made to reset your OpenAIRE account password. To reset your " +
"password, you will need to submit this verification code in order to verify that the " +
"request was legitimate.</p>" +
"<p> The verification code is " + verificationCode.toString() + "</p>" +
"<p> The verification code is " + vCode + "</p>" +
"Click the URL below and proceed with verification." +
"<p><a href=" + resultPath + ">" + resultPath + "</a></p>" +
"<p><a href=" + resultPathWithVCode + ">" + resultPathWithVCode + "</a></p>" +
"<p>Thank you</p>";
String verificationCodeSubject = "Your OpenAIRE password reset request";

View File

@ -92,27 +92,29 @@ public class RegisterServlet extends HttpServlet {
UUID verificationCode = UUID.randomUUID();
Date creationDate = new Date();
String vCode = verificationCode.toString();
Timestamp timestamp = new Timestamp(creationDate.getTime());
if (!verificationActions.verificationEntryExists(username)) {
verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp);
verificationActions.addVerificationEntry(username, vCode, timestamp);
} else {
verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp);
verificationActions.updateVerificationEntry(username, vCode, timestamp);
}
String resultPath = UrlConstructor.getRedirectUrl(request, "activate.jsp");
String resultPathWithVCode = UrlConstructor.getVerificationLink(resultPath, vCode);
String verificationCodeMsg = "<p>Hello " + username + ",</p>" +
"<p> A request has been made to verify your email and activate your OpenAIRE account. To activate your " +
"account, you will need to submit your username and this activation code in order to verify that the" +
"request was legitimate.</p>" +
"<p>" +
"The activation code is " + verificationCode.toString() +
"The activation code is " + vCode +
"</p>" +
"Click the URL below and proceed with activating your password." +
"<p><a href=" + resultPath + ">" + resultPath + "</a></p>" +
"<p><a href=" + resultPathWithVCode + ">" + resultPathWithVCode + "</a></p>" +
"<p>Thank you</p>";
String verificationCodeSubject = "Activate your OpenAIRE account";

View File

@ -3,6 +3,7 @@ package eu.dnetlib.openaire.usermanagement.utils;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;
/**
* Created by sofia on 8/3/2018.
@ -47,4 +48,10 @@ public class UrlConstructor {
return resultPath;
}
public static String getVerificationLink(String path , String verificationCode ) {
return path + "?code=" + verificationCode;
}
}