package edu.uprm.ece.icom5016.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import edu.uprm.ece.icom5016.bean.Customer;

/**
 * @version 	1.0
 * @author
 */
public class CheckoutServlet extends HttpServlet {

	/**
	* @see javax.servlet.GenericServlet#void ()
	*/
	public void destroy() {

		super.destroy();

	}

	/**
	* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	*/
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		String red_url;
		//RequestDispatcher dispatcher = null;//req.getRequestDispatcher()
		HttpSession session = req.getSession();
		//check if the user is logged
		Customer cust = (Customer) session.getAttribute("customer");
		if(cust == null){
			//user is not logged
			session.setAttribute("checkout", "checkout");
			//req.setAttribute("checkout", "checkout");
			red_url = "/icom5016/login.jsp";
			//dispatcher = req.getRequestDispatcher("/login.jsp");
		}else{
			red_url = "/icom5016/checkout.jsp";
			//dispatcher = req.getRequestDispatcher("/checkout.jsp");
		}
		resp.sendRedirect(red_url);
		//dispatcher.forward(req, resp);
	}

	/**
	* @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	*/
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		doGet(req, resp);
	}

	/**
	* @see javax.servlet.GenericServlet#void ()
	*/
	public void init() throws ServletException {

		super.init();

	}

}
