package com.Controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Dao.AdminLoginOperation;
import com.Dao.CustomerOperations;
import com.Model.Customer;

/**
 * Servlet implementation class Server3_customer_login
 */
@WebServlet("customerLoginReq")
public class Server3_customer_login extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Server3_customer_login() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.getWriter().append("Served at: ").append(req.getContextPath());
		
		PrintWriter out=resp.getWriter();
		
		if(req.getParameter("customer_login_btn").equalsIgnoreCase("LOGIN"))
		{

			System.out.println("Inside find csutomer function");
			Customer a = new Customer();
			
			a.setcId(req.getParameter("cid"));
			a.setcPwd(req.getParameter("cpwd"));
			
			System.out.println("***************************");
			System.out.println(a.getcId());
			System.out.println(a.getcPwd());
			System.out.println("***************************");
//			System.out.println("OUTPUT RECEIVED: "+new CustomerOperations().checkLogin(a.getEmpId(),a.getPwd()));
			if(new CustomerOperations().checkLogin(a.getcId(),a.getcPwd())>0)
			{
				resp.sendRedirect("customerDashBoard.jsp");
			}
			else
			{
				resp.sendRedirect("ErrorPage.jsp");
			}
			
			
			
		}
	}
	
}
