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

📄 cmslogin.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* File   : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsLogin.java,v $
* Date   : $Date: 2001/07/31 15:50:19 $
* Version: $Revision: 1.43 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001  The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org 
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

package com.opencms.workplace;

import com.opencms.file.*;
import com.opencms.core.*;
import com.opencms.util.*;
import com.opencms.template.*;
import javax.servlet.http.*;
import java.util.*;

/**
 * Template class for displaying the login screen of the OpenCms workplace.<P>
 * Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
 *
 * @author Waruschan Babachan
 * @version $Revision: 1.43 $ $Date: 2001/07/31 15:50:19 $
 */

public class CmsLogin extends CmsWorkplaceDefault implements I_CmsWpConstants,I_CmsConstants {

    /**
     * Overwrtied the getContent method of the CmsWorkplaceDefault.<br>
     * Gets the content of the longin templated and processed the data input.
     * If the user has authentificated to the system, the login window is closed and
     * the workplace is opened. <br>
     * If the login was incorrect, an error message is displayed and the login
     * dialog is displayed again.
     * @param cms The CmsObject.
     * @param templateFile The login template file
     * @param elementName not used
     * @param parameters Parameters of the request and the template.
     * @param templateSelector Selector of the template tag to be displayed.
     * @return Bytearre containgine the processed data of the template.
     * @exception Throws CmsException if something goes wrong.
     */

    public byte[] getContent(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) throws CmsException {
        String username = null;
        I_CmsSession session = null;
        CmsUser user;
        CmsXmlWpConfigFile configFile = new CmsXmlWpConfigFile(cms);
        String actionPath = configFile.getWorkplaceActionPath();
        String startTaskId = (String)parameters.get(C_PARA_STARTTASKID);
        String startProjectId = (String)parameters.get(C_PARA_STARTPROJECTID);
        if(startTaskId == null) {
            startTaskId = "";
        }
        if(startProjectId == null) {
            startProjectId = "";
        }
        if(!startProjectId.equals("")) {
            session = cms.getRequestContext().getSession(true);
            session.putValue(C_PARA_STARTPROJECTID, startProjectId);
        }

        // check if this is a link of a task
        if(!startTaskId.equals("")) {
            session = cms.getRequestContext().getSession(true);
            session.putValue(C_PARA_STARTTASKID, startTaskId);
            Vector viewNames = new Vector();
            Vector viewLinks = new Vector();

            //configFile.getWorkplaceIniData(viewNames, viewLinks,"WORKPLACEVIEWS","VIEW");
            (cms.getRegistry()).getViews(viewNames, viewLinks);
            String link = "";
            for(int i = 0;i < viewNames.size();i++) {
                if(((String)viewNames.elementAt(i)).equals("select.tasks")) {
                    link = (String)viewLinks.elementAt(i);
                    break;
                }
            }
            session.putValue(C_PARA_VIEW, link);
        }

        // Indicates, if this is a request of a guest user.
        if(!cms.anonymousUser().equals(cms.getRequestContext().currentUser())
                && (!startTaskId.equals(""))) {

            // set current project to a default or to a specified project
            Integer currentProject = null;
            session.removeValue(C_PARA_STARTPROJECTID);
            if(!startProjectId.equals("")) {
                currentProject = new Integer(startProjectId);
                boolean access = true;
                try {
                    access = cms.accessProject(currentProject.intValue());
                }
                catch(Exception e) {
                    access = false;
                }
                if(!access) {

                    // check out the user information if a default project is stored there.
                    Hashtable startSettings = (Hashtable)cms.getRequestContext().currentUser().getAdditionalInfo(C_ADDITIONAL_INFO_STARTSETTINGS);
                    if(startSettings != null) {
                        currentProject = (Integer)startSettings.get(C_START_PROJECT);
                    }
                }
            }
            else {

                // check out the user information if a default project is stored there.
                Hashtable startSettings = (Hashtable)cms.getRequestContext().currentUser().getAdditionalInfo(C_ADDITIONAL_INFO_STARTSETTINGS);
                if(startSettings != null) {
                    currentProject = (Integer)startSettings.get(C_START_PROJECT);
                }
            }
            try {
                if(cms.accessProject(currentProject.intValue())) {
                    cms.getRequestContext().setCurrentProject(currentProject.intValue());
                }
            }
            catch(Exception e) {

            }
            try {
                cms.getRequestContext().getResponse().sendCmsRedirect(actionPath
                        + "index.html");

                // return "".getBytes();
                return null;
            }
            catch(Exception e) {
                throw new CmsException(e.getMessage());
            }
        }

        // the template to be displayed
        String template = templateSelector;
        CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms,
                templateFile);
        Hashtable preferences = new Hashtable();

        // get user name and password
        String name = (String)parameters.get("NAME");
        String password = (String)parameters.get("PASSWORD");

        // try to read this user
        if((name != null) && (password != null)) {
            try {
                username = cms.loginUser(name, password);
            }
            catch(CmsException e) {
                if((e.getType() == CmsException.C_NO_USER) || (e.getType()
                        == CmsException.C_NO_ACCESS)) {

                    // there was an authentification error during login
                    // set user to null and switch to error template
                    username = null;
                    xmlTemplateDocument.setData("details", Utils.getStackTrace(e));
                    template = "error";
                }
                else {
                    throw e;
                }
            }

⌨️ 快捷键说明

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