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

📄 onlineuserfactory.java

📁 easy to use, easy to setup bulletin board (forum)
💻 JAVA
字号:
/*
 * Copyright (C) 2002 by MyVietnam.net
 *
 * 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.
 *
 * 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 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@MyVietnam.net
 *
 * @author: Minh Nguyen  minhnn@MyVietnam.net
 * @author: Mai  Nguyen  mai.nh@MyVietnam.net
 */
package net.myvietnam.mvnplugin.mvnforum.auth;

import java.sql.Timestamp;
import net.myvietnam.mvncore.exception.NotLoginException;
import net.myvietnam.mvncore.exception.DatabaseException;
import net.myvietnam.mvncore.exception.AssertionException;
import net.myvietnam.mvncore.exception.BadInputException;
import net.myvietnam.mvncore.util.DateUtil;
import net.myvietnam.mvnplugin.mvnforum.db.MemberBean;
import net.myvietnam.mvnplugin.mvnforum.MVNForumConstant;

class OnlineUserFactory {

    //private static OnlineUser anonymousUser = null;

    private OnlineUserFactory() {
    }

    public static OnlineUser getAuthenticatedUser(String memberName, String encodedPassword)
        throws AuthenticationException, DatabaseException, AssertionException {

        int memberID = 0;
        int timeZone = 0;

        try {
            memberID = MemberWebHelper.getMemberIDFromMemberName(memberName);
        } catch (BadInputException e) {
            throw new AuthenticationException(NotLoginException.WRONG_NAME);
        } catch (Exception e) {
            /** @todo find a beter one than NotLoginException.NOT_LOGIN */
            throw new AuthenticationException(NotLoginException.NOT_LOGIN);
        }

        try {

            MemberBean memberBean = MemberWebHelper.getMember_forViewCurrentMember(memberID);
            /*
            if (memberBean.getMemberStatus() == 0) {
                throw new AuthenticationException(NotLoginException.ACCOUNTDISABLED);
            }*/

            if (!encodedPassword.equals(MemberWebHelper.getMemberPassword(memberID))) {
                throw new AuthenticationException(NotLoginException.WRONG_PASSWORD);
            }

            // now we have checked the authentication, then we update the lastlogon date
            timeZone = memberBean.getMemberTimeZone();
            Timestamp now = DateUtil.getCurrentGMTTimestamp();
            MemberWebHelper.updateMemberLastLogon(memberID, now);
        } catch (BadInputException e) {
            throw new AuthenticationException(NotLoginException.NOT_LOGIN);//we dont want this line to happen
        } catch (DatabaseException e) {
            throw new AuthenticationException(NotLoginException.NOT_LOGIN);//we dont want this line to happen
        }

        OnlineUserImpl user = new OnlineUserImpl();
        user.setMemberID(memberID);
        user.setMemberName(memberName);
        user.setHourOffset(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
        MVNForumPermission permission = MVNForumPermissionFactory.getAuthenticatedPermission(memberID);
        user.setPermission(permission);
        return user;
    }

    public static synchronized OnlineUser getAnonymousUser()
        throws DatabaseException, AssertionException {

        OnlineUserImpl anonymousUser = new OnlineUserImpl();
        anonymousUser.setMemberID(0);
        anonymousUser.setMemberName(MVNForumConstant.MEMBER_GUEST_NAME);
        MVNForumPermission permission = MVNForumPermissionFactory.getAnonymousPermission();
        anonymousUser.setPermission(permission);

        return anonymousUser;
    }

    /*
    static synchronized void reloadAnonymousUser()
        throws DatabaseException, AssertionException {
        OnlineUserImpl user = new OnlineUserImpl();
        user.setMemberID(0);
        user.setMemberName(MVNForumConstant.MEMBER_GUEST_NAME);
        MVNForumPermission permission = MVNForumPermissionFactory.getAnonymousPermission();
        user.setPermission(permission);

        anonymousUser = user;
    }*/
}

⌨️ 快捷键说明

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