dnet-openaire-users/src/main/java/eu/dnetlib/openaire/usermanagement/RegisterServlet.java

71 lines
2.5 KiB
Java
Raw Normal View History

2017-10-20 14:31:39 +02:00
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 java.io.IOException;
import java.io.PrintWriter;
/**
* Created by sofia on 20/10/2017.
*/
public class RegisterServlet 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(RegisterServlet.class);
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
PrintWriter printWriter = response.getWriter();
logger.info("Mphkaaa!!!");
String firstName = request.getParameter("first_name");
String lastName = request.getParameter("last_name");
String organization = request.getParameter("organization");
String username = request.getParameter("username");
String email =request.getParameter("email");
String confirmEmail = request.getParameter("email_conf");
//String password = request.getParameter("password");
//String confirmPassword = request.getParameter("password_conf");
if (organization == null){
logger.info("organization is null");
}
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");
} catch (Exception e) {
logger.error("LDAP error in creating user", e);
response.sendRedirect("./error.jsp");
}
}
2017-10-23 15:04:57 +02:00
response.sendRedirect("./activate.jsp");
2017-10-20 14:31:39 +02:00
printWriter.close();
}
}