package com.Controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;

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.Model.Admin;


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

	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		resp.getWriter().append("Served at: ").append(req.getContextPath());
		
		PrintWriter out=resp.getWriter();
		
		if(req.getParameter("admin_login_btn").equalsIgnoreCase("LOGIN"))
		{

			System.out.println("Inside find admin function");
			Admin a = new Admin();
			
			a.setEmpId(Integer.parseInt(req.getParameter("eid")));
			a.setPwd(req.getParameter("epwd"));
			
			System.out.println("***************************");
			System.out.println(a.getEmpId());
			System.out.println(a.getPwd());
			System.out.println("***************************");
			System.out.println("OUTPUT RECEIVED: "+new AdminLoginOperation().checkLogin(a.getEmpId(),a.getPwd()));
			if(new AdminLoginOperation().checkLogin(a.getEmpId(),a.getPwd())>0)
			{
				resp.sendRedirect("adminDashBoard.jsp");
			}
			else
			{
				resp.sendRedirect("ErrorPage.jsp");
			}
			
			
			
		}
	}

}
