src/java/Controllers/LoginController.java
/**
     * Handles the HTTP <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
Handles the HTTP POST method.

@param request servlet request
@param response servlet response
@throws ServletException if a servlet-specific error occurs
@throws IOException if an I/O error occurs
Handles the HTTP POST method . @param request servlet request @param response servlet response @throws ServletException if a servlet - specific error occurs @throws IOException if an I / O error occurs
@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException
    {
        String email = request.getParameter("email");
        String password = request.getParameter("password"); 
        String gRecaptchaResponse = request.getParameter("g-recaptcha-response");
        password = MD5.getMd5(password);
        if(!ReCaptchaV2.verify(gRecaptchaResponse))
        {
            request.setAttribute("message", "Captcha invalid!");
            RequestDispatcher rd=request.getRequestDispatcher("views/login.jsp");  
            rd.forward(request, response);
        }
        String[] keys = {"email", "password"};
        String[] values = {email, password};
        this.user = this.userDAO.getBy(keys, values);
        if(email.length() == 0 || password.length() == 0 || this.user == null)
        {
            request.setAttribute("message", "Enter a valid email and password!");
            RequestDispatcher rd = request.getRequestDispatcher("views/login.jsp");  
            rd.forward(request, response);
        }
        else 
        {
            HttpSession session = request.getSession();  
            session.setAttribute("user_id", this.user.getId());
            session.setAttribute("email", this.user.getEmail());
            session.setAttribute("user_type", this.user.getUserType());
            response.sendRedirect("profile");
        }
    }
@ Override protected void doPost ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { String email = request . getParameter ( "email" ) ; String password = request . getParameter ( "password" ) ; String gRecaptchaResponse = request . getParameter ( "g-recaptcha-response" ) ; password = MD5 . getMd5 ( password ) ; if ( ! ReCaptchaV2 . verify ( gRecaptchaResponse ) ) { request . setAttribute ( "message" , "Captcha invalid!" ) ; RequestDispatcher rd = request . getRequestDispatcher ( "views/login.jsp" ) ; rd . forward ( request , response ) ; } String [ ] keys = { "email" , "password" } ; String [ ] values = { email , password } ; this . user = this . userDAO . getBy ( keys , values ) ; if ( email . length ( ) == 0 || password . length ( ) == 0 || this . user == null ) { request . setAttribute ( "message" , "Enter a valid email and password!" ) ; RequestDispatcher rd = request . getRequestDispatcher ( "views/login.jsp" ) ; rd . forward ( request , response ) ; } else { HttpSession session = request . getSession ( ) ; session . setAttribute ( "user_id" , this . user . getId ( ) ) ; session . setAttribute ( "email" , this . user . getEmail ( ) ) ; session . setAttribute ( "user_type" , this . user . getUserType ( ) ) ; response . sendRedirect ( "profile" ) ; } }
Handles the HTTP <code>POST</code> method.
Handles the HTTP <code > POST< / code > method .