/projects/mvnforum-1.2.2-ga/mvnforum/src/com/mvnforum/admin/MemberWebHandler.java
Java | 847 lines | 630 code | 130 blank | 87 comment | 105 complexity | 409dc1306e3ee4389e0c2b838350f368 MD5 | raw file
- /*
- * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/MemberWebHandler.java,v 1.165.2.2 2008/11/18 08:27:37 nguyendnc Exp $
- * $Author: nguyendnc $
- * $Revision: 1.165.2.2 $
- * $Date: 2008/11/18 08:27:37 $
- *
- * ====================================================================
- *
- * Copyright (C) 2002-2007 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
- * @author: Igor Manic
- */
- package com.mvnforum.admin;
-
- import java.io.File;
- import java.io.IOException;
- import java.sql.Date;
- import java.sql.Timestamp;
- import java.util.*;
-
- import net.myvietnam.mvncore.MVNCoreResourceBundle;
- import net.myvietnam.mvncore.exception.*;
- import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
- import net.myvietnam.mvncore.interceptor.InterceptorService;
- import net.myvietnam.mvncore.security.Encoder;
- import net.myvietnam.mvncore.security.SecurityUtil;
- import net.myvietnam.mvncore.service.EventLogService;
- import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
- import net.myvietnam.mvncore.util.*;
- import net.myvietnam.mvncore.web.GenericRequest;
- import net.myvietnam.mvncore.web.GenericResponse;
-
- import org.apache.commons.logging.Log;
- import org.apache.commons.logging.LogFactory;
-
- import com.mvnforum.*;
- import com.mvnforum.auth.*;
- import com.mvnforum.categorytree.*;
- import com.mvnforum.common.*;
- import com.mvnforum.db.*;
- import com.mvnforum.search.member.MemberIndexer;
- import com.mvnforum.search.member.MemberSearchQuery;
- import com.mvnforum.service.*;
-
- public class MemberWebHandler {
-
- private static final Log log = LogFactory.getLog(MemberWebHandler.class);
-
- private OnlineUserManager onlineUserManager = OnlineUserManager.getInstance();
-
- private static CategoryService categoryService = MvnForumServiceFactory.getMvnForumService().getCategoryService();
-
- private static CategoryBuilderService categoryBuilderService = MvnForumServiceFactory.getMvnForumService().getCategoryBuilderService();
-
- private static EventLogService eventLogService = MvnCoreServiceFactory.getMvnCoreService().getEventLogService();
-
- public MemberWebHandler() {
- }
-
- public void prepareAdd(GenericRequest request) throws AuthenticationException, DatabaseException {
-
- if (MVNForumConfig.getEnableExternalUserDatabase()) {
- Locale locale = I18nUtil.getLocaleInRequest(request);
-
- String localizedMessage = MVNForumResourceBundle.getString(locale, "java.lang.IllegalStateException.create_user_is_disabled");
- throw new IllegalStateException(localizedMessage);
- //throw new IllegalStateException("Cannot create user if we enable external user database.");
- }
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanAdminSystem();
- }
-
- public void processAdd(GenericRequest request)
- throws BadInputException, ObjectNotFoundException, CreateException, DatabaseException,
- DuplicateKeyException, ForeignKeyNotFoundException, AuthenticationException, InterceptorException {
-
- Locale locale = I18nUtil.getLocaleInRequest(request);
-
- if (MVNForumConfig.getEnableExternalUserDatabase()) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "java.lang.IllegalStateException.create_user_is_disabled");
- throw new IllegalStateException(localizedMessage);
- //throw new IllegalStateException("Cannot create user if we enable external user database.");
- }
-
- SecurityUtil.checkHttpPostMethod(request);
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanAdminSystem();
-
- Timestamp now = DateUtil.getCurrentGMTTimestamp();
-
- String memberName = GenericParamUtil.getParameterSafe(request, "MemberName", true); // check good name
- /** @todo move to a name filter */
- if ( memberName.equalsIgnoreCase(MVNForumConfig.getDefaultGuestName()) ||
- memberName.equalsIgnoreCase("Guest") ||
- memberName.equalsIgnoreCase("Administrator") ||
- memberName.equalsIgnoreCase("Moderator") ) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_register_with_reserved_name", new Object[] {memberName});
- throw new BadInputException(localizedMessage);
- //throw new BadInputException("Cannot register member with a reserved name : " + memberName);
- }
- StringUtil.checkGoodName(memberName);
- InterceptorService.getInstance().validateLoginID(memberName);
- if (memberName.length() > MVNForumGlobal.MAX_MEMBER_LOGIN_LENGTH) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.member_name_too_long");
- throw new BadInputException(localizedMessage);
- //throw new BadInputException("MemberName cannot be longer than 30 characters.");
- }
-
- String memberPassword1 = GenericParamUtil.getParameterPassword(request, "MemberMatkhau", 3, 0);
- String memberPassword2 = GenericParamUtil.getParameterPassword(request, "MemberMatkhauConfirm", 3, 0);
-
- InterceptorService.getInstance().validatePassword(memberPassword1);
-
- if (!memberPassword1.equals(memberPassword2)) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.confirmed_password_is_not_match");
- throw new BadInputException(localizedMessage);
- //throw new BadInputException("Password and confirmed password are not the same, please try again.");
- }
- String memberPassword = Encoder.getMD5_Base64(memberPassword1);
-
- String memberEmail = GenericParamUtil.getParameterEmail(request, "MemberEmail");
- String memberEmailConfirm = GenericParamUtil.getParameterEmail(request, "MemberEmailConfirm");
- if (!memberEmail.equals(memberEmailConfirm)) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.confirmed_email_is_not_match");
- throw new BadInputException(localizedMessage);
- //throw new BadInputException("Email and confirmed email are not the same, please try again.");
- }
- if (memberEmail.length() > MVNForumGlobal.MAX_MEMBER_EMAIL_LENGTH) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.member_email_too_long");
- throw new BadInputException(localizedMessage);
- //throw new BadInputException("MemberEmail cannot be longer than 60 characters.");
- }
- String memberFirstEmail = memberEmail;
- InterceptorService.getInstance().validateMail(memberFirstEmail);
-
- int memberEmailVisible = MemberBean.MEMBER_EMAIL_INVISIBLE;
- int memberNameVisible = MemberBean.MEMBER_NAME_VISIBLE;
- String memberFirstIP = request.getRemoteAddr();
- String memberLastIP = memberFirstIP;
- int memberOption = 0;//@todo review and support it later
- int memberStatus = MemberBean.MEMBER_STATUS_ENABLE;//MemberBean.MEMBER_STATUS_PENDING;// @todo review and support it later, ex: should it be active or not?
- String memberActivateCode = "";// @todo review and support it later
- int memberMessageOption = 0;// @todo review and support it later
- int memberPostsPerPage = 10; //default for all preregistered users
- Date memberBirthday = new java.sql.Date(now.getTime());
- Timestamp memberCreationDate= now;
- Timestamp memberModifiedDate= now;
- Timestamp memberExpireDate = memberCreationDate;// equal Creation Date mean no expiration
- Timestamp memberPasswordExpireDate = memberCreationDate;// equal Creation Date mean no password expiration
-
- DAOFactory.getMemberDAO().create(memberName, memberPassword, memberFirstEmail,
- memberEmail, memberEmailVisible, memberNameVisible,
- memberFirstIP, memberLastIP, 0/*memberViewCount*/,
- 0/*memberPostCount*/, memberCreationDate, memberModifiedDate, memberExpireDate, memberPasswordExpireDate,
- now/*memberLastLogon*/, memberOption, memberStatus,
- memberActivateCode, ""/*memberTempPassword*/, 0/*memberMessageCount*/,
- memberMessageOption, memberPostsPerPage, 0/*memberWarnCount*/,
- 0/*memberVoteCount*/, 0/*memberVoteTotalStars*/, 0/*memberRewardPoints*/,
- ""/*memberTitle*/, 0/*memberTimeZone*/, ""/*memberSignature*/,
- ""/*memberAvatar*/, ""/*memberSkin*/, ""/*memberLanguage*/,
- " "/*memberFirstname*/, " "/*memberLastname*/, 1/*memberGender*/,
- memberBirthday, ""/*memberAddress*/, ""/*memberCity*/,
- ""/*memberState*/, ""/*memberCountry*/, ""/*memberPhone*/,
- ""/*memberMobile*/, ""/*memberFax*/, ""/*memberCareer*/,
- ""/*memberHomepage*/, ""/*memberYahoo*/, ""/*memberAol*/,
- ""/*memberIcq*/, ""/*memberMsn*/, ""/*memberCoolLink1*/,
- ""/*memberCoolLink2*/);
-
- // Now, create 4 default folders for each member
- int memberID = MemberCache.getInstance().getMemberIDFromMemberName(memberName);
- int folderStatus = 0;
- int folderOption = 0;
- int folderType = 0;
- DAOFactory.getMessageFolderDAO().create(MVNForumConstant.MESSAGE_FOLDER_INBOX, memberID, 0/*order*/, folderStatus, folderOption, folderType, now, now);
- DAOFactory.getMessageFolderDAO().create(MVNForumConstant.MESSAGE_FOLDER_DRAFT, memberID, 1/*order*/, folderStatus, folderOption, folderType, now, now);
- DAOFactory.getMessageFolderDAO().create(MVNForumConstant.MESSAGE_FOLDER_SENT, memberID, 2/*order*/, folderStatus, folderOption, folderType, now, now);
- DAOFactory.getMessageFolderDAO().create(MVNForumConstant.MESSAGE_FOLDER_TRASH, memberID, 3/*order*/, folderStatus, folderOption, folderType, now, now);
-
- // Add member to the lucene index
- MemberBean memberBean = null;
- try {
- memberBean = DAOFactory.getMemberDAO().getMember(memberID);
- } catch(ObjectNotFoundException ex) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
- MemberIndexer.scheduleAddMemberTask(memberBean);
-
- // now, if require activation, then we will send mail
- // Note that because after this page succeed,
- // we redirect to usermanagement so not use mvnforum.mail.failed now
- if (MVNForumConfig.getRequireActivation()) {
- String serverName = ParamUtil.getServerPath();//ParamUtil.getServer2(request);
- try {
- SendMailUtil.sendActivationCodeEmail(memberID, serverName);
- } catch (Exception ex) {
- log.error("Cannot send mail after registration!", ex);
- request.setAttribute("mvnforum.mail.failed", "Cannot send activation email after registration!");
- //@todo: save the error message to displayed later
- }
- }
-
- String actionDesc = MVNForumResourceBundle.getString(MVNForumConfig.getEventLogLocale(), "mvnforum.eventlog.desc.AddMemberProcess", new Object[]{memberName});
- eventLogService.logEvent(onlineUser.getMemberName(), request.getRemoteAddr(), MVNForumConstant.EVENT_LOG_MAIN_MODULE, MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN, "add member", actionDesc, EventLogService.MEDIUM);
-
- }
-
- public void processUpdateMemberStatus(GenericRequest request)
- throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException {
-
- SecurityUtil.checkHttpReferer(request);
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanModerateUser();
-
- // primary key column(s)
- int memberID = GenericParamUtil.getParameterInt(request, "memberid");
-
- // column(s) to update
- int memberStatus = GenericParamUtil.getParameterInt(request, "status");
- Locale locale = I18nUtil.getLocaleInRequest(request);
-
- // now check if status is in the valid range
- if ( (memberStatus != MemberBean.MEMBER_STATUS_ENABLE) && (memberStatus != MemberBean.MEMBER_STATUS_DISABLE) ) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_update_member_status.unknown_status", new Object[] { new Integer(memberStatus)});
- throw new BadInputException(localizedMessage);
- //throw new BadInputException("Cannot update member's status to an unknown status = " + memberStatus);
- }
-
- // This code make sure Admin always has Enable status
- if (memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN) {
- memberStatus = MemberBean.MEMBER_STATUS_ENABLE;
- }
- //IMPORTANT: Guest (id=MEMBER_ID_OF_GUEST) can be disabled by administrator.
- try {
- DAOFactory.getMemberDAO().updateStatus(memberID, memberStatus);
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- String actionDesc = MVNForumResourceBundle.getString(MVNForumConfig.getEventLogLocale(), "mvnforum.eventlog.desc.UpdateMemberStatus", new Object[]{new Integer(memberID), new Integer(memberStatus)});
- eventLogService.logEvent(onlineUser.getMemberName(), request.getRemoteAddr(), MVNForumConstant.EVENT_LOG_MAIN_MODULE, MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN, "update member status", actionDesc, EventLogService.MEDIUM);
-
- }
-
- public void prepareEdit(GenericRequest request)
- throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException {
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanModerateUser();
-
- Locale locale = I18nUtil.getLocaleInRequest(request);
-
- int memberID = GenericParamUtil.getParameterInt(request, "memberid");
-
- MemberBean memberBean = null;
- try {
- memberBean = DAOFactory.getMemberDAO().getMember(memberID);
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- request.setAttribute("MemberBean", memberBean);
- }
-
- public void processEdit(GenericRequest request, GenericResponse response)
- throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException {
-
- SecurityUtil.checkHttpPostMethod(request);
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanModerateUser();
-
- // now check the password
- MyUtil.ensureCorrectCurrentPassword(request);
-
- MyUtil.saveVNTyperMode(request, response);
-
- int memberID = GenericParamUtil.getParameterInt(request, "memberid");
- MemberBean memberBean = DAOFactory.getMemberDAO().getMember(memberID);
- MemberMapping mapping = MemberMapping.getInstance();
- boolean internalUserDatabase = !MVNForumConfig.getEnableExternalUserDatabase();
-
- Timestamp now = DateUtil.getCurrentGMTTimestamp();
-
- // column(s) to update
- int memberEmailVisible = memberBean.getMemberEmailVisible();
- int memberNameVisible = memberBean.getMemberNameVisible();
- int memberOption = 0;//GenericParamUtil.getParameterInt(request, "MemberOption");
- int memberStatus = GenericParamUtil.getParameterInt(request, "MemberStatus");
- int memberMessageOption = 0;//GenericParamUtil.getParameterInt(request, "MemberMessageOption");
- int memberPostsPerPage = memberBean.getMemberPostsPerPage();
- if (memberPostsPerPage < 5) {
- memberPostsPerPage = 5;
- }
- double memberTimeZone = memberBean.getMemberTimeZone();
- String memberSkin = memberBean.getMemberSkin();
- String memberLanguage = memberBean.getMemberLanguage();
- String memberFirstname = memberBean.getMemberFirstname();
- String memberLastname = memberBean.getMemberLastname();
- int memberGender = memberBean.getMemberGender();
- Date memberBirthday = memberBean.getMemberBirthday();
- String memberAddress = memberBean.getMemberAddress();
- String memberCity = memberBean.getMemberCity();
- String memberState = memberBean.getMemberState();
- String memberCountry = memberBean.getMemberCountry();
- String memberPhone = memberBean.getMemberPhone();
- String memberMobile = memberBean.getMemberMobile();
- String memberFax = memberBean.getMemberFax();
- String memberCareer = memberBean.getMemberCareer();
- String memberHomepage = memberBean.getMemberHomepage();
- String memberYahoo = memberBean.getMemberYahoo();
- String memberAol = memberBean.getMemberAol();
- String memberIcq = memberBean.getMemberIcq();
- String memberMsn = memberBean.getMemberMsn();
- String memberCoolLink1 = memberBean.getMemberCoolLink1();
- String memberCoolLink2 = memberBean.getMemberCoolLink2();
-
- // column(s) to update
- if (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberEmailVisible())) {
- memberEmailVisible = GenericParamUtil.getParameterBoolean(request, "MemberEmailVisible")? MemberBean.MEMBER_EMAIL_VISIBLE : MemberBean.MEMBER_EMAIL_INVISIBLE;
- }
- if (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberNameVisible())) {
- memberNameVisible = GenericParamUtil.getParameterBoolean(request, "MemberNameVisible") ? MemberBean.MEMBER_NAME_VISIBLE : MemberBean.MEMBER_NAME_INVISIBLE;
- }
- if (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberPostsPerPage())) {
- memberPostsPerPage = GenericParamUtil.getParameterInt(request, "MemberPostsPerPage");
- }
- if (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberTimeZone())) {
- memberTimeZone = GenericParamUtil.getParameterTimeZone(request, "MemberTimeZone");
- }
- if (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberSkin())) {
- memberSkin = GenericParamUtil.getParameterFilter(request, "MemberSkin", false);
- }
- if (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberLanguage())) {
- memberLanguage = GenericParamUtil.getParameterFilter(request, "MemberLanguage", false);
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberFirstname())) &&
- MVNForumConfig.getEnableShowFirstName() ) {
- memberFirstname = GenericParamUtil.getParameterFilter(request, "MemberFirstname", MVNForumConfig.isRequireRegisterFirstname());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberLastname())) &&
- MVNForumConfig.getEnableShowLastName() ) {
- memberLastname = GenericParamUtil.getParameterFilter(request, "MemberLastname", MVNForumConfig.isRequireRegisterLastname());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberGender())) &&
- MVNForumConfig.getEnableShowGender() ) {
- memberGender = GenericParamUtil.getParameterBoolean(request, "MemberGender")? 1 : 0;
- memberGender = Integer.parseInt(GenericParamUtil.getParameterFilter(request, "MemberGender", MVNForumConfig.isRequireRegisterGender()));
- if (memberGender != 0 && memberGender != 1) {
- memberGender = 0;
- }
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberBirthday())) &&
- MVNForumConfig.getEnableShowBirthday() ) {
- String memberBirthdayStr = GenericParamUtil.getParameter(request, "MemberBirthday");
- if ( MVNForumConfig.isRequireRegisterBirthday() ||
- memberBirthdayStr.length() > 0 ) {
- memberBirthday = GenericParamUtil.getParameterDate(request, "MemberBirthday");
- }
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberAddress())) &&
- MVNForumConfig.getEnableShowAddress() ) {
- memberAddress = GenericParamUtil.getParameterFilter(request, "MemberAddress", MVNForumConfig.isRequireRegisterAddress());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberCity())) &&
- MVNForumConfig.getEnableShowCity() ) {
- memberCity = GenericParamUtil.getParameterFilter(request, "MemberCity", MVNForumConfig.isRequireRegisterCity());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberState())) &&
- MVNForumConfig.getEnableShowState() ) {
- memberState = GenericParamUtil.getParameterFilter(request, "MemberState", MVNForumConfig.isRequireRegisterState());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberCountry())) &&
- MVNForumConfig.getEnableShowCountry() ) {
- memberCountry = GenericParamUtil.getParameterFilter(request, "MemberCountry", MVNForumConfig.isRequireRegisterCountry());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberPhone())) &&
- MVNForumConfig.getEnableShowPhone() ) {
- memberPhone = GenericParamUtil.getParameterFilter(request, "MemberPhone", MVNForumConfig.isRequireRegisterPhone());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberMobile())) &&
- MVNForumConfig.getEnableShowMobile() ) {
- memberMobile = GenericParamUtil.getParameterFilter(request, "MemberMobile", MVNForumConfig.isRequireRegisterMobile());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberFax())) &&
- MVNForumConfig.getEnableShowFax() ) {
- memberFax = GenericParamUtil.getParameterFilter(request, "MemberFax", MVNForumConfig.isRequireRegisterFax());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberCareer())) &&
- MVNForumConfig.getEnableShowCareer() ) {
- memberCareer = GenericParamUtil.getParameterFilter(request, "MemberCareer", MVNForumConfig.isRequireRegisterCareer());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberHomepage())) &&
- MVNForumConfig.getEnableShowHomepage() ) {
- String memberHomepageStr = GenericParamUtil.getParameter(request, "MemberHomepage");
- if ( MVNForumConfig.isRequireRegisterHomepage() ||
- memberHomepageStr.length() > 0 ) {
- memberHomepage = GenericParamUtil.getParameterUrl(request, "MemberHomepage");
- }
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberYahoo())) &&
- MVNForumConfig.getEnableShowYahoo() ) {
- memberYahoo = GenericParamUtil.getParameterFilter(request, "MemberYahoo", MVNForumConfig.isRequireRegisterYahoo());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberAol())) &&
- MVNForumConfig.getEnableShowAOL() ) {
- memberAol = GenericParamUtil.getParameterFilter(request, "MemberAol", MVNForumConfig.isRequireRegisterAol());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberIcq())) &&
- MVNForumConfig.getEnableShowICQ() ) {
- memberIcq = GenericParamUtil.getParameterFilter(request, "MemberIcq", MVNForumConfig.isRequireRegisterIcq());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberMsn())) &&
- MVNForumConfig.getEnableShowMSN() ) {
- memberMsn = GenericParamUtil.getParameterFilter(request, "MemberMsn", MVNForumConfig.isRequireRegisterMsn());
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberCoolLink1())) &&
- MVNForumConfig.getEnableShowCoolLink1() ) {
- String memberCoolLink1Str = GenericParamUtil.getParameter(request, "MemberCoolLink1");
- if ( MVNForumConfig.isRequireRegisterLink1() ||
- memberCoolLink1Str.length() > 0 ) {
- memberCoolLink1 = GenericParamUtil.getParameterUrl(request, "MemberCoolLink1");
- }
- }
- if ( (internalUserDatabase || MemberMapping.isLocalField(mapping.getMemberCoolLink2())) &&
- MVNForumConfig.getEnableShowCoolLink2() ) {
- String memberCoolLink2Str = GenericParamUtil.getParameter(request, "MemberCoolLink2");
- if ( MVNForumConfig.isRequireRegisterLink2() ||
- memberCoolLink2Str.length() > 0 ) {
- memberCoolLink2 = GenericParamUtil.getParameterUrl(request, "MemberCoolLink2");
- }
- }
-
- try {
- DAOFactory.getMemberDAO().update(memberID, // primary key
- memberEmailVisible, memberNameVisible, now/*memberModifiedDate*/,
- memberOption, memberStatus, memberMessageOption,
- memberPostsPerPage, memberTimeZone, memberSkin,
- memberLanguage, memberFirstname, memberLastname,
- memberGender, memberBirthday, memberAddress,
- memberCity, memberState, memberCountry,
- memberPhone, memberMobile, memberFax,
- memberCareer, memberHomepage, memberYahoo,
- memberAol, memberIcq, memberMsn,
- memberCoolLink1, memberCoolLink2);
-
- String actionDesc = MVNForumResourceBundle.getString(MVNForumConfig.getEventLogLocale(), "mvnforum.eventlog.desc.UpdateMemberProcess", new Object[]{new Integer(memberID)});
- eventLogService.logEvent(onlineUser.getMemberName(), request.getRemoteAddr(), MVNForumConstant.EVENT_LOG_MAIN_MODULE, MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN, "update member", actionDesc, EventLogService.MEDIUM);
-
- } catch(ObjectNotFoundException ex) {
- Locale locale = I18nUtil.getLocaleInRequest(request);
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- MemberBean justEditedMemberBean = DAOFactory.getMemberDAO().getMember(memberID);
-
- MemberIndexer.scheduleUpdateMemberTask(justEditedMemberBean);
- //request.setAttribute("MemberBean", justEditedMemberBean);
- }
-
- public void prepareView(GenericRequest request)
- throws BadInputException, ObjectNotFoundException, DatabaseException, AuthenticationException {
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanModerateUser();
-
- Locale locale = I18nUtil.getLocaleInRequest(request);
-
- String strMemberID = GenericParamUtil.getParameter(request, "memberid", false);
- String strMemberName = GenericParamUtil.getParameter(request, "member", false);
- String strMemberEmail = GenericParamUtil.getParameter(request, "memberemail", false);
-
- int memberID;
- MemberBean memberBean = null;
-
- if (strMemberID.length() > 0) {
- memberID = GenericParamUtil.getParameterInt(request, "memberid");
- } else if (strMemberName.length() > 0) {
- /**@todo: improve this for better performance(don't use this method,
- * and write 2 new methods)*/
- StringUtil.checkGoodName(strMemberName);// check for better security
- try {
- memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberName(strMemberName);
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.membername_not_exists", new Object[] {strMemberName});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- // now, in the LDAP case, we can get memberID from memberName does not mean user is in LDAP or not,
- // so we must check if the whole memberBean can be loaded or not
- try {
- memberBean = DAOFactory.getMemberDAO().getMember(memberID);
- } catch (ObjectNotFoundException e) {
- throw new ObjectNotFoundException("Member with login id = " + strMemberName + " has been deleted externally (for example, in LDAP) but the numeric id (" + memberID + ") still in the database.");
- }
- } else if (strMemberEmail.length() > 0) {
- String memberEmail = GenericParamUtil.getParameterEmail(request, "memberemail");// check for better security
- try {
- memberID = DAOFactory.getMemberDAO().getMemberIDFromMemberEmail(memberEmail);
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberemail_not_exists", new Object[] {memberEmail});
- throw new ObjectNotFoundException(localizedMessage);
- }
- } else {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_get_member_info");
- throw new BadInputException(localizedMessage);
- //throw new BadInputException("Cannot get the information to view member.");
- }
-
- // Update statistics to make sure Admin can delete this user
- // with the actual memberPostCount
- try {
- StatisticsUtil.updateMemberStatistics(memberID);
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- int toMessageCount = 0;
- int fromMessageCount = 0;
-
- String toDay = GenericParamUtil.getParameter(request, "toDay", false);
- String toMonth = GenericParamUtil.getParameter(request, "toMonth", false);
- String toYear = GenericParamUtil.getParameter(request, "toYear", false);
-
- String fromDay = GenericParamUtil.getParameter(request, "fromDay", false);
- String fromMonth = GenericParamUtil.getParameter(request, "fromMonth", false);
- String fromYear = GenericParamUtil.getParameter(request, "fromYear", false);
-
- if ( !toDay.equals("") &&
- !toMonth.equals("") &&
- !toYear.equals("") &&
- !fromDay.equals("") &&
- !fromMonth.equals("") &&
- !fromYear.equals("")) {
- Timestamp from = new Timestamp(GenericParamUtil.getParameterDate(request, "fromDay", "fromMonth", "fromYear").getTime());
- Timestamp to = new Timestamp(GenericParamUtil.getParameterDate(request, "toDay", "toMonth", "toYear").getTime());
-
- toMessageCount = DAOFactory.getMessageStatisticsDAO().getNumberOfBeans_inToID_supportTimestamp(memberID, from, to);
- fromMessageCount = DAOFactory.getMessageStatisticsDAO().getNumberOfBeans_inFromID_supportTimestamp(memberID, from, to);
- } else {
- toMessageCount = DAOFactory.getMessageStatisticsDAO().getNumberOfBeans_inToID(memberID);
- fromMessageCount = DAOFactory.getMessageStatisticsDAO().getNumberOfBeans_inFromID(memberID);
- }
-
- try {
- if (memberBean == null) {
- memberBean = DAOFactory.getMemberDAO().getMember(memberID);
- }
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
- int watchCount = DAOFactory.getWatchDAO().getNumberOfWatches_forMember(memberID);
-
- request.setAttribute("MemberBean", memberBean);
- request.setAttribute("WatchCount", new Integer(watchCount));
-
- request.setAttribute("ToMessageCount", new Integer(toMessageCount));
- request.setAttribute("FromMessageCount", new Integer(fromMessageCount));
- request.setAttribute("toDay", toDay);
- request.setAttribute("toMonth", toMonth);
- request.setAttribute("toYear", toYear);
- request.setAttribute("fromDay", fromDay);
- request.setAttribute("fromMonth", fromMonth);
- request.setAttribute("fromYear", toYear);
- }
-
- public void processUpdateMemberTitle(GenericRequest request, GenericResponse response)
- throws BadInputException, DatabaseException, ObjectNotFoundException, AuthenticationException {
-
- SecurityUtil.checkHttpPostMethod(request);
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanModerateUser();
-
- MyUtil.saveVNTyperMode(request, response);
-
- // primary key column(s)
- int memberID = GenericParamUtil.getParameterInt(request, "MemberID");
-
- // column(s) to update
- String memberTitle = GenericParamUtil.getParameterSafe(request, "MemberTitle", false);
- Locale locale = I18nUtil.getLocaleInRequest(request);
- try {
- DAOFactory.getMemberDAO().updateTitle(memberID, memberTitle);
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- String actionDesc = MVNForumResourceBundle.getString(MVNForumConfig.getEventLogLocale(), "mvnforum.eventlog.desc.UpdateMemberTitle", new Object[]{new Integer(memberID), memberTitle});
- eventLogService.logEvent(onlineUser.getMemberName(), request.getRemoteAddr(), MVNForumConstant.EVENT_LOG_MAIN_MODULE, MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN, "update member title", actionDesc, EventLogService.MEDIUM);
-
- // clear the member cache
- MemberCache.getInstance().clear();
- }
-
- public void processResetMemberSignature(GenericRequest request)
- throws BadInputException, DatabaseException, ObjectNotFoundException, AuthenticationException {
-
- SecurityUtil.checkHttpReferer(request);
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanModerateUser();
-
- Locale locale = I18nUtil.getLocaleInRequest(request);
- int memberID = GenericParamUtil.getParameterInt(request, "memberid");
- try {
- DAOFactory.getMemberDAO().updateSignature(memberID, "");
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- String actionDesc = MVNForumResourceBundle.getString(MVNForumConfig.getEventLogLocale(), "mvnforum.eventlog.desc.ResetMemberSignature", new Object[]{new Integer(memberID)});
- eventLogService.logEvent(onlineUser.getMemberName(), request.getRemoteAddr(), MVNForumConstant.EVENT_LOG_MAIN_MODULE, MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN, "reset member signature", actionDesc, EventLogService.MEDIUM);
-
- request.setAttribute("MemberID", new Integer(memberID));
- }
-
- public void processResetMemberAvatar(GenericRequest request)
- throws BadInputException, DatabaseException, ObjectNotFoundException, AuthenticationException {
-
- SecurityUtil.checkHttpReferer(request);
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanModerateUser();
-
- Locale locale = I18nUtil.getLocaleInRequest(request);
- int memberID = GenericParamUtil.getParameterInt(request, "memberid");
- try {
- DAOFactory.getMemberDAO().updateAvatar(memberID, "");
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- String actionDesc = MVNForumResourceBundle.getString(MVNForumConfig.getEventLogLocale(), "mvnforum.eventlog.desc.ResetMemberAvatar", new Object[]{new Integer(memberID)});
- eventLogService.logEvent(onlineUser.getMemberName(), request.getRemoteAddr(), MVNForumConstant.EVENT_LOG_MAIN_MODULE, MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN, "reset member avatar", actionDesc, EventLogService.MEDIUM);
-
- request.setAttribute("MemberID", new Integer(memberID));
- }
-
- public void processResetMemberActivation(GenericRequest request)
- throws BadInputException, DatabaseException, ObjectNotFoundException, AuthenticationException {
-
- SecurityUtil.checkHttpReferer(request);
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanModerateUser();// TODO: should check if we need AdminSystem permission to do this action
-
- Locale locale = I18nUtil.getLocaleInRequest(request);
- int memberID = GenericParamUtil.getParameterInt(request, "memberid");
- try {
- DAOFactory.getMemberDAO().updateActivateCode(memberID, "");
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- String actionDesc = MVNForumResourceBundle.getString(MVNForumConfig.getEventLogLocale(), "mvnforum.eventlog.desc.ResetMemberActivation", new Object[]{new Integer(memberID)});
- eventLogService.logEvent(onlineUser.getMemberName(), request.getRemoteAddr(), MVNForumConstant.EVENT_LOG_MAIN_MODULE, MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN, "reset member activation", actionDesc, EventLogService.MEDIUM);
-
- request.setAttribute("MemberID", new Integer(memberID));
- }
-
- public void prepareDeleteMember(GenericRequest request)
- throws BadInputException, DatabaseException, ObjectNotFoundException, AuthenticationException {
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanAdminSystem();
-
- Locale locale = I18nUtil.getLocaleInRequest(request);
-
- int memberID = GenericParamUtil.getParameterInt(request, "memberid");
- if ((memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN) ||
- (memberID == 0) ||
- (memberID == onlineUser.getMemberID()) ||
- (memberID == MVNForumConstant.MEMBER_ID_OF_GUEST)) {
-
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_admin_or_guest");
- throw new BadInputException(localizedMessage);
- //throw new BadInputException("Cannot delete default Admin and Guest users.");
- }
-
- MemberBean memberBean = null;
- try {
- memberBean = DAOFactory.getMemberDAO().getMember(memberID);
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- request.setAttribute("MemberBean", memberBean);
- }
-
- public void processDeleteMember(GenericRequest request)
- throws BadInputException, DatabaseException, ObjectNotFoundException, AuthenticationException {
-
- SecurityUtil.checkHttpPostMethod(request);
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanAdminSystem();
-
- Locale locale = I18nUtil.getLocaleInRequest(request);
-
- // now check the password
- MyUtil.ensureCorrectCurrentPassword(request);
-
- int memberID = GenericParamUtil.getParameterInt(request, "memberid");
- if ((memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN) ||
- (memberID == 0) ||
- (memberID == onlineUser.getMemberID()) ||
- (memberID == MVNForumConstant.MEMBER_ID_OF_GUEST)) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.cannot_delete_admin_or_guest");
- throw new BadInputException(localizedMessage);
- //throw new BadInputException("Cannot delete default Admin and Guest users.");
- }
-
- boolean deleteSentMessages = GenericParamUtil.getParameterBoolean(request, "deletesentmessages");
-
- MemberBean memberBean = null;
- try {
- memberBean = DAOFactory.getMemberDAO().getMember(memberID);
- } catch (ObjectNotFoundException e) {
- String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.ObjectNotFoundException.memberid_not_exists", new Object[] {new Integer(memberID)});
- throw new ObjectNotFoundException(localizedMessage);
- }
-
- MemberWebHandler.deleteMember(memberBean, deleteSentMessages, /*context*/request, locale);
-
- String actionDesc = MVNForumResourceBundle.getString(MVNForumConfig.getEventLogLocale(), "mvnforum.eventlog.desc.DeleteMemberProcess", new Object[]{new Integer(memberID)});
- eventLogService.logEvent(onlineUser.getMemberName(), request.getRemoteAddr(), MVNForumConstant.EVENT_LOG_MAIN_MODULE, MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN, "delete member", actionDesc, EventLogService.HIGH);
- }
-
- /**
- * This method supports sorting base on many criteria
- */
- public void prepareShowUserManagement(GenericRequest request)
- throws DatabaseException, BadInputException, AuthenticationException {
-
- OnlineUser onlineUser = onlineUserManager.getOnlineUser(request);
- MVNForumPermission permission = onlineUser.getPermission();
- permission.ensureCanModerateUser();
-
- Locale locale = I18nUtil.getLocaleInRequest(request);
-
- // 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.getParameterUnsignedInt(request, "offset");
- } catch (BadInputException e) {
- // do nothing
- }
-
- int totalMembers = 0;
- Collection memberBeans = new ArrayList ();
- int enabledMembers = 0;
- int pendingMembers = 0;
- int activatedMembers = 0;
- int nonactivatedMembers = 0;
- int disabledMembers = 0;
- if (DAOFactory.getMemberDAO().isSupportGetMembers_withSortSupport_limit()) {
- if (DAOFactory.getMemberDAO().isSupportGetNumberOfMembers()) {
- 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.");
- }
- memberBeans = DAOFactory.getMemberDAO().getMembers_withSortSupport_limit(offset, postsPerPage, sort, order, MemberDAO.ALL_MEMBER_STATUS);
-
- if (DAOFactory.getMemberDAO().isSupportGetNumberOfMembers_inActivationStatus()) {
- activatedMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inActivationStatus(true);
- nonactivatedMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inActivationStatus(false);
- if ((activatedMembers + nonactivatedMembers) != totalMembers) {
- // please do not localize this
- throw new AssertionError("Assertion: (activatedMembers + nonactivatedMembers) == totalMembers");
- }
- }
-
- if (DAOFactory.getMemberDAO().isSupportGetNumberOfMembers_inMemberStatus()) {
- disabledMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inMemberStatus(MemberBean.MEMBER_STATUS_DISABLE);
- enabledMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inMemberStatus(MemberBean.MEMBER_STATUS_ENABLE);
- pendingMembers = DAOFactory.getMemberDAO().getNumberOfMembers_inMemberStatus(MemberBean.MEMBER_STATUS_PENDING);
- if ((disabledMembers + enabledMembers + pendingMembers) != totalMembers) {
- // please do not localize this
- throw new AssertionError("Assertion: (disabledMembers + enabledMembers + pendingMembers) == totalMembers");
- }
- }
-