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

📄 cmslogin.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

            // please no GuestUsers in Workplace
            if((username != null) && (username.equals(cms.C_USER_GUEST))) {
                username = null;
                xmlTemplateDocument.setData("details", "please no guest users here");
                template = "error";
            }

            // check if a user was found.
            if(username != null) {

                // get a session for this user so that he is authentificated at the
                // end of this request
                session = cms.getRequestContext().getSession(true);
                if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
                    A_OpenCms.log(C_OPENCMS_INFO, "[CmsLogin] Login user " + username);
                }

                // now get the users preferences
                user = cms.readUser(username);

                // set current project to a default or to a specified project
                Integer currentProject = null;
                startProjectId = (String)session.getValue(C_PARA_STARTPROJECTID);
                if(startProjectId != null && (!startProjectId.equals(""))) {
                    currentProject = new Integer(startProjectId);
                    session.removeValue(C_PARA_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) {

                }
                preferences = (Hashtable)user.getAdditionalInfo(C_ADDITIONAL_INFO_PREFERENCES);

                // check if preferences are existing, otherwiese use defaults
                if(preferences == null) {
                    preferences = getDefaultPreferences();
                }
                session.putValue(C_ADDITIONAL_INFO_PREFERENCES, preferences);
            }
        }
        else {

            // This is a new login!
            // If there is an old session, remove all user variables from this session
            session = cms.getRequestContext().getSession(true);
            if(session != null) {
                String projectid = (String)session.getValue(C_PARA_STARTPROJECTID);
                String taskid = (String)session.getValue(C_PARA_STARTTASKID);
                String view = (String)session.getValue(C_PARA_VIEW);
                if(projectid == null) {
                    projectid = "";
                }
                if(taskid == null) {
                    taskid = "";
                    view = "";
                }

                //session.invalidate();
                session = cms.getRequestContext().getSession(true);
                if(!projectid.equals("")) {
                    session.putValue(C_PARA_STARTPROJECTID, projectid);
                }
                if(!taskid.equals("")) {
                    session.putValue(C_PARA_STARTTASKID, taskid);
                    session.putValue(C_PARA_VIEW, view);
                }
            }
        }

        // this is the first time the dockument is selected, so reade the page forwarding
        if(username == null) {
            xmlTemplateDocument.clearStartup();
        }
        else {
            long id = System.currentTimeMillis();
            xmlTemplateDocument.setData("ID", new Long(id).toString());
        }

        // process the selected template
        return startProcessing(cms, xmlTemplateDocument, "", parameters, template);
    }

    /**
     * Sets the default preferences for the current user if those values are not available.
     * @return Hashtable with default preferences.
     */

    private Hashtable getDefaultPreferences() {
        Hashtable pref = new Hashtable();

        // set the default columns in the filelist
        int filelist = C_FILELIST_TITLE + C_FILELIST_TYPE + C_FILELIST_CHANGED;

        // HACK
        filelist = 4095 + 512;
        pref.put(C_USERPREF_FILELIST, new Integer(filelist));
        return pref;
    }

    /**
     * Inserts the correct document title into the template.
     * This is a customized method for adding the recent version number to the title of the login screen.
     * <P>
     * This method can be called using <code>&lt;METHOD name="getTitle"&gt;</code>
     * in the template file.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent Unused in this special case of a user method. Can be ignored.
     * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
     * @param userObj Hashtable with parameters.
     * @return String or byte[] with the content of this subelement.
     * @exception CmsException
     */

    public Object getTitle(CmsObject cms, String tagcontent, A_CmsXmlContent doc,
            Object userObject) throws CmsException {
        String title = (String)super.getTitle(cms, tagcontent, doc, userObject);
        if(title == null) {
            title = "";
        }
        title = title + " - " + cms.version();
        return title;
    }

    /**
     * Inserts the correct version-number og OpenCms into the template.
     *
     * @param cms CmsObject Object for accessing system resources.
     * @param tagcontent Unused in this special case of a user method. Can be ignored.
     * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
     * @param userObj Hashtable with parameters.
     * @return String or byte[] with the content of this subelement.
     * @exception CmsException
     */

    public Object version(CmsObject cms, String tagcontent, A_CmsXmlContent doc, Object userObject) throws CmsException {
        return cms.version();
    }

    /**
     * Indicates if the results of this class are cacheable.
     *
     * @param cms CmsObject Object for accessing system resources
     * @param templateFile Filename of the template file
     * @param elementName Element name of this template in our parent template.
     * @param parameters Hashtable with all template class parameters.
     * @param templateSelector template section that should be processed.
     * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
     */

    public boolean isCacheable(CmsObject cms, String templateFile, String elementName,
            Hashtable parameters, String templateSelector) {
        return false;
    }
}

⌨️ 快捷键说明

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