1
|
package eu.dnetlib.openaire.usermanagement;
|
2
|
|
3
|
import eu.dnetlib.openaire.user.utils.LDAPActions;
|
4
|
import eu.dnetlib.openaire.user.utils.VerificationActions;
|
5
|
import org.apache.log4j.Logger;
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
7
|
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
|
8
|
|
9
|
import javax.servlet.ServletConfig;
|
10
|
import javax.servlet.ServletException;
|
11
|
import javax.servlet.http.HttpServlet;
|
12
|
import javax.servlet.http.HttpServletRequest;
|
13
|
import javax.servlet.http.HttpServletResponse;
|
14
|
import javax.servlet.http.HttpSession;
|
15
|
import java.io.IOException;
|
16
|
import java.io.PrintWriter;
|
17
|
|
18
|
/**
|
19
|
* Created by sofia on 23/10/2017.
|
20
|
*/
|
21
|
public class ActivationCodeServlet extends HttpServlet{
|
22
|
|
23
|
public void init(ServletConfig config) throws ServletException {
|
24
|
super.init(config);
|
25
|
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this,
|
26
|
config.getServletContext());
|
27
|
}
|
28
|
|
29
|
@Autowired
|
30
|
private VerificationActions verificationActions;
|
31
|
|
32
|
@Autowired
|
33
|
private LDAPActions ldapActions;
|
34
|
|
35
|
|
36
|
private Logger logger = Logger.getLogger(ActivationCodeServlet.class);
|
37
|
|
38
|
@Override
|
39
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
40
|
response.setContentType("text/html");
|
41
|
PrintWriter printWriter = response.getWriter();
|
42
|
|
43
|
String formUsername = request.getParameter("username");
|
44
|
String formVerificationCode = request.getParameter("verification_code");
|
45
|
|
46
|
if (verificationActions.verificationEntryExists(formUsername) && verificationActions.verificationCodeIsCorrect(formUsername, formVerificationCode)) {
|
47
|
if (!verificationActions.verificationCodeHasExpired(formUsername)) {
|
48
|
HttpSession session = request.getSession();
|
49
|
session.setAttribute("username", formUsername);
|
50
|
try {
|
51
|
ldapActions.moveUser(formUsername);
|
52
|
} catch (Exception e) {
|
53
|
logger.error("LDAP error in moving user", e);
|
54
|
response.sendRedirect("./error.jsp");
|
55
|
}
|
56
|
response.sendRedirect("./registerSuccess.jsp");
|
57
|
} else {
|
58
|
logger.info("Verification code has expired!");
|
59
|
response.sendRedirect("./expiredVerificationCode.jsp");
|
60
|
}
|
61
|
} else {
|
62
|
request.getSession().setAttribute("message", "Username or activation code are not valid.");
|
63
|
response.sendRedirect("./activate.jsp");
|
64
|
}
|
65
|
printWriter.close();
|
66
|
|
67
|
}
|
68
|
}
|