/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package guestbook;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import beans.Users;

import database.DBConn;

/** 
 * MyEclipse Struts
 * Creation date: 05-21-2008
 * 
 * XDoclet definition:
 * @struts.action path="/loginGuest" name="loginGuestFrom" scope="request" validate="true"
 * @struts.action-forward name="ok" path="/ok.jsp"
 * @struts.action-forward name="err" path="err.jsp"
 */
public class LoginGuestAction extends Action {
	/*
	 * Generated Methods
	 */

	/** 
	 * Method execute
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		loginGuestFrom loginGuestFrom = (loginGuestFrom) form;// TODO Auto-generated method stub
		String check = (String)request.getSession().getAttribute("rand");
		if(loginGuestFrom.getCheckcode().equals(check))
		{
			DBConn db = new DBConn();
			Users u = db.loginGuest(loginGuestFrom.getName(), loginGuestFrom.getPwd());
			request.getSession().setAttribute("loginGuest", u);
			if(u!=null)
			{
				return mapping.findForward("ok");
			}
			else
			{
				return mapping.findForward("err");
			}
		}
		else
		{
			return mapping.findForward("err");
		}
		
		
	}
}