0001: /*
0002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/MemberWebHandler.java,v 1.156 2008/01/25 10:11:24 phuongpdd Exp $
0003: * $Author: phuongpdd $
0004: * $Revision: 1.156 $
0005: * $Date: 2008/01/25 10:11:24 $
0006: *
0007: * ====================================================================
0008: *
0009: * Copyright (C) 2002-2007 by MyVietnam.net
0010: *
0011: * All copyright notices regarding mvnForum MUST remain
0012: * intact in the scripts and in the outputted HTML.
0013: * The "powered by" text/logo with a link back to
0014: * http://www.mvnForum.com and http://www.MyVietnam.net in
0015: * the footer of the pages MUST remain visible when the pages
0016: * are viewed on the internet or intranet.
0017: *
0018: * This program is free software; you can redistribute it and/or modify
0019: * it under the terms of the GNU General Public License as published by
0020: * the Free Software Foundation; either version 2 of the License, or
0021: * any later version.
0022: *
0023: * This program is distributed in the hope that it will be useful,
0024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0026: * GNU General Public License for more details.
0027: *
0028: * You should have received a copy of the GNU General Public License
0029: * along with this program; if not, write to the Free Software
0030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0031: *
0032: * Support can be obtained from support forums at:
0033: * http://www.mvnForum.com/mvnforum/index
0034: *
0035: * Correspondence and Marketing Questions can be sent to:
0036: * info at MyVietnam net
0037: *
0038: * @author: Minh Nguyen
0039: * @author: Mai Nguyen
0040: * @author: Igor Manic
0041: */
0042: package com.mvnforum.admin;
0043:
0044: import java.io.File;
0045: import java.io.IOException;
0046: import java.sql.Date;
0047: import java.sql.Timestamp;
0048: import java.util.*;
0049:
0050: import net.myvietnam.mvncore.MVNCoreResourceBundle;
0051: import net.myvietnam.mvncore.exception.*;
0052: import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
0053: import net.myvietnam.mvncore.interceptor.InterceptorService;
0054: import net.myvietnam.mvncore.security.Encoder;
0055: import net.myvietnam.mvncore.security.SecurityUtil;
0056: import net.myvietnam.mvncore.service.EventLogService;
0057: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
0058: import net.myvietnam.mvncore.util.*;
0059: import net.myvietnam.mvncore.web.GenericRequest;
0060: import net.myvietnam.mvncore.web.GenericResponse;
0061:
0062: import org.apache.commons.logging.Log;
0063: import org.apache.commons.logging.LogFactory;
0064:
0065: import com.mvnforum.*;
0066: import com.mvnforum.auth.*;
0067: import com.mvnforum.categorytree.*;
0068: import com.mvnforum.common.*;
0069: import com.mvnforum.db.*;
0070: import com.mvnforum.search.member.MemberIndexer;
0071: import com.mvnforum.search.member.MemberSearchQuery;
0072: import com.mvnforum.service.CategoryService;
0073: import com.mvnforum.service.MvnForumServiceFactory;
0074:
0075: public class MemberWebHandler {
0076:
0077: private static Log log = LogFactory.getLog(MemberWebHandler.class);
0078:
0079: private OnlineUserManager onlineUserManager = OnlineUserManager
0080: .getInstance();
0081:
0082: private static CategoryService categoryService = MvnForumServiceFactory
0083: .getMvnForumService().getCategoryService();
0084:
0085: private static EventLogService eventLogService = MvnCoreServiceFactory
0086: .getMvnCoreService().getEventLogService();
0087:
0088: public MemberWebHandler() {
0089: }
0090:
0091: public void prepareAdd(GenericRequest request)
0092: throws AuthenticationException, DatabaseException {
0093:
0094: if (MVNForumConfig.getEnableExternalUserDatabase()) {
0095: Locale locale = I18nUtil.getLocaleInRequest(request);
0096:
0097: String localizedMessage = MVNForumResourceBundle
0098: .getString(locale,
0099: "java.lang.IllegalStateException.create_user_is_disabled");
0100: throw new IllegalStateException(localizedMessage);
0101: //throw new IllegalStateException("Cannot create user if we enable external user database.");
0102: }
0103:
0104: OnlineUser onlineUser = onlineUserManager
0105: .getOnlineUser(request);
0106: MVNForumPermission permission = onlineUser.getPermission();
0107: permission.ensureCanAdminSystem();
0108: }
0109:
0110: public void processAdd(GenericRequest request)
0111: throws BadInputException, ObjectNotFoundException,
0112: CreateException, DatabaseException, DuplicateKeyException,
0113: ForeignKeyNotFoundException, AuthenticationException,
0114: InterceptorException {
0115:
0116: Locale locale = I18nUtil.getLocaleInRequest(request);
0117:
0118: if (MVNForumConfig.getEnableExternalUserDatabase()) {
0119: String localizedMessage = MVNForumResourceBundle
0120: .getString(locale,
0121: "java.lang.IllegalStateException.create_user_is_disabled");
0122: throw new IllegalStateException(localizedMessage);
0123: //throw new IllegalStateException("Cannot create user if we enable external user database.");
0124: }
0125:
0126: SecurityUtil.checkHttpPostMethod(request);
0127:
0128: OnlineUser onlineUser = onlineUserManager
0129: .getOnlineUser(request);
0130: MVNForumPermission permission = onlineUser.getPermission();
0131: permission.ensureCanAdminSystem();
0132:
0133: Timestamp now = DateUtil.getCurrentGMTTimestamp();
0134:
0135: String memberName = GenericParamUtil.getParameterSafe(request,
0136: "MemberName", true); // check good name
0137: /** @todo move to a name filter */
0138: if (memberName.equalsIgnoreCase(MVNForumConfig
0139: .getDefaultGuestName())
0140: || memberName.equalsIgnoreCase("Guest")
0141: || memberName.equalsIgnoreCase("Administrator")
0142: || memberName.equalsIgnoreCase("Moderator")) {
0143: String localizedMessage = MVNForumResourceBundle
0144: .getString(
0145: locale,
0146: "mvncore.exception.BadInputException.cannot_register_with_reserved_name",
0147: new Object[] { memberName });
0148: throw new BadInputException(localizedMessage);
0149: //throw new BadInputException("Cannot register member with a reserved name : " + memberName);
0150: }
0151: StringUtil.checkGoodName(memberName);
0152: InterceptorService.getInstance().validateLoginID(memberName);
0153: if (memberName.length() > MVNForumGlobal.MAX_MEMBER_LOGIN_LENGTH) {
0154: String localizedMessage = MVNForumResourceBundle
0155: .getString(locale,
0156: "mvncore.exception.BadInputException.member_name_too_long");
0157: throw new BadInputException(localizedMessage);
0158: //throw new BadInputException("MemberName cannot be longer than 30 characters.");
0159: }
0160:
0161: String memberPassword1 = GenericParamUtil.getParameterPassword(
0162: request, "MemberMatkhau", 3, 0);
0163: String memberPassword2 = GenericParamUtil.getParameterPassword(
0164: request, "MemberMatkhauConfirm", 3, 0);
0165:
0166: InterceptorService.getInstance().validatePassword(
0167: memberPassword1);
0168:
0169: if (!memberPassword1.equals(memberPassword2)) {
0170: String localizedMessage = MVNForumResourceBundle
0171: .getString(locale,
0172: "mvncore.exception.BadInputException.confirmed_password_is_not_match");
0173: throw new BadInputException(localizedMessage);
0174: //throw new BadInputException("Password and confirmed password are not the same, please try again.");
0175: }
0176: String memberPassword = Encoder.getMD5_Base64(memberPassword1);
0177:
0178: String memberEmail = GenericParamUtil.getParameterEmail(
0179: request, "MemberEmail");
0180: String memberEmailConfirm = GenericParamUtil.getParameterEmail(
0181: request, "MemberEmailConfirm");
0182: if (!memberEmail.equals(memberEmailConfirm)) {
0183: String localizedMessage = MVNForumResourceBundle
0184: .getString(locale,
0185: "mvncore.exception.BadInputException.confirmed_email_is_not_match");
0186: throw new BadInputException(localizedMessage);
0187: //throw new BadInputException("Email and confirmed email are not the same, please try again.");
0188: }
0189: if (memberEmail.length() > MVNForumGlobal.MAX_MEMBER_EMAIL_LENGTH) {
0190: String localizedMessage = MVNForumResourceBundle
0191: .getString(locale,
0192: "mvncore.exception.BadInputException.member_email_too_long");
0193: throw new BadInputException(localizedMessage);
0194: //throw new BadInputException("MemberEmail cannot be longer than 60 characters.");
0195: }
0196: String memberFirstEmail = memberEmail;
0197: InterceptorService.getInstance().validateMail(memberFirstEmail);
0198:
0199: int memberEmailVisible = MemberBean.MEMBER_EMAIL_INVISIBLE;
0200: int memberNameVisible = MemberBean.MEMBER_NAME_VISIBLE;
0201: String memberFirstIP = request.getRemoteAddr();
0202: String memberLastIP = memberFirstIP;
0203: int memberOption = 0;//@todo review and support it later
0204: int memberStatus = MemberBean.MEMBER_STATUS_ENABLE;//MemberBean.MEMBER_STATUS_PENDING;// @todo review and support it later, ex: should it be active or not?
0205: String memberActivateCode = "";// @todo review and support it later
0206: int memberMessageOption = 0;// @todo review and support it later
0207: int memberPostsPerPage = 10; //default for all preregistered users
0208: Date memberBirthday = new java.sql.Date(now.getTime());
0209: Timestamp memberCreationDate = now;
0210: Timestamp memberModifiedDate = now;
0211: Timestamp memberExpireDate = memberCreationDate;// equal Creation Date mean no expiration
0212: Timestamp memberPasswordExpireDate = memberCreationDate;// equal Creation Date mean no password expiration
0213:
0214: DAOFactory.getMemberDAO()
0215: .create(memberName, memberPassword, memberFirstEmail,
0216: memberEmail, memberEmailVisible,
0217: memberNameVisible, memberFirstIP, memberLastIP,
0218: 0/*memberViewCount*/, 0/*memberPostCount*/,
0219: memberCreationDate, memberModifiedDate,
0220: memberExpireDate, memberPasswordExpireDate,
0221: now/*memberLastLogon*/, memberOption,
0222: memberStatus, memberActivateCode,
0223: ""/*memberTempPassword*/,
0224: 0/*memberMessageCount*/, memberMessageOption,
0225: memberPostsPerPage, 0/*memberWarnCount*/,
0226: 0/*memberVoteCount*/,
0227: 0/*memberVoteTotalStars*/,
0228: 0/*memberRewardPoints*/, ""/*memberTitle*/,
0229: 0/*memberTimeZone*/, ""/*memberSignature*/,
0230: ""/*memberAvatar*/, ""/*memberSkin*/,
0231: ""/*memberLanguage*/, " "/*memberFirstname*/,
0232: " "/*memberLastname*/, 1/*memberGender*/,
0233: memberBirthday, ""/*memberAddress*/,
0234: ""/*memberCity*/, ""/*memberState*/,
0235: ""/*memberCountry*/, ""/*memberPhone*/,
0236: ""/*memberMobile*/, ""/*memberFax*/,
0237: ""/*memberCareer*/, ""/*memberHomepage*/,
0238: ""/*memberYahoo*/, ""/*memberAol*/,
0239: ""/*memberIcq*/, ""/*memberMsn*/,
0240: ""/*memberCoolLink1*/, ""/*memberCoolLink2*/);
0241:
0242: // Now, create 4 default folders for each member
0243: int memberID = MemberCache.getInstance()
0244: .getMemberIDFromMemberName(memberName);
0245: int folderStatus = 0;
0246: int folderOption = 0;
0247: int folderType = 0;
0248: DAOFactory.getMessageFolderDAO().create(
0249: MVNForumConstant.MESSAGE_FOLDER_INBOX, memberID,
0250: 0/*order*/, folderStatus, folderOption, folderType,
0251: now, now);
0252: DAOFactory.getMessageFolderDAO().create(
0253: MVNForumConstant.MESSAGE_FOLDER_DRAFT, memberID,
0254: 1/*order*/, folderStatus, folderOption, folderType,
0255: now, now);
0256: DAOFactory.getMessageFolderDAO().create(
0257: MVNForumConstant.MESSAGE_FOLDER_SENT, memberID,
0258: 2/*order*/, folderStatus, folderOption, folderType,
0259: now, now);
0260: DAOFactory.getMessageFolderDAO().create(
0261: MVNForumConstant.MESSAGE_FOLDER_TRASH, memberID,
0262: 3/*order*/, folderStatus, folderOption, folderType,
0263: now, now);
0264:
0265: // Add member to the lucene index
0266: MemberBean memberBean = null;
0267: try {
0268: memberBean = DAOFactory.getMemberDAO().getMember(memberID);
0269: } catch (ObjectNotFoundException ex) {
0270: String localizedMessage = MVNForumResourceBundle
0271: .getString(
0272: locale,
0273: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0274: new Object[] { new Integer(memberID) });
0275: throw new ObjectNotFoundException(localizedMessage);
0276: }
0277: MemberIndexer.scheduleAddMemberTask(memberBean);
0278:
0279: // now, if require activation, then we will send mail
0280: // Note that because after this page succeed,
0281: // we redirect to usermanagement so not use mvnforum.mail.failed now
0282: if (MVNForumConfig.getRequireActivation()) {
0283: String serverName = ParamUtil.getServerPath();//ParamUtil.getServer2(request);
0284: try {
0285: SendMailUtil.sendActivationCodeEmail(memberID,
0286: serverName);
0287: } catch (Exception ex) {
0288: log.error("Cannot send mail after registration!", ex);
0289: request
0290: .setAttribute("mvnforum.mail.failed",
0291: "Cannot send activation email after registration!");
0292: //@todo: save the error message to displayed later
0293: }
0294: }
0295:
0296: String actionDesc = MVNForumResourceBundle.getString(
0297: MVNForumConfig.getEventLogLocale(),
0298: "mvnforum.eventlog.desc.AddMemberProcess",
0299: new Object[] { memberName });
0300: eventLogService.logEvent(onlineUser.getMemberName(), request
0301: .getRemoteAddr(),
0302: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
0303: MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
0304: "add members", actionDesc, EventLogService.MEDIUM);
0305:
0306: }
0307:
0308: public void processUpdateMemberStatus(GenericRequest request)
0309: throws BadInputException, ObjectNotFoundException,
0310: DatabaseException, AuthenticationException {
0311:
0312: OnlineUser onlineUser = onlineUserManager
0313: .getOnlineUser(request);
0314: MVNForumPermission permission = onlineUser.getPermission();
0315: permission.ensureCanModerateUser();
0316:
0317: // primary key column(s)
0318: int memberID = GenericParamUtil.getParameterInt(request,
0319: "memberid");
0320:
0321: // column(s) to update
0322: int memberStatus = GenericParamUtil.getParameterInt(request,
0323: "status");
0324: Locale locale = I18nUtil.getLocaleInRequest(request);
0325:
0326: // now check if status is in the valid range
0327: if ((memberStatus != MemberBean.MEMBER_STATUS_ENABLE)
0328: && (memberStatus != MemberBean.MEMBER_STATUS_DISABLE)) {
0329: String localizedMessage = MVNForumResourceBundle
0330: .getString(
0331: locale,
0332: "mvncore.exception.BadInputException.cannot_update_member_status.unknown_status",
0333: new Object[] { new Integer(memberStatus) });
0334: throw new BadInputException(localizedMessage);
0335: //throw new BadInputException("Cannot update member's status to an unknown status = " + memberStatus);
0336: }
0337:
0338: // This code make sure Admin always has Enable status
0339: if (memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN) {
0340: memberStatus = MemberBean.MEMBER_STATUS_ENABLE;
0341: }
0342: //IMPORTANT: Guest (id=MEMBER_ID_OF_GUEST) can be disabled by administrator.
0343: try {
0344: DAOFactory.getMemberDAO().updateStatus(memberID,
0345: memberStatus);
0346: } catch (ObjectNotFoundException e) {
0347: String localizedMessage = MVNForumResourceBundle
0348: .getString(
0349: locale,
0350: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0351: new Object[] { new Integer(memberID) });
0352: throw new ObjectNotFoundException(localizedMessage);
0353: }
0354: }
0355:
0356: public void prepareEdit(GenericRequest request)
0357: throws BadInputException, ObjectNotFoundException,
0358: DatabaseException, AuthenticationException {
0359:
0360: OnlineUser onlineUser = onlineUserManager
0361: .getOnlineUser(request);
0362: MVNForumPermission permission = onlineUser.getPermission();
0363: permission.ensureCanModerateUser();
0364:
0365: Locale locale = I18nUtil.getLocaleInRequest(request);
0366:
0367: int memberID = GenericParamUtil.getParameterInt(request,
0368: "memberid");
0369:
0370: MemberBean memberBean = null;
0371: try {
0372: memberBean = DAOFactory.getMemberDAO().getMember(memberID);
0373: } catch (ObjectNotFoundException e) {
0374: String localizedMessage = MVNForumResourceBundle
0375: .getString(
0376: locale,
0377: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0378: new Object[] { new Integer(memberID) });
0379: throw new ObjectNotFoundException(localizedMessage);
0380: }
0381:
0382: request.setAttribute("MemberBean", memberBean);
0383: }
0384:
0385: public void processEdit(GenericRequest request,
0386: GenericResponse response) throws BadInputException,
0387: ObjectNotFoundException, DatabaseException,
0388: AuthenticationException {
0389:
0390: OnlineUser onlineUser = onlineUserManager
0391: .getOnlineUser(request);
0392: MVNForumPermission permission = onlineUser.getPermission();
0393: permission.ensureCanModerateUser();
0394:
0395: MyUtil.saveVNTyperMode(request, response);
0396:
0397: int memberID = GenericParamUtil.getParameterInt(request,
0398: "memberid");
0399:
0400: Timestamp now = DateUtil.getCurrentGMTTimestamp();
0401:
0402: // column(s) to update
0403: int memberEmailVisible = GenericParamUtil.getParameterBoolean(
0404: request, "MemberEmailVisible") ? MemberBean.MEMBER_EMAIL_VISIBLE
0405: : MemberBean.MEMBER_EMAIL_INVISIBLE;
0406: int memberNameVisible = GenericParamUtil.getParameterBoolean(
0407: request, "MemberNameVisible") ? MemberBean.MEMBER_NAME_VISIBLE
0408: : MemberBean.MEMBER_NAME_INVISIBLE;
0409: int memberOption = 0;//GenericParamUtil.getParameterInt(request, "MemberOption");
0410: int memberStatus = GenericParamUtil.getParameterInt(request,
0411: "MemberStatus");
0412: int memberMessageOption = 0;//GenericParamUtil.getParameterInt(request, "MemberMessageOption");
0413: int memberPostsPerPage = GenericParamUtil.getParameterInt(
0414: request, "MemberPostsPerPage");
0415: if (memberPostsPerPage < 5) {
0416: memberPostsPerPage = 5;
0417: }
0418: double memberTimeZone = GenericParamUtil.getParameterTimeZone(
0419: request, "MemberTimeZone");
0420: String memberSkin = GenericParamUtil.getParameterSafe(request,
0421: "MemberSkin", false);
0422: String memberLanguage = GenericParamUtil.getParameterSafe(
0423: request, "MemberLanguage", false);
0424: String memberFirstname = GenericParamUtil.getParameterSafe(
0425: request, "MemberFirstname", true);
0426: String memberLastname = GenericParamUtil.getParameterSafe(
0427: request, "MemberLastname", true);
0428: int memberGender = GenericParamUtil.getParameterBoolean(
0429: request, "MemberGender") ? 1 : 0;
0430: Date memberBirthday = GenericParamUtil.getParameterDate(
0431: request, "MemberBirthday");
0432: String memberAddress = GenericParamUtil.getParameterSafe(
0433: request, "MemberAddress", false);
0434: String memberCity = GenericParamUtil.getParameterSafe(request,
0435: "MemberCity", false);
0436: String memberState = GenericParamUtil.getParameterSafe(request,
0437: "MemberState", false);
0438: String memberCountry = GenericParamUtil.getParameterSafe(
0439: request, "MemberCountry", false);
0440: String memberPhone = GenericParamUtil.getParameterSafe(request,
0441: "MemberPhone", false);
0442: String memberMobile = GenericParamUtil.getParameterSafe(
0443: request, "MemberMobile", false);
0444: String memberFax = GenericParamUtil.getParameterSafe(request,
0445: "MemberFax", false);
0446: String memberCareer = GenericParamUtil.getParameterSafe(
0447: request, "MemberCareer", false);
0448: String memberHomepage = GenericParamUtil.getParameterUrl(
0449: request, "MemberHomepage");
0450: String memberYahoo = GenericParamUtil.getParameterSafe(request,
0451: "MemberYahoo", false);
0452: String memberAol = GenericParamUtil.getParameterSafe(request,
0453: "MemberAol", false);
0454: String memberIcq = GenericParamUtil.getParameterSafe(request,
0455: "MemberIcq", false);
0456: String memberMsn = GenericParamUtil.getParameterSafe(request,
0457: "MemberMsn", false);
0458: String memberCoolLink1 = GenericParamUtil.getParameterUrl(
0459: request, "MemberCoolLink1");
0460: String memberCoolLink2 = GenericParamUtil.getParameterUrl(
0461: request, "MemberCoolLink2");
0462:
0463: try {
0464: DAOFactory.getMemberDAO().update(
0465: memberID, // primary key
0466: memberEmailVisible, memberNameVisible,
0467: now/*memberModifiedDate*/, memberOption,
0468: memberStatus, memberMessageOption,
0469: memberPostsPerPage, memberTimeZone, memberSkin,
0470: memberLanguage, memberFirstname, memberLastname,
0471: memberGender, memberBirthday, memberAddress,
0472: memberCity, memberState, memberCountry,
0473: memberPhone, memberMobile, memberFax, memberCareer,
0474: memberHomepage, memberYahoo, memberAol, memberIcq,
0475: memberMsn, memberCoolLink1, memberCoolLink2);
0476: } catch (ObjectNotFoundException ex) {
0477: Locale locale = I18nUtil.getLocaleInRequest(request);
0478: String localizedMessage = MVNForumResourceBundle
0479: .getString(
0480: locale,
0481: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0482: new Object[] { new Integer(memberID) });
0483: throw new ObjectNotFoundException(localizedMessage);
0484: }
0485:
0486: MemberBean justEditedMemberBean = DAOFactory.getMemberDAO()
0487: .getMember(memberID);
0488:
0489: MemberIndexer.scheduleUpdateMemberTask(justEditedMemberBean);
0490: //request.setAttribute("MemberBean", justEditedMemberBean);
0491: }
0492:
0493: public void prepareView(GenericRequest request)
0494: throws BadInputException, ObjectNotFoundException,
0495: DatabaseException, AuthenticationException {
0496:
0497: OnlineUser onlineUser = onlineUserManager
0498: .getOnlineUser(request);
0499: MVNForumPermission permission = onlineUser.getPermission();
0500: permission.ensureCanModerateUser();
0501:
0502: Locale locale = I18nUtil.getLocaleInRequest(request);
0503:
0504: String strMemberID = GenericParamUtil.getParameter(request,
0505: "memberid", false);
0506: String strMemberName = GenericParamUtil.getParameter(request,
0507: "member", false);
0508: String strMemberEmail = GenericParamUtil.getParameter(request,
0509: "memberemail", false);
0510:
0511: int memberID;
0512: MemberBean memberBean = null;
0513:
0514: if (strMemberID.length() > 0) {
0515: memberID = GenericParamUtil.getParameterInt(request,
0516: "memberid");
0517: } else if (strMemberName.length() > 0) {
0518: /**@todo: improve this for better performance(dont use this method,
0519: * and write 2 new methods)*/
0520: StringUtil.checkGoodName(strMemberName);// check for better security
0521: try {
0522: memberID = DAOFactory.getMemberDAO()
0523: .getMemberIDFromMemberName(strMemberName);
0524: } catch (ObjectNotFoundException e) {
0525: String localizedMessage = MVNForumResourceBundle
0526: .getString(
0527: locale,
0528: "mvncore.exception.ObjectNotFoundException.membername_not_exists",
0529: new Object[] { strMemberName });
0530: throw new ObjectNotFoundException(localizedMessage);
0531: }
0532:
0533: // now, in the LDAP case, we can get memberID from memberName does not mean user is in LDAP or not,
0534: // so we must check if the whole memberBean can be loaded or not
0535: try {
0536: memberBean = DAOFactory.getMemberDAO().getMember(
0537: memberID);
0538: } catch (ObjectNotFoundException e) {
0539: throw new ObjectNotFoundException(
0540: "Member with login id = "
0541: + strMemberName
0542: + " has been deleted externally (for example, in LDAP) but the numeric id ("
0543: + memberID + ") still in the database.");
0544: }
0545: } else if (strMemberEmail.length() > 0) {
0546: String memberEmail = GenericParamUtil.getParameterEmail(
0547: request, "memberemail");// check for better security
0548: try {
0549: memberID = DAOFactory.getMemberDAO()
0550: .getMemberIDFromMemberEmail(memberEmail);
0551: } catch (ObjectNotFoundException e) {
0552: String localizedMessage = MVNForumResourceBundle
0553: .getString(
0554: locale,
0555: "mvncore.exception.ObjectNotFoundException.memberemail_not_exists",
0556: new Object[] { memberEmail });
0557: throw new ObjectNotFoundException(localizedMessage);
0558: }
0559: } else {
0560: String localizedMessage = MVNForumResourceBundle
0561: .getString(locale,
0562: "mvncore.exception.BadInputException.cannot_get_member_info");
0563: throw new BadInputException(localizedMessage);
0564: //throw new BadInputException("Cannot get the information to view member.");
0565: }
0566:
0567: // Update statistics to make sure Admin can delete this user
0568: // with the actual memberPostCount
0569: try {
0570: StatisticsUtil.updateMemberStatistics(memberID);
0571: } catch (ObjectNotFoundException e) {
0572: String localizedMessage = MVNForumResourceBundle
0573: .getString(
0574: locale,
0575: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0576: new Object[] { new Integer(memberID) });
0577: throw new ObjectNotFoundException(localizedMessage);
0578: }
0579:
0580: int toMessageCount = 0;
0581: int fromMessageCount = 0;
0582:
0583: String toDay = GenericParamUtil.getParameter(request, "toDay",
0584: false);
0585: String toMonth = GenericParamUtil.getParameter(request,
0586: "toMonth", false);
0587: String toYear = GenericParamUtil.getParameter(request,
0588: "toYear", false);
0589:
0590: String fromDay = GenericParamUtil.getParameter(request,
0591: "fromDay", false);
0592: String fromMonth = GenericParamUtil.getParameter(request,
0593: "fromMonth", false);
0594: String fromYear = GenericParamUtil.getParameter(request,
0595: "fromYear", false);
0596:
0597: if (!toDay.equals("") && !toMonth.equals("")
0598: && !toYear.equals("") && !fromDay.equals("")
0599: && !fromMonth.equals("") && !fromYear.equals("")) {
0600: Timestamp from = new Timestamp(GenericParamUtil
0601: .getParameterDate(request, "fromDay", "fromMonth",
0602: "fromYear").getTime());
0603: Timestamp to = new Timestamp(GenericParamUtil
0604: .getParameterDate(request, "toDay", "toMonth",
0605: "toYear").getTime());
0606:
0607: toMessageCount = DAOFactory.getMessageStatisticsDAO()
0608: .getNumberOfBeans_inToID_supportTimestamp(memberID,
0609: from, to);
0610: fromMessageCount = DAOFactory.getMessageStatisticsDAO()
0611: .getNumberOfBeans_inFromID_supportTimestamp(
0612: memberID, from, to);
0613: } else {
0614: toMessageCount = DAOFactory.getMessageStatisticsDAO()
0615: .getNumberOfBeans_inToID(memberID);
0616: fromMessageCount = DAOFactory.getMessageStatisticsDAO()
0617: .getNumberOfBeans_inFromID(memberID);
0618: }
0619:
0620: try {
0621: if (memberBean == null) {
0622: memberBean = DAOFactory.getMemberDAO().getMember(
0623: memberID);
0624: }
0625: } catch (ObjectNotFoundException e) {
0626: String localizedMessage = MVNForumResourceBundle
0627: .getString(
0628: locale,
0629: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0630: new Object[] { new Integer(memberID) });
0631: throw new ObjectNotFoundException(localizedMessage);
0632: }
0633: int watchCount = DAOFactory.getWatchDAO()
0634: .getNumberOfWatches_forMember(memberID);
0635:
0636: request.setAttribute("MemberBean", memberBean);
0637: request.setAttribute("WatchCount", new Integer(watchCount));
0638:
0639: request.setAttribute("ToMessageCount", new Integer(
0640: toMessageCount));
0641: request.setAttribute("FromMessageCount", new Integer(
0642: fromMessageCount));
0643: request.setAttribute("toDay", toDay);
0644: request.setAttribute("toMonth", toMonth);
0645: request.setAttribute("toYear", toYear);
0646: request.setAttribute("fromDay", fromDay);
0647: request.setAttribute("fromMonth", fromMonth);
0648: request.setAttribute("fromYear", toYear);
0649: }
0650:
0651: public void processUpdateMemberTitle(GenericRequest request,
0652: GenericResponse response) throws BadInputException,
0653: DatabaseException, ObjectNotFoundException,
0654: AuthenticationException {
0655:
0656: SecurityUtil.checkHttpPostMethod(request);
0657:
0658: OnlineUser onlineUser = onlineUserManager
0659: .getOnlineUser(request);
0660: MVNForumPermission permission = onlineUser.getPermission();
0661: permission.ensureCanModerateUser();
0662:
0663: MyUtil.saveVNTyperMode(request, response);
0664:
0665: // primary key column(s)
0666: int memberID = GenericParamUtil.getParameterInt(request,
0667: "MemberID");
0668:
0669: // column(s) to update
0670: String memberTitle = GenericParamUtil.getParameterSafe(request,
0671: "MemberTitle", false);
0672: Locale locale = I18nUtil.getLocaleInRequest(request);
0673: try {
0674: DAOFactory.getMemberDAO()
0675: .updateTitle(memberID, memberTitle);
0676: } catch (ObjectNotFoundException e) {
0677: String localizedMessage = MVNForumResourceBundle
0678: .getString(
0679: locale,
0680: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0681: new Object[] { new Integer(memberID) });
0682: throw new ObjectNotFoundException(localizedMessage);
0683: }
0684: }
0685:
0686: public void processResetMemberSignature(GenericRequest request)
0687: throws BadInputException, DatabaseException,
0688: ObjectNotFoundException, AuthenticationException {
0689:
0690: OnlineUser onlineUser = onlineUserManager
0691: .getOnlineUser(request);
0692: MVNForumPermission permission = onlineUser.getPermission();
0693: permission.ensureCanModerateUser();
0694:
0695: Locale locale = I18nUtil.getLocaleInRequest(request);
0696: int memberID = GenericParamUtil.getParameterInt(request,
0697: "memberid");
0698: try {
0699: DAOFactory.getMemberDAO().updateSignature(memberID, "");
0700: } catch (ObjectNotFoundException e) {
0701: String localizedMessage = MVNForumResourceBundle
0702: .getString(
0703: locale,
0704: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0705: new Object[] { new Integer(memberID) });
0706: throw new ObjectNotFoundException(localizedMessage);
0707: }
0708:
0709: request.setAttribute("MemberID", new Integer(memberID));
0710: }
0711:
0712: public void processResetMemberAvatar(GenericRequest request)
0713: throws BadInputException, DatabaseException,
0714: ObjectNotFoundException, AuthenticationException {
0715:
0716: OnlineUser onlineUser = onlineUserManager
0717: .getOnlineUser(request);
0718: MVNForumPermission permission = onlineUser.getPermission();
0719: permission.ensureCanModerateUser();
0720:
0721: Locale locale = I18nUtil.getLocaleInRequest(request);
0722: int memberID = GenericParamUtil.getParameterInt(request,
0723: "memberid");
0724: try {
0725: DAOFactory.getMemberDAO().updateAvatar(memberID, "");
0726: } catch (ObjectNotFoundException e) {
0727: String localizedMessage = MVNForumResourceBundle
0728: .getString(
0729: locale,
0730: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0731: new Object[] { new Integer(memberID) });
0732: throw new ObjectNotFoundException(localizedMessage);
0733: }
0734:
0735: request.setAttribute("MemberID", new Integer(memberID));
0736: }
0737:
0738: public void processResetMemberActivation(GenericRequest request)
0739: throws BadInputException, DatabaseException,
0740: ObjectNotFoundException, AuthenticationException {
0741:
0742: OnlineUser onlineUser = onlineUserManager
0743: .getOnlineUser(request);
0744: MVNForumPermission permission = onlineUser.getPermission();
0745: permission.ensureCanModerateUser();// TODO: should check if we need AdminSystem permission to do this action
0746:
0747: Locale locale = I18nUtil.getLocaleInRequest(request);
0748: int memberID = GenericParamUtil.getParameterInt(request,
0749: "memberid");
0750: try {
0751: DAOFactory.getMemberDAO().updateActivateCode(memberID, "");
0752: } catch (ObjectNotFoundException e) {
0753: String localizedMessage = MVNForumResourceBundle
0754: .getString(
0755: locale,
0756: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0757: new Object[] { new Integer(memberID) });
0758: throw new ObjectNotFoundException(localizedMessage);
0759: }
0760:
0761: request.setAttribute("MemberID", new Integer(memberID));
0762: }
0763:
0764: public void prepareDeleteMember(GenericRequest request)
0765: throws BadInputException, DatabaseException,
0766: ObjectNotFoundException, AuthenticationException {
0767:
0768: OnlineUser onlineUser = onlineUserManager
0769: .getOnlineUser(request);
0770: MVNForumPermission permission = onlineUser.getPermission();
0771: permission.ensureCanAdminSystem();
0772:
0773: Locale locale = I18nUtil.getLocaleInRequest(request);
0774:
0775: int memberID = GenericParamUtil.getParameterInt(request,
0776: "memberid");
0777: if ((memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN)
0778: || (memberID == 0)
0779: || (memberID == onlineUser.getMemberID())
0780: || (memberID == MVNForumConstant.MEMBER_ID_OF_GUEST)) {
0781:
0782: String localizedMessage = MVNForumResourceBundle
0783: .getString(locale,
0784: "mvncore.exception.BadInputException.cannot_delete_admin_or_guest");
0785: throw new BadInputException(localizedMessage);
0786: //throw new BadInputException("Cannot delete default Admin and Guest users.");
0787: }
0788:
0789: MemberBean memberBean = null;
0790: try {
0791: memberBean = DAOFactory.getMemberDAO().getMember(memberID);
0792: } catch (ObjectNotFoundException e) {
0793: String localizedMessage = MVNForumResourceBundle
0794: .getString(
0795: locale,
0796: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0797: new Object[] { new Integer(memberID) });
0798: throw new ObjectNotFoundException(localizedMessage);
0799: }
0800:
0801: request.setAttribute("MemberBean", memberBean);
0802: }
0803:
0804: public void processDeleteMember(GenericRequest request)
0805: throws BadInputException, DatabaseException,
0806: ObjectNotFoundException, AuthenticationException {
0807:
0808: SecurityUtil.checkHttpPostMethod(request);
0809:
0810: OnlineUser onlineUser = onlineUserManager
0811: .getOnlineUser(request);
0812: MVNForumPermission permission = onlineUser.getPermission();
0813: permission.ensureCanAdminSystem();
0814:
0815: Locale locale = I18nUtil.getLocaleInRequest(request);
0816:
0817: // now check the password
0818: MyUtil.ensureCorrectCurrentPassword(request);
0819:
0820: int memberID = GenericParamUtil.getParameterInt(request,
0821: "memberid");
0822: if ((memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN)
0823: || (memberID == 0)
0824: || (memberID == onlineUser.getMemberID())
0825: || (memberID == MVNForumConstant.MEMBER_ID_OF_GUEST)) {
0826: String localizedMessage = MVNForumResourceBundle
0827: .getString(locale,
0828: "mvncore.exception.BadInputException.cannot_delete_admin_or_guest");
0829: throw new BadInputException(localizedMessage);
0830: //throw new BadInputException("Cannot delete default Admin and Guest users.");
0831: }
0832:
0833: boolean deleteSentMessages = GenericParamUtil
0834: .getParameterBoolean(request, "deletesentmessages");
0835:
0836: MemberBean memberBean = null;
0837: try {
0838: memberBean = DAOFactory.getMemberDAO().getMember(memberID);
0839: } catch (ObjectNotFoundException e) {
0840: String localizedMessage = MVNForumResourceBundle
0841: .getString(
0842: locale,
0843: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0844: new Object[] { new Integer(memberID) });
0845: throw new ObjectNotFoundException(localizedMessage);
0846: }
0847:
0848: MemberWebHandler.deleteMember(memberBean, deleteSentMessages, /*context*/
0849: request, locale);
0850:
0851: String actionDesc = MVNForumResourceBundle.getString(
0852: MVNForumConfig.getEventLogLocale(),
0853: "mvnforum.eventlog.desc.DeleteMemberProcess",
0854: new Object[] { new Integer(memberID) });
0855: eventLogService.logEvent(onlineUser.getMemberName(), request
0856: .getRemoteAddr(),
0857: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
0858: MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
0859: "delete member", actionDesc, EventLogService.HIGH);
0860: }
0861:
0862: /**
0863: * This method supports sorting base on many criteria
0864: */
0865: public void prepareShowUserManagement(GenericRequest request)
0866: throws DatabaseException, BadInputException,
0867: AuthenticationException {
0868:
0869: OnlineUser onlineUser = onlineUserManager
0870: .getOnlineUser(request);
0871: MVNForumPermission permission = onlineUser.getPermission();
0872: permission.ensureCanModerateUser();
0873:
0874: Locale locale = I18nUtil.getLocaleInRequest(request);
0875:
0876: // for sort and order stuff
0877: String sort = GenericParamUtil.getParameter(request, "sort");
0878: String order = GenericParamUtil.getParameter(request, "order");
0879: if (sort.length() == 0)
0880: sort = "MemberCreationDate";
0881: if (order.length() == 0)
0882: order = "DESC";
0883:
0884: // we continue
0885: int postsPerPage = onlineUser.getPostsPerPage();
0886: int offset = 0;
0887: try {
0888: offset = GenericParamUtil.getParameterUnsignedInt(request,
0889: "offset");
0890: } catch (BadInputException e) {
0891: // do nothing
0892: }
0893:
0894: int totalMembers = 0;
0895: Collection memberBeans = new ArrayList();
0896: int enabledMembers = 0;
0897: int pendingMembers = 0;
0898: int activatedMembers = 0;
0899: int nonactivatedMembers = 0;
0900: int disabledMembers = 0;
0901: if (DAOFactory.getMemberDAO()
0902: .isSupportGetMembers_withSortSupport_limit()) {
0903: if (DAOFactory.getMemberDAO().isSupportGetNumberOfMembers()) {
0904: totalMembers = DAOFactory.getMemberDAO()
0905: .getNumberOfMembers();
0906: }
0907: if (offset > totalMembers) {
0908: String localizedMessage = MVNForumResourceBundle
0909: .getString(locale,
0910: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
0911: throw new BadInputException(localizedMessage);
0912: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
0913: }
0914: memberBeans = DAOFactory.getMemberDAO()
0915: .getMembers_withSortSupport_limit(offset,
0916: postsPerPage, sort, order,
0917: MemberDAO.ALL_MEMBER_STATUS);
0918:
0919: if (DAOFactory.getMemberDAO()
0920: .isSupportGetNumberOfMembers_inActivationStatus()) {
0921: activatedMembers = DAOFactory.getMemberDAO()
0922: .getNumberOfMembers_inActivationStatus(true);
0923: nonactivatedMembers = DAOFactory.getMemberDAO()
0924: .getNumberOfMembers_inActivationStatus(false);
0925: if ((activatedMembers + nonactivatedMembers) != totalMembers) {
0926: // please do not localize this
0927: throw new AssertionError(
0928: "Assertion: (activatedMembers + nonactivatedMembers) == totalMembers");
0929: }
0930: }
0931:
0932: if (DAOFactory.getMemberDAO()
0933: .isSupportGetNumberOfMembers_inMemberStatus()) {
0934: disabledMembers = DAOFactory.getMemberDAO()
0935: .getNumberOfMembers_inMemberStatus(
0936: MemberBean.MEMBER_STATUS_DISABLE);
0937: enabledMembers = DAOFactory.getMemberDAO()
0938: .getNumberOfMembers_inMemberStatus(
0939: MemberBean.MEMBER_STATUS_ENABLE);
0940: pendingMembers = DAOFactory.getMemberDAO()
0941: .getNumberOfMembers_inMemberStatus(
0942: MemberBean.MEMBER_STATUS_PENDING);
0943: if ((disabledMembers + enabledMembers + pendingMembers) != totalMembers) {
0944: // please do not localize this
0945: throw new AssertionError(
0946: "Assertion: (disabledMembers + enabledMembers + pendingMembers) == totalMembers");
0947: }
0948: }
0949: }
0950: request.setAttribute("MemberBeans", memberBeans);
0951: request.setAttribute("TotalMembers", new Integer(totalMembers));
0952: request.setAttribute("EnabledMembers", new Integer(
0953: enabledMembers));
0954: request.setAttribute("DisabledMembers", new Integer(
0955: disabledMembers));
0956: request.setAttribute("PendingMembers", new Integer(
0957: pendingMembers));
0958: request.setAttribute("ActivatedMembers", new Integer(
0959: activatedMembers));
0960: request.setAttribute("NonActivatedMembers", new Integer(
0961: nonactivatedMembers));
0962: request.setAttribute("offset", new Integer(offset));
0963: }
0964:
0965: public void prepareListUserExpire(GenericRequest request)
0966: throws DatabaseException, BadInputException,
0967: AuthenticationException {
0968:
0969: OnlineUser onlineUser = onlineUserManager
0970: .getOnlineUser(request);
0971: MVNForumPermission permission = onlineUser.getPermission();
0972: permission.ensureCanAdminSystem();
0973:
0974: // for sort and order stuff
0975: String sort = GenericParamUtil.getParameter(request, "sort");
0976: String order = GenericParamUtil.getParameter(request, "order");
0977: if (sort.length() == 0)
0978: sort = "MemberExpireDate";
0979: if (order.length() == 0)
0980: order = "ASC";
0981:
0982: // we continue
0983: int postsPerPage = onlineUser.getPostsPerPage();
0984: int offset = 0;
0985: try {
0986: offset = GenericParamUtil.getParameterUnsignedInt(request,
0987: "offset");
0988: } catch (BadInputException e) {
0989: // do nothing
0990: }
0991: Timestamp expiresoonDate = DateUtil
0992: .getCurrentGMTTimestampExpiredDay(7 /*MVNForumConfig.getExpireSoonDate()*/);
0993:
0994: int totalExpireMembers = DAOFactory.getMemberDAO()
0995: .getNumberOfMembers_inExpire(expiresoonDate);
0996: if (offset > totalExpireMembers) {
0997: //@todo : localize me
0998: throw new BadInputException(
0999: "The offset is not allowed to be greater than total members.");
1000: }
1001:
1002: Collection expireMemberBeans = DAOFactory.getMemberDAO()
1003: .getMembers_inExpire_limit(expiresoonDate, offset,
1004: postsPerPage, sort, order);
1005:
1006: request.setAttribute("TotalMembers", new Integer(
1007: totalExpireMembers));
1008: request.setAttribute("ExpireMemberBeans", expireMemberBeans);
1009: request.setAttribute("offset", new Integer(offset));
1010: }
1011:
1012: public void prepareListPendingUsers(GenericRequest request)
1013: throws DatabaseException, BadInputException,
1014: AuthenticationException {
1015:
1016: OnlineUser onlineUser = onlineUserManager
1017: .getOnlineUser(request);
1018: MVNForumPermission permission = onlineUser.getPermission();
1019: permission.ensureCanModerateUser();
1020:
1021: Locale locale = I18nUtil.getLocaleInRequest(request);
1022:
1023: // for sort and order stuff
1024: String sort = GenericParamUtil.getParameter(request, "sort");
1025: String order = GenericParamUtil.getParameter(request, "order");
1026: if (sort.length() == 0)
1027: sort = "MemberCreationDate";
1028: if (order.length() == 0)
1029: order = "DESC";
1030:
1031: // we continue
1032: int postsPerPage = onlineUser.getPostsPerPage();
1033: int offset = 0;
1034: try {
1035: offset = GenericParamUtil.getParameterUnsignedInt(request,
1036: "offset");
1037: } catch (BadInputException e) {
1038: // do nothing
1039: }
1040:
1041: int pendingMembersCount = 0;
1042: Collection pendingMemberBeans = new ArrayList();
1043:
1044: if (DAOFactory.getMemberDAO()
1045: .isSupportGetMembers_withSortSupport_limit()
1046: && DAOFactory.getMemberDAO()
1047: .isSupportGetNumberOfMembers_inMemberStatus()) {
1048:
1049: pendingMembersCount = DAOFactory.getMemberDAO()
1050: .getNumberOfMembers_inMemberStatus(
1051: MemberBean.MEMBER_STATUS_PENDING);
1052: if (offset > pendingMembersCount) {
1053: String localizedMessage = MVNForumResourceBundle
1054: .getString(locale,
1055: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1056: throw new BadInputException(localizedMessage);
1057: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
1058: }
1059: pendingMemberBeans = DAOFactory.getMemberDAO()
1060: .getMembers_withSortSupport_limit(offset,
1061: postsPerPage, sort, order,
1062: MemberBean.MEMBER_STATUS_PENDING);
1063: }
1064: request.setAttribute("PendingMemberBeans", pendingMemberBeans);
1065: request.setAttribute("PendingMembers", new Integer(
1066: pendingMembersCount));
1067: request.setAttribute("offset", new Integer(offset));
1068: }
1069:
1070: public void processListPendingUsers(GenericRequest request)
1071: throws DatabaseException, AuthenticationException,
1072: BadInputException, DatabaseException,
1073: ObjectNotFoundException {
1074:
1075: SecurityUtil.checkHttpPostMethod(request);
1076:
1077: OnlineUser onlineUser = onlineUserManager
1078: .getOnlineUser(request);
1079: MVNForumPermission permission = onlineUser.getPermission();
1080: permission.ensureCanModerateUser();
1081:
1082: Locale locale = I18nUtil.getLocaleInRequest(request);
1083:
1084: String prefix = "listpendingaction_";
1085: for (Enumeration enumeration = request.getParameterNames(); enumeration
1086: .hasMoreElements();) {
1087: String param = (String) enumeration.nextElement();
1088: if (param.startsWith(prefix)) {
1089: String actionValue = GenericParamUtil.getParameter(
1090: request, param, true);
1091: String strMemberID = param.substring(prefix.length());
1092: int memberID = 0;
1093: MemberBean memberBean = null;
1094: try {
1095: memberID = Integer.parseInt(strMemberID);
1096: memberBean = DAOFactory.getMemberDAO().getMember(
1097: memberID);
1098: } catch (ObjectNotFoundException ex) {
1099: String localizedMessage = MVNForumResourceBundle
1100: .getString(
1101: locale,
1102: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
1103: new Object[] { new Integer(memberID) });
1104: throw new ObjectNotFoundException(localizedMessage);
1105: } catch (NumberFormatException nfe) {
1106: String localizedMessage = MVNCoreResourceBundle
1107: .getString(
1108: locale,
1109: "mvncore.exception.BadInputException.cannot_parse",
1110: new Object[] {
1111: DisableHtmlTagFilter
1112: .filter(strMemberID),
1113: "int" });
1114: throw new BadInputException(localizedMessage);
1115: }
1116:
1117: if (actionValue.equals("enable")) {
1118: DAOFactory.getMemberDAO().updateStatus(memberID,
1119: MemberBean.MEMBER_STATUS_ENABLE);
1120: String actionDesc = MVNForumResourceBundle
1121: .getString(
1122: MVNForumConfig.getEventLogLocale(),
1123: "mvnforum.eventlog.desc.EnableMemberProcess",
1124: new Object[] { new Integer(memberID) });
1125: eventLogService
1126: .logEvent(
1127: onlineUser.getMemberName(),
1128: request.getRemoteAddr(),
1129: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
1130: MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
1131: "enable pending member",
1132: actionDesc, EventLogService.MEDIUM);
1133: } else if (actionValue.equals("delete")) {
1134: MemberWebHandler.deleteMember(memberBean, true,
1135: request, locale);
1136: String actionDesc = MVNForumResourceBundle
1137: .getString(
1138: MVNForumConfig.getEventLogLocale(),
1139: "mvnforum.eventlog.desc.DeleteMemberProcess",
1140: new Object[] { new Integer(memberID) });
1141: eventLogService
1142: .logEvent(
1143: onlineUser.getMemberName(),
1144: request.getRemoteAddr(),
1145: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
1146: MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
1147: "delete pending member",
1148: actionDesc, EventLogService.MEDIUM);
1149: } else if (actionValue.equals("ignore")) {
1150: // we do nothing here
1151: } else {
1152: throw new IllegalArgumentException(
1153: "Cannot accept action = " + actionValue);
1154: }
1155: }
1156: }
1157: request.setAttribute("Offset", GenericParamUtil.getParameter(
1158: request, "offset"));
1159: }
1160:
1161: public void updateMemberExpireProcess(GenericRequest request)
1162: throws DatabaseException, BadInputException,
1163: ObjectNotFoundException, AuthenticationException {
1164:
1165: SecurityUtil.checkHttpPostMethod(request);
1166:
1167: OnlineUser onlineUser = onlineUserManager
1168: .getOnlineUser(request);
1169: MVNForumPermission permission = onlineUser.getPermission();
1170: permission.ensureCanAdminSystem();
1171:
1172: String renew = GenericParamUtil.getParameter(request, "renew");
1173: String disable = GenericParamUtil.getParameter(request,
1174: "disable");
1175: String enable = GenericParamUtil
1176: .getParameter(request, "enable");
1177: int expiredDays = GenericParamUtil.getParameterUnsignedInt(
1178: request, "addtime");
1179:
1180: String[] checkList = request
1181: .getParameterValues("selectedmember");
1182: if (checkList == null)
1183: return;
1184:
1185: if (renew.equals("Renew")) {
1186: //renew creation date and expire date
1187: long offsetDate = expiredDays * DateUtil.DAY;
1188: Timestamp now = DateUtil.getCurrentGMTTimestamp();
1189: for (int i = 0; (checkList != null)
1190: && (i < checkList.length); i++) {
1191: int memberID = Integer.parseInt(checkList[i]);
1192: log.debug("Renew expiration date for MemberID = "
1193: + memberID);
1194: try {
1195: MemberBean memberBean = DAOFactory.getMemberDAO()
1196: .getMember(memberID);
1197: Timestamp expireDate = memberBean
1198: .getMemberExpireDate();
1199: if (expireDate == null) {
1200: expireDate = now;
1201: }
1202: Timestamp memberExpireDate = new Timestamp(
1203: expireDate.getTime() + offsetDate);
1204: DAOFactory.getMemberDAO().updateMember_expireDate(
1205: memberID, memberExpireDate);
1206: } catch (ObjectNotFoundException e) {
1207: Locale locale = I18nUtil
1208: .getLocaleInRequest(request);
1209: String localizedMessage = MVNForumResourceBundle
1210: .getString(
1211: locale,
1212: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
1213: new Object[] { new Integer(memberID) });
1214: throw new ObjectNotFoundException(localizedMessage);
1215: }
1216: }
1217: } else if (disable.equals("Disable")) {
1218: for (int i = 0; (checkList != null)
1219: && (i < checkList.length); i++) {
1220: int memberID = Integer.parseInt(checkList[i]);
1221: log.debug("Disable member with MemberID = " + memberID);
1222: try {
1223: DAOFactory.getMemberDAO().updateStatus(memberID,
1224: MemberBean.MEMBER_STATUS_DISABLE);
1225: } catch (ObjectNotFoundException e) {
1226: Locale locale = I18nUtil
1227: .getLocaleInRequest(request);
1228: String localizedMessage = MVNForumResourceBundle
1229: .getString(
1230: locale,
1231: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
1232: new Object[] { new Integer(memberID) });
1233: throw new ObjectNotFoundException(localizedMessage);
1234: }
1235: }
1236: } else if (enable.equals("Enable")) {
1237: for (int i = 0; (checkList != null)
1238: && (i < checkList.length); i++) {
1239: int memberID = Integer.parseInt(checkList[i]);
1240: log.debug("Enable member with MemberID = " + memberID);
1241: try {
1242: DAOFactory.getMemberDAO().updateStatus(memberID,
1243: MemberBean.MEMBER_STATUS_ENABLE);
1244: } catch (ObjectNotFoundException e) {
1245: Locale locale = I18nUtil
1246: .getLocaleInRequest(request);
1247: String localizedMessage = MVNForumResourceBundle
1248: .getString(
1249: locale,
1250: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
1251: new Object[] { new Integer(memberID) });
1252: throw new ObjectNotFoundException(localizedMessage);
1253: }
1254: }
1255: }
1256: }
1257:
1258: public void processSearch(GenericRequest request)
1259: throws BadInputException, IOException, DatabaseException,
1260: ObjectNotFoundException, AuthenticationException {
1261:
1262: if (DAOFactory.getMemberDAO().isSupportGetMembersFromIDRange() == false) {
1263: throw new IllegalArgumentException(
1264: "Cannot search member because this method is not supported: MemberDAO.isSupportGetMembersFromIDRange()");
1265: }
1266:
1267: OnlineUser onlineUser = onlineUserManager
1268: .getOnlineUser(request);
1269: MVNForumPermission permission = onlineUser.getPermission();
1270: permission.ensureCanModerateUser();
1271:
1272: String memberNameKey = GenericParamUtil.getParameter(request,
1273: "membername", false);
1274: String memberEmailKey = GenericParamUtil.getParameter(request,
1275: "email", false);
1276: String memberLastNameKey = GenericParamUtil.getParameter(
1277: request, "lastname", false);
1278: String memberFirstNameKey = GenericParamUtil.getParameter(
1279: request, "firstname", false);
1280: String memberCountryKey = GenericParamUtil.getParameter(
1281: request, "country", false);
1282:
1283: if ((memberNameKey.length() == 0)
1284: && (memberEmailKey.length() == 0)
1285: && (memberLastNameKey.length() == 0)
1286: && (memberFirstNameKey.length() == 0)
1287: && (memberCountryKey.length() == 0)) {
1288: return;
1289: }
1290:
1291: Locale locale = I18nUtil.getLocaleInRequest(request);
1292:
1293: int defaultRows = onlineUser.getPostsPerPage();
1294:
1295: int offset = GenericParamUtil.getParameterUnsignedInt(request,
1296: "offset", 0);
1297: int rows = GenericParamUtil.getParameterUnsignedInt(request,
1298: "rows", defaultRows);
1299: if (rows == 0) {
1300: rows = defaultRows;// fix NullPointerException when rows = 0
1301: }
1302:
1303: // offset should be even when divide with rowsToReturn
1304: offset = (offset / rows) * rows;
1305:
1306: MemberSearchQuery query = new MemberSearchQuery();
1307: boolean isNullKey = true;
1308: if (memberNameKey.length() > 0) {
1309: query.setMemberNameKey(memberNameKey);
1310: isNullKey = false;
1311: }
1312: if (memberEmailKey.length() > 0) {
1313: query.setMemberEmailKey(memberEmailKey);
1314: isNullKey = false;
1315: }
1316: if (memberLastNameKey.length() > 0) {
1317: query.setMemberLastNameKey(memberLastNameKey);
1318: isNullKey = false;
1319: }
1320: if (memberFirstNameKey.length() > 0) {
1321: query.setMemberFirstNameKey(memberFirstNameKey);
1322: isNullKey = false;
1323: }
1324: if (memberCountryKey.length() > 0) {
1325: query.setCountry(memberCountryKey);
1326: isNullKey = false;
1327: }
1328: if (isNullKey) {
1329: String localizedMessage = MVNForumResourceBundle
1330: .getString(locale,
1331: "mvncore.exception.BadInputException.cannot_search.key_is_null");
1332: throw new BadInputException(localizedMessage);
1333: }
1334:
1335: int searchDate = GenericParamUtil.getParameterUnsignedInt(
1336: request, "date", MemberSearchQuery.SEARCH_ANY_DATE);
1337: int searchBeforeAfter = GenericParamUtil.getParameterInt(
1338: request, "beforeafter", MemberSearchQuery.SEARCH_NEWER);
1339:
1340: if ((searchDate != MemberSearchQuery.SEARCH_ANY_DATE)
1341: && (searchDate < 365 * 10)) { // 10 years
1342: long deltaTime = DateUtil.DAY * searchDate;
1343:
1344: Timestamp now = DateUtil.getCurrentGMTTimestamp();
1345: Timestamp from = null;
1346: Timestamp to = null;
1347:
1348: long currentTime = now.getTime();
1349:
1350: if (searchBeforeAfter == MemberSearchQuery.SEARCH_NEWER) {
1351: from = new Timestamp(currentTime - deltaTime);
1352: } else {// older
1353: to = new Timestamp(currentTime - deltaTime);
1354: }
1355:
1356: query.setFromDate(from);
1357: query.setToDate(to);
1358: }
1359:
1360: query.searchDocuments(offset, rows);
1361: int hitCount = query.getHitCount();
1362: Collection result = query.getMemberResult();
1363:
1364: if (offset > hitCount) {
1365: String localizedMessage = MVNForumResourceBundle
1366: .getString(locale,
1367: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1368: throw new BadInputException(localizedMessage);
1369: }
1370:
1371: request.setAttribute("offset", new Integer(offset));
1372: request.setAttribute("rows", new Integer(rows));
1373: request.setAttribute("TotalMembers", new Integer(hitCount));
1374: request.setAttribute("MemberBeans", result);
1375: request.setAttribute("MemberName", memberNameKey);
1376: request.setAttribute("MemberEmail", memberEmailKey);
1377: request.setAttribute("MemberLastname", memberLastNameKey);
1378: request.setAttribute("MemberFirstname", memberFirstNameKey);
1379: request.setAttribute("MemberCountry", memberCountryKey);
1380: request.setAttribute("DateOption", new Integer(searchDate));
1381: request.setAttribute("BeforeAfterOption", new Integer(
1382: searchBeforeAfter));
1383: }
1384:
1385: public void preparePermissionSummary(GenericRequest request)
1386: throws DatabaseException, ObjectNotFoundException,
1387: AuthenticationException {
1388:
1389: OnlineUser onlineUser = onlineUserManager
1390: .getOnlineUser(request);
1391: MVNForumPermission permission = onlineUser.getPermission();
1392: permission.ensureCanAdminSystem();
1393:
1394: Collection authorizedMembers = new ArrayList();
1395: if (DAOFactory.getMemberDAO().isSupportGetAuthorizedMembers()) {
1396: authorizedMembers = DAOFactory.getMemberDAO()
1397: .getAuthorizedMembers();
1398: }
1399: Collection forumsAuthorizedMembers = new ArrayList();
1400: if (DAOFactory.getMemberDAO()
1401: .isSupportGetForumsAuthorizedMembers()) {
1402: forumsAuthorizedMembers = DAOFactory.getMemberDAO()
1403: .getForumsAuthorizedMembers();
1404: }
1405:
1406: Collection distinctAuthorizedGroups = DAOFactory
1407: .getGroupPermissionDAO().getDistinctGroups();
1408: Collection authorizedGroups = new ArrayList(
1409: distinctAuthorizedGroups.size());
1410: for (Iterator iter = distinctAuthorizedGroups.iterator(); iter
1411: .hasNext();) {
1412: GroupPermissionBean item = (GroupPermissionBean) iter
1413: .next();
1414: GroupsBean groupBean = DAOFactory.getGroupsDAO().getGroup(
1415: item.getGroupID());
1416: authorizedGroups.add(groupBean);
1417: }
1418:
1419: Collection distinctForumAuthorizedGroups = DAOFactory
1420: .getGroupForumDAO().getDistinctGroups();
1421: Collection forumAuthorizedGroups = new ArrayList(
1422: distinctForumAuthorizedGroups.size());
1423: for (Iterator iter = distinctForumAuthorizedGroups.iterator(); iter
1424: .hasNext();) {
1425: GroupForumBean item = (GroupForumBean) iter.next();
1426: GroupsBean groupBean = DAOFactory.getGroupsDAO().getGroup(
1427: item.getGroupID());
1428: forumAuthorizedGroups.add(groupBean);
1429: }
1430:
1431: request.setAttribute("AuthorizedMembers", authorizedMembers);
1432: request.setAttribute("ForumsAuthorizedMembers",
1433: forumsAuthorizedMembers);
1434: request.setAttribute("AuthorizedGroups", authorizedGroups);
1435: request.setAttribute("ForumAuthorizedGroups",
1436: forumAuthorizedGroups);
1437: }
1438:
1439: public void prepareViewPermission(GenericRequest request)
1440: throws AuthenticationException, BadInputException,
1441: DatabaseException, ObjectNotFoundException {
1442: //Check here again.
1443: //SecurityUtil.checkHttpPostMethod(request);
1444:
1445: OnlineUser onlineUser = onlineUserManager
1446: .getOnlineUser(request);
1447: MVNForumPermission permission = onlineUser.getPermission();
1448: permission.ensureCanAdminSystem();
1449:
1450: int memberID = GenericParamUtil.getParameterInt(request,
1451: "memberid");
1452:
1453: MemberBean memberBean = null;
1454: try {
1455: memberBean = DAOFactory.getMemberDAO().getMember(memberID);
1456: } catch (ObjectNotFoundException e) {
1457: Locale locale = I18nUtil.getLocaleInRequest(request);
1458: String localizedMessage = MVNForumResourceBundle
1459: .getString(
1460: locale,
1461: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
1462: new Object[] { new Integer(memberID) });
1463: throw new ObjectNotFoundException(localizedMessage);
1464: }
1465: MVNForumPermission this Permission = MVNForumPermissionFactory
1466: .getAuthenticatedPermission(memberBean);
1467: Collection groups = DAOFactory.getGroupsDAO().getMyGroups(
1468: memberID);
1469:
1470: request.setAttribute("MemberBean", memberBean);
1471: request.setAttribute("MemberGroups", groups);
1472: request.setAttribute("Permissions", this Permission);
1473:
1474: CategoryBuilder builder = new DefaultCategoryBuilder();
1475: CategoryTree tree = new CategoryTree(builder);
1476: CategoryTreeListener listener = categoryService
1477: .getManagementViewMemberPermissions(request);
1478: tree.addCategeoryTreeListener(listener);
1479: request.setAttribute("Result", tree.build());
1480: }
1481:
1482: public void prepareChangePassword(GenericRequest request)
1483: throws DatabaseException, AuthenticationException,
1484: ObjectNotFoundException, BadInputException {
1485:
1486: OnlineUser onlineUser = onlineUserManager
1487: .getOnlineUser(request);
1488: MVNForumPermission permission = onlineUser.getPermission();
1489: permission.ensureCanAdminSystem();
1490:
1491: Locale locale = I18nUtil.getLocaleInRequest(request);
1492: if (MVNForumConfig.getEnableAdminCanChangePassword() == false) {
1493: String localizedMessage = MVNForumResourceBundle
1494: .getString(locale,
1495: "java.lang.IllegalStateException.admin_can_change_password_is_disabled");
1496: throw new IllegalStateException(localizedMessage);
1497: //throw new IllegalStateException("Admin Cannot change the user password. This feature is disabled by administrator");
1498: }
1499: int memberID = GenericParamUtil.getParameterInt(request,
1500: "memberid");
1501:
1502: if (memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN) {
1503: String localizedMessage = MVNForumResourceBundle
1504: .getString(locale,
1505: "java.lang.AssertionError.cannot_change_root_password");
1506: throw new AssertionError(localizedMessage);
1507: }
1508: MemberBean memberBean = null;
1509: try {
1510: memberBean = DAOFactory.getMemberDAO().getMember(memberID);
1511: } catch (ObjectNotFoundException e) {
1512: String localizedMessage = MVNForumResourceBundle
1513: .getString(
1514: locale,
1515: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
1516: new Object[] { new Integer(memberID) });
1517: throw new ObjectNotFoundException(localizedMessage);
1518: }
1519:
1520: request.setAttribute("MemberBean", memberBean);
1521: }
1522:
1523: public void processChangePassword(GenericRequest request)
1524: throws DatabaseException, AuthenticationException,
1525: ObjectNotFoundException, BadInputException {
1526:
1527: SecurityUtil.checkHttpPostMethod(request);
1528:
1529: OnlineUser onlineUser = onlineUserManager
1530: .getOnlineUser(request);
1531: MVNForumPermission permission = onlineUser.getPermission();
1532: permission.ensureCanAdminSystem();
1533:
1534: Locale locale = I18nUtil.getLocaleInRequest(request);
1535:
1536: if (MVNForumConfig.getEnableAdminCanChangePassword() == false) {
1537: String localizedMessage = MVNForumResourceBundle
1538: .getString(locale,
1539: "java.lang.IllegalStateException.admin_can_change_password_is_disabled");
1540: throw new IllegalStateException(localizedMessage);
1541: //throw new IllegalStateException("Admin Cannot change the user password. This feature is disabled by administrator");
1542: }
1543:
1544: int memberID = GenericParamUtil.getParameterInt(request,
1545: "memberid");
1546:
1547: if (memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN) {
1548: String localizedMessage = MVNForumResourceBundle
1549: .getString(locale,
1550: "java.lang.AssertionError.cannot_change_root_password");
1551: throw new AssertionError(localizedMessage);
1552: }
1553:
1554: // now check the password
1555: MyUtil.ensureCorrectCurrentPassword(request);
1556:
1557: String password = GenericParamUtil.getParameterPassword(
1558: request, "MemberMatkhau", 3, 0);
1559: String confirmword = GenericParamUtil.getParameterPassword(
1560: request, "MemberMatkhauConfirm", 3, 0);
1561: if (password.equals(confirmword) == false) {
1562: String localizedMessage = MVNForumResourceBundle
1563: .getString(locale,
1564: "mvncore.exception.BadInputException.confirmed_password_is_not_match");
1565: throw new BadInputException(localizedMessage);
1566: //throw new BadInputException("Password and confirmed password are not the same, please try again.");
1567: }
1568: password = Encoder.getMD5_Base64(password);
1569:
1570: Timestamp passwordExpireDate = null;
1571: if (MVNForumConfig.getMaxPasswordDays() > 0) {
1572: passwordExpireDate = DateUtil
1573: .getCurrentGMTTimestampExpiredDay(MVNForumConfig
1574: .getMaxPasswordDays());
1575: }
1576: try {
1577: DAOFactory.getMemberDAO().updatePassword(memberID,
1578: password, passwordExpireDate);
1579: } catch (ObjectNotFoundException e) {
1580: String localizedMessage = MVNForumResourceBundle
1581: .getString(
1582: locale,
1583: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
1584: new Object[] { new Integer(memberID) });
1585: throw new ObjectNotFoundException(localizedMessage);
1586: }
1587:
1588: String actionDesc = MVNForumResourceBundle.getString(
1589: MVNForumConfig.getEventLogLocale(),
1590: "mvnforum.eventlog.desc.ChangePasswordProcess");
1591: eventLogService.logEvent(onlineUser.getMemberName(), request
1592: .getRemoteAddr(),
1593: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
1594: MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
1595: "change password", actionDesc, EventLogService.MEDIUM);
1596:
1597: request.setAttribute("MemberID", new Integer(memberID));
1598: }
1599:
1600: public void prepareDeleteNonActivatedNoPostMembers(
1601: GenericRequest request) throws DatabaseException,
1602: AuthenticationException, BadInputException {
1603:
1604: OnlineUser onlineUser = onlineUserManager
1605: .getOnlineUser(request);
1606: MVNForumPermission permission = onlineUser.getPermission();
1607: permission.ensureCanAdminSystem();
1608:
1609: int days = GenericParamUtil.getParameterUnsignedInt(request,
1610: "days");
1611:
1612: long delta = days * DateUtil.DAY;
1613: Timestamp before = new Timestamp(DateUtil
1614: .getCurrentGMTTimestamp().getTime()
1615: - delta);
1616:
1617: Collection members = DAOFactory.getMemberDAO()
1618: .getNonActivatedNoPostMembers(before);
1619:
1620: request.setAttribute("DeleteMembers", members);
1621: }
1622:
1623: public void processDeleteNonActivatedNoPostMembers(
1624: GenericRequest request) throws DatabaseException,
1625: ObjectNotFoundException, BadInputException,
1626: AuthenticationException {
1627:
1628: SecurityUtil.checkHttpPostMethod(request);
1629:
1630: OnlineUser onlineUser = onlineUserManager
1631: .getOnlineUser(request);
1632: MVNForumPermission permission = onlineUser.getPermission();
1633: permission.ensureCanAdminSystem();
1634:
1635: Locale locale = I18nUtil.getLocaleInRequest(request);
1636:
1637: // now check the password
1638: MyUtil.ensureCorrectCurrentPassword(request);
1639:
1640: int days = GenericParamUtil.getParameterUnsignedInt(request,
1641: "days");
1642:
1643: boolean deleteMessages = GenericParamUtil.getParameterBoolean(
1644: request, "deletesentmessages");
1645:
1646: long delta = days * DateUtil.DAY;
1647: Timestamp before = new Timestamp(DateUtil
1648: .getCurrentGMTTimestamp().getTime()
1649: - delta);
1650:
1651: Collection members = DAOFactory.getMemberDAO()
1652: .getNonActivatedNoPostMembers(before);
1653:
1654: int deletedMembersCount = 0;
1655: for (Iterator iterator = members.iterator(); iterator.hasNext();) {
1656: MemberBean member = (MemberBean) iterator.next();
1657: if ((member.getMemberID() != 0)
1658: && (MyUtil.isRootAdminID(member.getMemberID()) == false)) {
1659: MemberWebHandler.deleteMember(member, deleteMessages,
1660: request, locale);
1661: deletedMembersCount++;
1662: }
1663: }
1664: log.info("DeleteNonActivatedNoPostMembers: Deleted "
1665: + deletedMembersCount + " members");
1666:
1667: String actionDesc = MVNForumResourceBundle
1668: .getString(
1669: MVNForumConfig.getEventLogLocale(),
1670: "mvnforum.eventlog.desc.DeleteNonActivatedMembersProces",
1671: new Object[] { members });
1672: eventLogService.logEvent(onlineUser.getMemberName(), request
1673: .getRemoteAddr(),
1674: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
1675: MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
1676: "delete nonactivated members", actionDesc,
1677: EventLogService.HIGH);
1678:
1679: request.setAttribute("DeletedMembersCount", new Integer(
1680: deletedMembersCount));
1681: }
1682:
1683: public static void deleteMember(MemberBean memberBean,
1684: boolean deleteSentMessages, GenericRequest request,
1685: Locale locale) throws DatabaseException, BadInputException,
1686: ObjectNotFoundException {
1687:
1688: int memberID = memberBean.getMemberID();
1689: if ((memberID == MVNForumConstant.MEMBER_ID_OF_ADMIN)
1690: || (memberID == 0)
1691: || (memberID == MVNForumConstant.MEMBER_ID_OF_GUEST)) {
1692: String localizedMessage = MVNForumResourceBundle
1693: .getString(locale,
1694: "mvncore.exception.BadInputException.cannot_delete_admin_or_guest");
1695: throw new BadInputException(localizedMessage);
1696: //throw new BadInputException("Cannot delete default Admin and Guest users.");
1697: }
1698:
1699: // check in the MemberBean
1700: if (memberBean.getMemberPostCount() > 0) {
1701: String localizedMessage = MVNForumResourceBundle
1702: .getString(locale,
1703: "mvncore.exception.BadInputException.cannot_delete_member_has_a_post");
1704: throw new BadInputException(localizedMessage);
1705: //throw new BadInputException("Cannot delete member that has posted at least one post.");
1706: }
1707:
1708: // Real checking in table post
1709: if (DAOFactory.getPostDAO().getNumberOfPosts_inMember(memberID) > 0) {
1710: String localizedMessage = MVNForumResourceBundle
1711: .getString(locale,
1712: "mvncore.exception.BadInputException.cannot_delete_member_has_a_post");
1713: throw new BadInputException(localizedMessage);
1714: //throw new BadInputException("Cannot delete member that has posted at least one post.");
1715: }
1716:
1717: // first, we delete uploaded image if there is one
1718: String memberName = memberBean.getMemberName();
1719:
1720: log.info("About to delete member with login = " + memberName
1721: + " and id = " + memberID
1722: + " with option deleteSentMessages = "
1723: + deleteSentMessages);
1724:
1725: StringBuffer bufferPicFile = new StringBuffer(256);
1726: bufferPicFile.append(request
1727: .getRealPath(MVNForumGlobal.UPLOADED_AVATAR_DIR));
1728: bufferPicFile.append(File.separatorChar).append(memberName)
1729: .append(".jpg");
1730: String picFile = bufferPicFile.toString();
1731:
1732: log.debug("Delete avatar = " + picFile);
1733: File file = new File(picFile);
1734: file.delete();// we dont need to check the returned value
1735:
1736: //@todo delete table Post/Thread/Attachment if we support delete posted user
1737: DAOFactory.getWatchDAO().delete_inMember(memberID);
1738: DAOFactory.getMemberForumDAO().delete_inMember(memberID);
1739: DAOFactory.getMemberGroupDAO().delete_inMember(memberID);
1740: DAOFactory.getMemberPermissionDAO().delete_inMember(memberID);
1741: DAOFactory.getFavoriteThreadDAO().delete_inMember(memberID);
1742:
1743: //Delete message, attachmessage, folder, message statistics stuff
1744: PrivateMessageUtil.deleteMessageFoldersInDatabase(memberID);
1745: DAOFactory.getMessageStatisticsDAO().delete_inMember(memberID);
1746: if (deleteSentMessages) {
1747: DAOFactory.getMessageDAO().deleteSenderMessages(memberID);
1748: }
1749:
1750: // reset ForumOwnerName before delete member
1751: DAOFactory.getForumDAO().resetForumOwnerNameWhenDeleteMember(
1752: memberName);
1753:
1754: //Delete in primary table
1755: DAOFactory.getMemberDAO().deleteByPrimaryKey(memberID);
1756: MemberIndexer.scheduleDeleteMemberTask(memberID);
1757:
1758: MemberCache.getInstance().clear();
1759: }
1760:
1761: }
|