diff --git a/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java b/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java index 10b3302..cf61625 100644 --- a/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java +++ b/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java @@ -97,7 +97,7 @@ public class ForgotPasswordServlet extends HttpServlet { request.getSession().setAttribute("message", "Error sending email."); response.sendRedirect("./forgotPassword.jsp"); } - + } } diff --git a/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java b/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java index 141289b..a0f8169 100644 --- a/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java +++ b/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java @@ -1,5 +1,6 @@ package eu.dnetlib.openaire.usermanagement; +import eu.dnetlib.openaire.user.utils.EmailSender; import eu.dnetlib.openaire.user.utils.LDAPActions; import eu.dnetlib.openaire.user.utils.VerificationActions; import org.apache.log4j.Logger; @@ -13,6 +14,9 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +import java.sql.Timestamp; +import java.util.Date; +import java.util.UUID; /** * Created by sofia on 20/10/2017. @@ -28,6 +32,9 @@ public class RegisterServlet extends HttpServlet { @Autowired private VerificationActions verificationActions; + @Autowired + private EmailSender emailSender; + @Autowired private LDAPActions ldapActions; @@ -55,14 +62,55 @@ public class RegisterServlet extends HttpServlet { if (firstName != null && lastName != null && username != null && email.equals(confirmEmail) /*&& password.equals(confirmPassword)*/ ) { try { - ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/); - logger.info("User successfully created"); + +// if (ldapActions.usernameExists(username)) { +// request.getSession().setAttribute("username_message", "Username already exists! Choose another one."); +// logger.info("Username already exists"); +// response.sendRedirect("./register.jsp"); +// +// } else if (ldapActions.emailExists(email)) { +// request.getSession().setAttribute("email_message", "There is another user with this email."); +// logger.info("There is another user with this email"); +// response.sendRedirect("./register.jsp"); +// +// } else { + + ldapActions.createUser(username, email, firstName, lastName, organization/*, password*/); + logger.info("User successfully created"); + + UUID verificationCode = UUID.randomUUID(); + Date creationDate = new Date(); + + Timestamp timestamp = new Timestamp(creationDate.getTime()); + + if (!verificationActions.verificationEntryExists(username)) { + verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp); + + } else { + verificationActions.updateVerificationEntry(username, verificationCode.toString(), timestamp); + } + + String verificationCodeMsg = "Hello " + username + ",\n" + + "\n" + + "A request has been made to verify your email and activate your OpenAIRE account. To activate your\n" + + "account, you will need to submit your username and this activation code in order to verify that the\n" + + "request was legitimate.\n" + + "\n" + + "The activation code is " + verificationCode.toString() + "\n Thank you"; + + String verificationCodeSubject = "Your OpenAIRE password reset request"; + + emailSender.sendEmail(email, verificationCodeSubject, verificationCodeMsg); + + + response.sendRedirect("./activate.jsp"); +// } + } catch (Exception e) { logger.error("LDAP error in creating user", e); response.sendRedirect("./error.jsp"); } } - response.sendRedirect("./activate.jsp"); printWriter.close(); } diff --git a/src/main/webapp/register.jsp b/src/main/webapp/register.jsp index 4206b8c..ccb31a6 100644 --- a/src/main/webapp/register.jsp +++ b/src/main/webapp/register.jsp @@ -17,7 +17,7 @@ - + @@ -56,7 +56,7 @@