/*******************************************************************************
 * Copyright (c), 2001, 2002 N2 Broadband, Inc.  All Rights Reserved.
 *
 * This module contains unpublished, confidential, proprietary
 * material.  The use and dissemination of this material are
 * governed by a license.  The above copyright notice does not
 * evidence any actual or intended publication of this material.
 *
 ******************************************************************************/

package com.n2bb.login;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;



/**
 * Takes user to login page, or to home page if already logged in.
 *
 * @author kmatsuoka
 */
public class LoginAction extends Action {
	Logger logger = Logger.getLogger(LoginAction.class);
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        if (request.getUserPrincipal() == null) { // if not already logged in
            // tell the browser not to cache the login page,
            // to avoid problems with Tomcat
            response.setHeader("Cache-control", "no-cache");
            response.setHeader("Pragma", "no-cache");
            response.setDateHeader("Expires", 0);
            logger.debug("forwarding  to the login page");
            return mapping.findForward("success");
       }
        else { // if already logged in, just go to the home page
            logger.debug("Forwarding to the home page");
        	return mapping.findForward("home");
        }
    }

}

