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;
import edu.uprm.ece.icom5016.util.ActiveAccounts;

/**
 * @version 	1.0
 * @author
 */
public class NewAccountServlet 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 {
		//Create a new account
		String user = req.getParameter("name");
		Customer new_cust = new Customer(user);
		ActiveAccounts.addActiveCustomer(new_cust);
		//Get new session for this client
		HttpSession session = req.getSession(true);
		session.setAttribute("message", "Thank you for creating an account with us");
		session.setAttribute("link", "/icom5016/login.jsp");
		session.setAttribute("link_message", "Login");
		resp.sendRedirect("/icom5016/thanks.jsp");
		//RequestDispatcher dispatcher = req.getRequestDispatcher("/thanks.jsp");
		//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 {
		this.doGet(req, resp);
	}

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

		super.init();

	}

}
