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

📄 memberwebhandler.java

📁 解觖java技术中后台无法上传数给的情况
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        MemberBean memberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
        if (!memberEmail.equalsIgnoreCase(memberBean.getMemberEmail())) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.provided_email_not_equals_member_email");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Your provided email does not equals to the member's email in our database. Please try again.");
        }

        // end check, send mail now
        String serverName = ParamUtil.getServerPath();//ParamUtil.getServer2(request);
        SendMailUtil.sendActivationCodeEmail(memberID, serverName);
    }

    public void activateMember(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException,
        AuthenticationException, AssertionException {

        String memberName = GenericParamUtil.getParameter(request, "member", true);
        StringUtil.checkGoodName(memberName);
        Locale locale = I18nUtil.getLocaleInRequest(request);

        // IMPORTANT: MUST check that ActivateCode is not empty, because ActivateCode = empty
        // means invalid
        String memberActivateCode = GenericParamUtil.getParameter(request, "activatecode", true);
        if (memberActivateCode.equals(MemberBean.MEMBER_ACTIVATECODE_ACTIVATED)) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_activate.invalid_activation_code");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot activate member with invalid activation code.");
        }
        int memberID = 0;
        try {
            memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.membername_not_exists", new Object[] {memberName});
            throw new ObjectNotFoundException(localizedMessage);
        }

        // Now, check that this member is not activated, to prevent the
        // situation that other people try to annoy this member
        if (DAOFactory.getMemberDAO().getActivateCode(memberID).equals(MemberBean.MEMBER_ACTIVATECODE_ACTIVATED)) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_activate.is_activated_member");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Cannot activate an activated member.");
        }

        String currentActivateCode = DAOFactory.getMemberDAO().getActivateCode(memberID);
        if (memberActivateCode.equals(currentActivateCode) == false) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_activate.wrong_activation_code");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("Your activation code is not correct, please try the Member Account Activation feature.");
        }

        DAOFactory.getMemberDAO().updateActivateCode(memberID, MemberBean.MEMBER_ACTIVATECODE_ACTIVATED);// activate member

        // now reload the permission if this online user is the activated user
        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        if (memberID == onlineUser.getMemberID()) {
            onlineUser.reloadPermission();
        }
    }

/*************************************************
 * For public view
 *************************************************/
    public void prepareView_forPublic(GenericRequest request)
        throws BadInputException, ObjectNotFoundException, DatabaseException {

        String memberName = GenericParamUtil.getParameter(request, "member", false);
        Locale locale = I18nUtil.getLocaleInRequest(request);
        // primary key column(s)
        int memberID = -1;
        if (memberName.length() == 0) {
            memberID = GenericParamUtil.getParameterInt(request, "memberid");
        } else {// has MemberName
            /**@todo: improve this for better performance(dont use this method,
             * and write 2 new methods)*/
            StringUtil.checkGoodName(memberName);// check for better security
            try {
                memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
            } catch (ObjectNotFoundException e) {
                String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.membername_not_exists", new Object[] {memberName});
                throw new ObjectNotFoundException(localizedMessage);
            }
        }

        try {
            DAOFactory.getMemberDAO().increaseViewCount(memberID);
        } catch (ObjectNotFoundException e) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
            throw new ObjectNotFoundException(localizedMessage);
        }

        MemberBean memberBean = DAOFactory.getMemberDAO().getMember_forPublic(memberID);

        request.setAttribute("MemberBean", memberBean);
    }

    /**
     * This method supports sorting base on many criteria
     */
    public void prepareListMembers_forPublic(GenericRequest request)
        throws DatabaseException, AssertionException, BadInputException, AuthenticationException {

        Locale locale = I18nUtil.getLocaleInRequest(request);
        if (MVNForumConfig.getEnableListMembers() == false) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.AssertionException.list_members_is_disabled");
            throw new AssertionException(localizedMessage);
            //throw new AssertionException("Cannot list members because LIST_MEMBERS feature is disabled by administrator.");
        }

        OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
        //MVNForumPermission permission = onlineUser.getPermission();
        //@todo: some permission checking is needed ???

        // for sort and order stuff
        String sort  = GenericParamUtil.getParameter(request, "sort");
        String order = GenericParamUtil.getParameter(request, "order");
        if (sort.length() == 0) sort = "MemberCreationDate";
        if (order.length()== 0) order = "DESC";

        // we continue
        int postsPerPage = onlineUser.getPostsPerPage();
        int offset = 0;
        try {
            offset = GenericParamUtil.getParameterInt(request, "offset");
        } catch (BadInputException e) {
            // do nothing
        }

        int totalMembers = DAOFactory.getMemberDAO().getNumberOfMembers();
        if (offset > totalMembers) {
            String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.offset_greater_than_total_rows");
            throw new BadInputException(localizedMessage);
            //throw new BadInputException("The offset is not allowed to be greater than total rows.");
        }

        Collection memberBeans = DAOFactory.getMemberDAO().getMembers_withSortSupport_limit(offset, postsPerPage, sort, order);

        request.setAttribute("MemberBeans", memberBeans);
        request.setAttribute("TotalMembers", new Integer(totalMembers));
    }

    // just for showing member's avatar
    public void getAvatar(HttpServletRequest request, HttpServletResponse response)
        throws BadInputException, DatabaseException, IOException {

        if (MVNForumConfig.getEnableAvatar() == false) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }

        int memberID = ParamUtil.getParameterInt(request, "memberid");

        MemberBean member = null;
        try {
            member = DAOFactory.getMemberDAO().getMember_forPublic(memberID);
        } catch (ObjectNotFoundException e) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        
        String memberAvatar = member.getMemberAvatar();
        if (memberAvatar.equals(MemberBean.MEMBER_AVATAR_USING_UPLOAD) ||
            memberAvatar.startsWith(BinaryStorage.BINARY_STORAGE)||
            memberAvatar.startsWith(MVNForumGlobal.UPLOADED_AVATAR_DIR)) {
            memberAvatar = member.getMemberName() + ".jpg";
        } else {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
            return;
        }
        String imageMimeType = "image/jpeg";

        File avatarFile = new File(MVNForumConfig.getAvatarDir() + File.separator + memberAvatar);
        if (!avatarFile.exists()) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
        if (!avatarFile.isFile()) {
            response.sendError(HttpServletResponse.SC_NO_CONTENT);
            return;
        }

        long lastModified = avatarFile.lastModified();
        long ifModifiedSince = request.getDateHeader("If-Modified-Since");
        //log.debug("\n ** Last Modified : " + lastModified + " If Modified Since : " + ifModifiedSince + " **");
        if (ifModifiedSince != -1) {
            if (/*(request.getHeader("If-None-Match") == null)
                && */(lastModified <= ifModifiedSince )) {
                // The entity has not been modified since the date
                // specified by the client. This is not an error case.
                response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
                return;
            }
        }

        OutputStream outputStream = null;
        try {
            String httpModified = DateUtil.getHTTPHeaderTime(new Date(lastModified));
            response.setContentType(imageMimeType);
            response.setHeader("Location", memberAvatar);
            response.setHeader("Last-Modified", httpModified);
            //response.setHeader("Content-Disposition", "attachment; filename=" + memberAvatar);//always download
            //response.setHeader("Content-Length", String.valueOf(avatarFile.length()));//problem with compression

            // now, the header inited, just write the file content on the output
            try {
                outputStream = response.getOutputStream();
                //FileUtil.popFile(avatarFile, outputStream);
                BinaryStorage binaryStorage = ManagerFactory.getBinaryStorage();
                InputStream inputStream = binaryStorage.getInputStream(BinaryStorage.CATEGORY_AVATAR, String.valueOf(memberID), null);
                IOUtils.copy(inputStream, outputStream);
            } catch (IOException ex) {
                // CANNOT throw Exception after we output to the response
                log.error("Error while trying to send avatar from server", ex);
            }

            outputStream.flush();
            outputStream.close();
            outputStream = null;// no close twice
        } catch (IOException ex) {
            throw ex;
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException ex) { }
            }
        }
    }
}

⌨️ 快捷键说明

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