diff --git a/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java b/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java index 2ef9d23..10b3302 100644 --- a/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java +++ b/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java @@ -56,7 +56,7 @@ public class ForgotPasswordServlet extends HttpServlet { try { String username = ldapActions.getUsername(formEmail); - if (username == null) { + if (username == null || username.isEmpty()) { request.getSession().setAttribute("message", "User does not exist."); response.sendRedirect("./forgotPassword.jsp"); @@ -84,6 +84,9 @@ public class ForgotPasswordServlet extends HttpServlet { String verificationCodeSubject = "Your OpenAIRE password reset request"; emailSender.sendEmail(formEmail, verificationCodeSubject, verificationCodeMsg); + + response.setContentType("text/html"); + response.sendRedirect("./verify.jsp"); } } catch (LDAPException ldape) { @@ -94,9 +97,7 @@ public class ForgotPasswordServlet extends HttpServlet { request.getSession().setAttribute("message", "Error sending email."); response.sendRedirect("./forgotPassword.jsp"); } - - response.setContentType("text/html"); - response.sendRedirect("./verify.jsp"); + } }