⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginaction.java

📁 老外的在线考试
💻 JAVA
字号:
/* * CyberTester - J2EE Web application for creating, delivering and managing tests/exams/surveys.  * Copyright (C) 2004 CyberDemia Research and Services Pty Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (see the file COPYING); if not, write to the * Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * * See the COPYING file located in the top-level-directory of * the archive of this program for complete text of license. */package com.cyberdemia.cybertester;import javax.servlet.*;import javax.servlet.http.*;import org.apache.struts.action.*;import com.cyberdemia.cybertester.Constants;import com.cyberdemia.user.*;import java.text.DateFormat;import java.util.Date;import java.util.HashMap;/** *  * LoginAction is a Struts action that performs login to CyberTester. * Responsible for setting up various session-wide objects such as login ID. *  * @version $Revision: 1.4 $ at $Date: 2004/03/15 09:56:27 $ by $Author: alexycyap $ * @author Alexander Yap */public final class LoginAction extends Action{	public ActionForward execute(ActionMapping mapping, ActionForm form,		HttpServletRequest request, HttpServletResponse response)		throws Exception	{		String userLogin = request.getRemoteUser();		if (userLogin==null)		{			throw new ServletException("No user has been authenticated.");		}		CyberTesterUtils.getLogger().info("Logging in user identity="+userLogin);		// Creates new session and store the user name		HttpSession session = request.getSession(true);		session.setAttribute(Constants.USER_LOGIN_KEY, userLogin );		session.setAttribute(Constants.LOGIN_TIME_KEY, DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(new Date()) );		session.setAttribute(Constants.CHARTS_CACHE_KEY, new HashMap());		UserManagerHome userMgrHome = CyberTesterUtils.getUserManagerHome();		ActionErrors errors = new ActionErrors();				UserManager userMgr = (UserManager)userMgrHome.create();		UserData userData = userMgr.getUserDataByLogin(userLogin, false);		if (userData!=null)		{			Integer userId = userData.getId();			session.setAttribute(Constants.USER_ID_KEY, userId );		}		else		{			errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("login.user.unknown", userLogin));		}		if (!errors.isEmpty())		{			CyberTesterUtils.getLogger().warning("Failed to login user "+userLogin);			saveErrors(request, errors);			return mapping.findForward(Constants.ERROR);		}				String target = Constants.ERROR;		if (request.isUserInRole("admin"))		{			target = "admin";			session.setAttribute(Constants.IS_ADMINISTRATOR_KEY, Boolean.TRUE);					CyberTesterUtils.getLogger().info("Administrator "+userLogin+" logged in.");		}        /*        else if (request.isUserInRole("tester"))        {            target = "tester";        }        */		else if (request.isUserInRole("testee"))		{			target = "testee";		}		return (mapping.findForward(target));	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -