package requestHandlers.mongoDB;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import requestHandlers.RequestHandler;
import Util.MongoDBUtil;

import com.mongodb.BasicDBObject;

public class registerH_mongo implements RequestHandler {

	@Override
	public void processRequest(Object user, HttpServletRequest req,
			HttpServletResponse res, Object[] services, Object log)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		String fname = req.getParameter("fname");
		String lname = req.getParameter("lname");
		String password = req.getParameter("password");
		String email = req.getParameter("email");
		String address1 = req.getParameter("address1");
		String address2 = req.getParameter("address2");
		String city = req.getParameter("city");
		String state = req.getParameter("state");
		String zip = req.getParameter("zip");
		
		BasicDBObject doc = new BasicDBObject();
		doc.put("fname", fname);
		doc.put("lname", lname);
		doc.put("password", password);
		doc.put("email", email);
		doc.put("address1", address1);
		doc.put("address2", address2);
		doc.put("city", city);
		doc.put("state", state);
		doc.put("zip", zip);
		
		if(!MongoDBUtil.addUser(doc))
		{
			res.sendRedirect("register.jsp"); 
		}
		else
		{
			res.sendRedirect("login.html"); 
		}
		
	}

}
