Add AddPasswordServlet.java
This commit is contained in:
parent
74b51ab29e
commit
484676ad24
|
@ -0,0 +1,63 @@
|
|||
package eu.dnetlib.openaire.usermanagement;
|
||||
|
||||
import eu.dnetlib.openaire.user.utils.LDAPActions;
|
||||
import eu.dnetlib.openaire.user.utils.VerificationActions;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Created by sofia on 23/10/2017.
|
||||
*/
|
||||
public class AddPasswordServlet extends HttpServlet {
|
||||
|
||||
public void init(ServletConfig config) throws ServletException {
|
||||
super.init(config);
|
||||
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
|
||||
config.getServletContext());
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private VerificationActions verificationActions;
|
||||
|
||||
@Autowired
|
||||
private LDAPActions ldapActions;
|
||||
|
||||
private Logger logger = Logger.getLogger(AddPasswordServlet.class);
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
response.setContentType("text/html");
|
||||
PrintWriter printWriter = response.getWriter();
|
||||
|
||||
HttpSession session = request.getSession();
|
||||
String username = (String) session.getAttribute("username");
|
||||
|
||||
String password = request.getParameter("password");
|
||||
String confirmPassword = request.getParameter("password_conf");
|
||||
|
||||
if (password.equals(confirmPassword) && username != null) {
|
||||
try {
|
||||
ldapActions.resetPassword(username, password);
|
||||
logger.info("password added");
|
||||
} catch (Exception e) {
|
||||
logger.error("LDAP error in adding password", e);
|
||||
response.sendRedirect("./error.jsp");
|
||||
}
|
||||
}
|
||||
|
||||
session.removeAttribute("username");
|
||||
response.sendRedirect("./success.jsp");
|
||||
printWriter.close();
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue