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

📄 onlineuserfactoryimpl.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/auth/OnlineUserFactoryImpl.java,v 1.30 2006/04/14 17:05:26 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.30 $
 * $Date: 2006/04/14 17:05:26 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2006 by MyVietnam.net
 *
 * All copyright notices regarding mvnForum MUST remain 
 * intact in the scripts and in the outputted HTML.
 * The "powered by" text/logo with a link back to
 * http://www.mvnForum.com and http://www.MyVietnam.net in 
 * the footer of the pages MUST remain visible when the pages
 * are viewed on the internet or intranet.
 *
 * 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
 * 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; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Support can be obtained from support forums at:
 * http://www.mvnForum.com/mvnforum/index
 *
 * Correspondence and Marketing Questions can be sent to:
 * info at MyVietnam net
 *
 * @author: Minh Nguyen  
 * @author: Mai  Nguyen  
 */
package com.mvnforum.auth;

import java.sql.Timestamp;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mvnforum.*;
import com.mvnforum.db.*;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.security.Encoder;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvncore.web.GenericRequest;
import net.myvietnam.mvncore.web.GenericResponse;
import net.myvietnam.mvncore.web.impl.GenericRequestServletImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class OnlineUserFactoryImpl implements OnlineUserFactory {

    private static Log log = LogFactory.getLog(OnlineUserFactoryImpl.class);

    public OnlineUserFactoryImpl() {
    }

    public OnlineUser getAuthenticatedUser(HttpServletRequest request,
                                           HttpServletResponse response,
                                           String loginName, String password,
                                           boolean isEncodedPassword)
        throws AuthenticationException, DatabaseException, AssertionException {

        GenericRequest req = new GenericRequestServletImpl(request);

        return getAuthenticatedUser(req, null, loginName, password, isEncodedPassword);
    }

    public OnlineUser getAuthenticatedUser(GenericRequest request,
                                           GenericResponse response,
                                           String loginName, String password,
                                           boolean isEncodedPassword)
        throws AuthenticationException, DatabaseException, AssertionException {

        int memberID = 0;
        double timeZone = 0;
        boolean invisible = false;
        String localeName = "";
        Timestamp lastLogon = null;
        String lastLogonIP = null;
        int postsPerPage = 10;

        try {
            memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(loginName);
        } catch (ObjectNotFoundException e) {
            throw new AuthenticationException(NotLoginException.WRONG_NAME);
        } catch (Exception e) {
            log.error("Unexpected error validating user", e);
            /** @todo find a beter one than NotLoginException.NOT_LOGIN */
            throw new AuthenticationException(NotLoginException.NOT_LOGIN);
        }

        try {
            MemberBean memberBean = DAOFactory.getMemberDAO().getMember_forViewCurrentMember(memberID);

            if (memberBean.getMemberStatus() != MemberBean.MEMBER_STATUS_ENABLE) {
                if (memberID != MVNForumConstant.MEMBER_ID_OF_ADMIN) {// Admin cannot be disabled
                    throw new AuthenticationException(NotLoginException.ACCOUNT_DISABLED);
                }
            }
            boolean disablePortlet = !MVNForumConfig.getEnablePortlet(); 
            if (disablePortlet) {
            
                if (DAOFactory.getMemberDAO().getActivateCode(memberID).equals(MemberBean.MEMBER_ACTIVATECODE_ACTIVATED) == false) {
                    // not activated
                    if (MVNForumConfig.getRequireActivation()) {
                        if (memberID != MVNForumConstant.MEMBER_ID_OF_ADMIN) {// Admin dont have to activate to login
                            throw new AuthenticationException(NotLoginException.NOT_ACTIVATED);
                        }
                    }
                }
    
                if (validatePassword(loginName, password, isEncodedPassword) == false) {
                    if ((MVNForumConfig.getEnablePasswordlessAuth() == false) || (password.length() > 0)) {
                        throw new AuthenticationException(NotLoginException.WRONG_PASSWORD);
                    }
                }
    
                // now we have checked the authentication, then we update the lastlogon date
                Timestamp now = DateUtil.getCurrentGMTTimestamp();
    
                DAOFactory.getMemberDAO().updateLastLogon(memberID, now, request.getRemoteAddr());
            }
            timeZone = memberBean.getMemberTimeZone();
            localeName = memberBean.getMemberLanguage();
            lastLogon = memberBean.getMemberLastLogon();
            postsPerPage = memberBean.getMemberPostsPerPage();
            lastLogonIP = memberBean.getMemberLastIP();
            invisible  = memberBean.isInvisible();

            // next, get the correct name from database
            // Eg: if in database the MemberName is "Admin", and user enter "admin"
            // We will convert "admin" to "Admin"
            String memberName = memberBean.getMemberName();

            OnlineUserImpl authenticatedUser = new OnlineUserImpl(request, false/*isGuest*/);
            authenticatedUser.setMemberID(memberID);
            authenticatedUser.setMemberName(memberName);
            authenticatedUser.setInvisible(invisible);
            authenticatedUser.setTimeZone(timeZone);
            //NOTE: This MUST be the only way to get permission for a member,
            // so we prevent getPermission for one user and set for other user
            // Note: this method might throw AssertionException
            MVNForumPermission permission = MVNForumPermissionFactory.getAuthenticatedPermission(memberID);
            authenticatedUser.setPermission(permission);
            authenticatedUser.setLocaleName(localeName);
            authenticatedUser.setLastLogonTimestamp(lastLogon);
            authenticatedUser.setLastLogonIP(lastLogonIP);
            authenticatedUser.setGender(memberBean.getMemberGender() != 0);
            authenticatedUser.setPostsPerPage(postsPerPage);

            if (MVNForumConfig.getEnableCompany()) {
                try {
                    int companyID = DAOFactory.getMemberCompanyDAO().getCompanyIDFromMemberID(memberID);
                    CompanyBean companyBean = DAOFactory.getCompanyDAO().getCompany(companyID);

                    // Load the css Path for this user
                    String cssPath = MyUtil.getCompanyCssPath(companyBean, request.getContextPath());
                    authenticatedUser.setCssPath(cssPath);

                    // Load the logo Path for this user
                    String logoPath = MyUtil.getCompanyLogoPath(companyBean, request.getContextPath());
                    authenticatedUser.setLogoPath(logoPath);
                } catch (ObjectNotFoundException ex) {
                    // not belong to a company, just ignore
                }
            }

            return authenticatedUser;
        } catch (ObjectNotFoundException e) {
            throw new AuthenticationException(NotLoginException.WRONG_NAME);//we dont want this line to happen

⌨️ 快捷键说明

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