Fix exceptions and errors

This commit is contained in:
Sofia Baltzi 2017-10-12 14:25:14 +00:00
parent 050186608b
commit 7299bd4813
6 changed files with 21 additions and 44 deletions

View File

@ -8,6 +8,7 @@ import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import javax.mail.MessagingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@ -87,33 +88,15 @@ public class ForgotPasswordServlet extends HttpServlet {
} catch (LDAPException ldape) {
//TODO create error page
logger.error("LDAP error" + ldape);
response.sendRedirect("./error.jsp");
} catch (MessagingException e) {
request.getSession().setAttribute("message", "Error sending email.");
response.sendRedirect("./forgotPassword.jsp");
}
response.setContentType("text/html");
// try {
//// request.getSession().setAttribute("email", formEmail);
//// request.getSession().setAttribute("username", ldapActions.getUsername(formEmail));
//// request.setAttribute("email", formEmail);
// request.setAttribute("username", ldapActions.getUsername(formEmail));
// RequestDispatcher rd = request.getRequestDispatcher("./verify.jsp");
// rd.forward(request, response);
//// RequestDispatcher rd = request.getRequestDispatcher("ForgotPasswordServlet");
//// rd.forward(request, response);
////
//// logger.info("Stelnwwww");
////
// } catch (LDAPException e) {
// e.printStackTrace();
// logger.info("LDAP error" + e);
// request.getSession().setAttribute("message", "Error getting username.");
// response.sendRedirect("./forgotPassword.jsp");
// } catch (ServletException ex) {
// ex.printStackTrace();
// logger.info("Dispacher error" + ex);
// }
response.sendRedirect("./verify.jsp");
}

View File

@ -8,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import javax.mail.MessagingException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@ -54,7 +55,9 @@ public class RemindUsernameServlet extends HttpServlet {
String verificationCodeSubject = "Your OpenAIRE username";
emailSender.sendEmail(formEmail, verificationCodeSubject, verificationCodeMsg);
emailSender.sendEmail(formEmail, verificationCodeSubject, verificationCodeMsg);
} else {
request.getSession().setAttribute("message", "User not found");
@ -65,7 +68,12 @@ public class RemindUsernameServlet extends HttpServlet {
//TODO create error page
logger.error("Could not find user with email " + formEmail, ldape);
response.sendRedirect("./error.jsp");
} catch (MessagingException e) {
logger.error("Error in sending email", e);
response.sendRedirect("./error.jsp");
}
}
}

View File

@ -45,23 +45,18 @@ public class ResetPasswordServlet extends HttpServlet {
String password = request.getParameter("password");
String confirmPassword = request.getParameter("password_conf");
logger.info("username: " + username);
logger.info("password: " + password);
logger.info("confirmPassword: " + confirmPassword);
if (password.equals(confirmPassword) && username != null) {
logger.info("username: " + username);
try {
ldapActions.resetPassword(username, password);
logger.info("password reseted");
logger.info("password resetted");
} catch (Exception e) {
e.printStackTrace();
request.getSession().setAttribute("message", "Error reseting password.");
response.sendRedirect("./verify.jsp");
logger.error("LDAP error" + e);
//TODO
//redirect to helpdesk error page
//request.getSession().setAttribute("message", "Error resetting password.");
//response.sendRedirect("./verify.jsp");
}
}

View File

@ -41,15 +41,6 @@ public class VerificationCodeServlet extends HttpServlet {
if (verificationActions.verificationEntryExists(formUsername, formVerificationCode)) {
//TODO check expiration date if "now" is more than 24h from the date in DB return error message
//else go to next step resetPassword.jsp
// request.setAttribute("username", formUsername);
// RequestDispatcher rd = getServletContext().getRequestDispatcher("/resetPassword.jsp");
// try {
// rd.forward(request, response);
// } catch (ServletException e) {
// logger.info("Dispatcher error" + e);
// }
HttpSession session = request.getSession();
session.setAttribute("username", formUsername);

View File

@ -51,7 +51,6 @@
<div id="registerForm">
<form action="resetPassword" method="POST" role="form" class="m-t" id="register_form" >
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<%--<input type="hidden" name="username" value="${username}"/>--%>
<div class="alert alert-success" aria-hidden="true" style="display: none;"></div>
<div class="alert alert-danger" aria-hidden="true" style="display: none;"></div>
<div class="form-group">

View File

@ -53,6 +53,7 @@
<div class="alert alert-success" aria-hidden="true" style="display: none;"></div>
<div class="alert alert-danger" aria-hidden="true" style="display: none;"></div>
<div class="form-group">
<span id="server_error" class="uk-text-danger uk-text-small uk-float-left">${message}</span>
<span class="msg_username_error uk-text-danger uk-text-small uk-float-left" style="display:none">Please enter your username.</span>
<input id="username" name="username" type="text" placeholder="Username" class="form-control"></div>
<div class="form-group">