Project

General

Profile

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, formVerificationCode)) {
43
            //TODO check expiration date if "now" is more than 24h from the date in DB return error message
44
            
45
            HttpSession session = request.getSession();
46
            session.setAttribute("username", formUsername);
47

    
48
            response.sendRedirect("./resetPassword.jsp");
49
            printWriter.close();
50

    
51
        } else {
52
            request.getSession().setAttribute("message", "Username or verification code are not valid.");
53
            response.sendRedirect("./verify.jsp");
54
            // response.sendRedirect("./error.jsp"); or write a message in the session
55
        }
56

    
57
    }
58
}
(4-4/4)