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.RequestDispatcher;
|
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 kiatrop on 28/9/2017.
|
20
|
*/
|
21
|
public class VerificationCodeServlet 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
|
private Logger logger = Logger.getLogger(VerificationCodeServlet.class);
|
33
|
|
34
|
@Override
|
35
|
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
36
|
response.setContentType("text/html");
|
37
|
PrintWriter printWriter = response.getWriter();
|
38
|
|
39
|
String formUsername = request.getParameter("username");
|
40
|
String formVerificationCode = request.getParameter("verification_code");
|
41
|
|
42
|
if (verificationActions.verificationEntryExists(formUsername) && verificationActions.verificationCodeIsCorrect(formUsername, formVerificationCode)) {
|
43
|
if (!verificationActions.verificationCodeHasExpired(formUsername)) {
|
44
|
HttpSession session = request.getSession();
|
45
|
session.setAttribute("username", formUsername);
|
46
|
response.sendRedirect("./resetPassword.jsp");
|
47
|
} else {
|
48
|
logger.info("Verification code has expired!");
|
49
|
response.sendRedirect("./expiredVerificationCode.jsp");
|
50
|
}
|
51
|
} else {
|
52
|
request.getSession().setAttribute("message", "Username or verification code are not valid.");
|
53
|
response.sendRedirect("./verify.jsp");
|
54
|
}
|
55
|
printWriter.close();
|
56
|
|
57
|
}
|
58
|
}
|