protected void doPost(HttpServletRequest req, HttpServletResponse res) 
			throws ServletException, IOException {
		
		HttpSession session = req.getSession();
		
		String url = "/";
		
		String action = (String)req.getParameter("action");
		
		RegisterViewHelper registerViewHelper = 
				ViewHelperFactory.getInstance().getRegisterViewHelper(req);
		req.setAttribute("registerViewHelper", registerViewHelper);
		
		switch (action) {
		case "register":
			url += "Register.jsp";
			break;

		case "register-submit":
			if (registerViewHelper.containsValidCustomerDetails()
					&& !registerViewHelper.isEmailInDatabase()) {

				Customer customer = registerViewHelper.createCustomer();
				int id = DAOFactory.getInstance().getCustomerDAO()
						.insertCustomer(customer);
				customer.setId(id);
				session.setAttribute("loggedInCustomer", customer);
				
				if ("purchase".equals(req.getParameter("requestAction"))) {
					url += "purchaseController";
				}
				else {
					req.setAttribute("msg", "Hi " + customer.getForename() 
							+ ", welcome to GAMER.com !");
					req.setAttribute("link", "start shopping "
							+ "<a href=\"/GAMER/shop?action=home\">here</a>");
					url += "UserMsg.jsp";
				}
			} 
			else {
				if ("purchase".equals(req.getParameter("requestAction"))) {
					req.setAttribute("requestAction", "purchase");
				}
				url += "RegisterSubmitted.jsp";
			}
			break;
		}
		
		getServletContext().getRequestDispatcher(url).forward(req, res);
	}