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