0001: /*
0002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/MemberWebHandler.java,v 1.171 2008/01/18 01:51:00 phuongpdd Exp $
0003: * $Author: phuongpdd $
0004: * $Revision: 1.171 $
0005: * $Date: 2008/01/18 01:51:00 $
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: */
0041: package com.mvnforum.user;
0042:
0043: import java.io.*;
0044: import java.net.URLEncoder;
0045: import java.sql.Date;
0046: import java.sql.Timestamp;
0047: import java.util.*;
0048:
0049: import javax.mail.MessagingException;
0050: import javax.servlet.http.HttpServletRequest;
0051: import javax.servlet.http.HttpServletResponse;
0052:
0053: import net.myvietnam.mvncore.exception.*;
0054: import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
0055: import net.myvietnam.mvncore.interceptor.InterceptorService;
0056: import net.myvietnam.mvncore.security.*;
0057: import net.myvietnam.mvncore.service.*;
0058: import net.myvietnam.mvncore.util.*;
0059: import net.myvietnam.mvncore.web.GenericRequest;
0060: import net.myvietnam.mvncore.web.GenericResponse;
0061: import net.myvietnam.mvncore.web.fileupload.FileItem;
0062: import net.myvietnam.mvncore.web.fileupload.FileUploadException;
0063:
0064: import org.apache.commons.io.IOUtils;
0065: import org.apache.commons.logging.Log;
0066: import org.apache.commons.logging.LogFactory;
0067:
0068: import com.mvnforum.*;
0069: import com.mvnforum.auth.*;
0070: import com.mvnforum.common.MemberMapping;
0071: import com.mvnforum.common.SendMailUtil;
0072: import com.mvnforum.db.*;
0073: import com.mvnforum.search.member.MemberIndexer;
0074: import com.mvnforum.service.MvnForumInfoService;
0075: import com.mvnforum.service.MvnForumServiceFactory;
0076:
0077: import freemarker.template.*;
0078:
0079: public class MemberWebHandler {
0080:
0081: private static Log log = LogFactory.getLog(MemberWebHandler.class);
0082:
0083: private OnlineUserManager onlineUserManager = OnlineUserManager
0084: .getInstance();
0085:
0086: private static MvnForumInfoService mvnForumInfo = MvnForumServiceFactory
0087: .getMvnForumService().getMvnForumInfoService();
0088:
0089: private static EventLogService eventLogService = MvnCoreServiceFactory
0090: .getMvnCoreService().getEventLogService();
0091:
0092: private BinaryStorageService binaryStorageService = MvnCoreServiceFactory
0093: .getMvnCoreService().getBinaryStorageService();
0094:
0095: private FileUploadParserService fileUploadParserService = MvnCoreServiceFactory
0096: .getMvnCoreService().getFileUploadParserService();
0097:
0098: public MemberWebHandler() {
0099: }
0100:
0101: public void prepareAdd(GenericRequest request)
0102: throws DatabaseException, AuthenticationException {
0103:
0104: Locale locale = I18nUtil.getLocaleInRequest(request);
0105:
0106: if (MVNForumConfig.getEnableExternalUserDatabase()) {
0107: String localizedMessage = MVNForumResourceBundle
0108: .getString(locale,
0109: "java.lang.IllegalStateException.create_user_is_disabled");
0110: throw new IllegalStateException(localizedMessage);
0111: //throw new IllegalStateException("Cannot create user if we enable external user database.");
0112: }
0113:
0114: if (MVNForumConfig.getEnableNewMember() == false) {
0115: String localizedMessage = MVNForumResourceBundle
0116: .getString(locale,
0117: "java.lang.IllegalStateException.cannot_register.new_member_is_disabled");
0118: throw new IllegalStateException(localizedMessage);
0119: //throw new IllegalStateException("Cannot register new member because NEW_MEMBER feature is disabled by administrator.");
0120: }
0121:
0122: boolean agree = GenericParamUtil.getParameterBoolean(request,
0123: "agree");
0124: if ((MVNForumConfig.getEnableRegisterRule())
0125: && (agree == false)) {
0126: return;
0127: }
0128:
0129: OnlineUser onlineUser = onlineUserManager
0130: .getOnlineUser(request);
0131: if (onlineUser.isMember()) {
0132: String localizedMessage = MVNForumResourceBundle
0133: .getString(
0134: locale,
0135: "java.lang.IllegalStateException.cannot_register.new_member_after_login",
0136: new Object[] { onlineUser.getMemberName() });
0137: throw new IllegalStateException(localizedMessage);
0138: }
0139:
0140: if (MVNForumConfig.getEnableCaptcha()) {
0141: onlineUser.buildNewCaptcha();
0142: }
0143: }
0144:
0145: public void processAdd(GenericRequest request,
0146: GenericResponse response) throws BadInputException,
0147: ObjectNotFoundException, CreateException,
0148: DatabaseException, InterceptorException,
0149: DuplicateKeyException, ForeignKeyNotFoundException,
0150: FloodException, DatabaseException, AuthenticationException {
0151:
0152: SecurityUtil.checkHttpPostMethod(request);
0153:
0154: Locale locale = I18nUtil.getLocaleInRequest(request);
0155:
0156: if (MVNForumConfig.getEnableExternalUserDatabase()) {
0157: String localizedMessage = MVNForumResourceBundle
0158: .getString(locale,
0159: "java.lang.IllegalStateException.create_user_is_disabled");
0160: throw new IllegalStateException(localizedMessage);
0161: //throw new IllegalStateException("Cannot create user if we enable external user database.");
0162: }
0163:
0164: if (MVNForumConfig.getEnableNewMember() == false) {
0165: String localizedMessage = MVNForumResourceBundle
0166: .getString(locale,
0167: "java.lang.IllegalStateException.cannot_register.new_member_is_disabled");
0168: throw new IllegalStateException(localizedMessage);
0169: //throw new IllegalStateException("Cannot register new member because NEW_MEMBER feature is disabled by administrator.");
0170: }
0171:
0172: // use for the captcha feature
0173: OnlineUser onlineUser = onlineUserManager
0174: .getOnlineUser(request);
0175:
0176: MyUtil.saveVNTyperMode(request, response);
0177:
0178: String currentIP = request.getRemoteAddr();
0179: try {
0180: FloodControl.ensureNotReachMaximum(
0181: MVNForumGlobal.FLOOD_ID_NEW_MEMBER_PER_IP,
0182: currentIP);
0183: } catch (FloodException fe) {
0184: //throw new FloodException("You have reached the maximum number of the registering actions for this page. Please try this page later. This is to prevent forum from being flooded.");
0185: Integer maxRegisters = new Integer(
0186: FloodControl
0187: .getActionsPerHour(MVNForumGlobal.FLOOD_ID_NEW_MEMBER_PER_IP));
0188: String localizedMessage = MVNForumResourceBundle
0189: .getString(
0190: locale,
0191: "mvncore.exception.FloodException.register_too_many_times",
0192: new Object[] { maxRegisters });
0193: throw new FloodException(localizedMessage);
0194: }
0195: Timestamp now = DateUtil.getCurrentGMTTimestamp();
0196:
0197: String memberName = GenericParamUtil.getParameterSafe(request,
0198: "MemberName", true);// check good name
0199: /** @todo move to a name filter */
0200: if (memberName.equalsIgnoreCase(MVNForumConfig
0201: .getDefaultGuestName())
0202: || memberName.equalsIgnoreCase("Guest")
0203: || memberName.equalsIgnoreCase("Administrator")
0204: || memberName.equalsIgnoreCase("Moderator")) {
0205: String localizedMessage = MVNForumResourceBundle
0206: .getString(
0207: locale,
0208: "mvncore.exception.BadInputException.cannot_register_with_reserved_name",
0209: new Object[] { memberName });
0210: throw new BadInputException(localizedMessage);
0211: //throw new BadInputException("Cannot register member with a reserved name : " + memberName);
0212: }
0213: StringUtil.checkGoodName(memberName);
0214:
0215: InterceptorService.getInstance().validateLoginID(memberName);
0216:
0217: if (memberName.length() > MVNForumGlobal.MAX_MEMBER_LOGIN_LENGTH) {
0218: String localizedMessage = MVNForumResourceBundle
0219: .getString(locale,
0220: "mvncore.exception.BadInputException.member_name_too_long");
0221: throw new BadInputException(localizedMessage);
0222: //throw new BadInputException("MemberName cannot be longer than 30 characters.");
0223: }
0224:
0225: String memberPassword1 = GenericParamUtil.getParameterPassword(
0226: request, "MemberMatkhau", 3, 0);
0227: String memberPassword2 = GenericParamUtil.getParameterPassword(
0228: request, "MemberMatkhauConfirm", 3, 0);
0229:
0230: InterceptorService.getInstance().validatePassword(
0231: memberPassword1);
0232:
0233: if (!memberPassword1.equals(memberPassword2)) {
0234: String localizedMessage = MVNForumResourceBundle
0235: .getString(locale,
0236: "mvncore.exception.BadInputException.confirmed_password_is_not_match");
0237: throw new BadInputException(localizedMessage);
0238: //throw new BadInputException("Password and confirmed password are not the same, please try again.");
0239: }
0240: String memberPassword = Encoder.getMD5_Base64(memberPassword1);
0241:
0242: String memberEmail = GenericParamUtil.getParameterEmail(
0243: request, "MemberEmail");
0244: String memberEmailConfirm = GenericParamUtil.getParameterEmail(
0245: request, "MemberEmailConfirm");
0246: if (!memberEmail.equals(memberEmailConfirm)) {
0247: String localizedMessage = MVNForumResourceBundle
0248: .getString(locale,
0249: "mvncore.exception.BadInputException.confirmed_email_is_not_match");
0250: throw new BadInputException(localizedMessage);
0251: //throw new BadInputException("Email and confirmed email are not the same, please try again.");
0252: }
0253: String memberFirstEmail = memberEmail;
0254: if (memberEmail.length() > MVNForumGlobal.MAX_MEMBER_EMAIL_LENGTH) {
0255: String localizedMessage = MVNForumResourceBundle
0256: .getString(locale,
0257: "mvncore.exception.BadInputException.member_email_too_long");
0258: throw new BadInputException(localizedMessage);
0259: //throw new BadInputException("MemberEmail cannot be longer than 60 characters.");
0260: }
0261: InterceptorService.getInstance().validateMail(memberFirstEmail);
0262:
0263: int memberEmailVisible = GenericParamUtil.getParameterBoolean(
0264: request, "MemberEmailVisible") ? MemberBean.MEMBER_EMAIL_VISIBLE
0265: : MemberBean.MEMBER_EMAIL_INVISIBLE;
0266: int memberNameVisible = GenericParamUtil.getParameterBoolean(
0267: request, "MemberNameVisible") ? MemberBean.MEMBER_NAME_VISIBLE
0268: : MemberBean.MEMBER_NAME_INVISIBLE;
0269: String memberFirstIP = currentIP;
0270: String memberLastIP = currentIP;
0271: Timestamp memberCreationDate = now;
0272: Timestamp memberModifiedDate = now;
0273: Timestamp memberLastLogon = now;// @todo review and support it later
0274: Timestamp memberPasswordExpireDate = now;
0275: if (MVNForumConfig.getMaxPasswordDays() > 0) {
0276: memberPasswordExpireDate = DateUtil
0277: .getCurrentGMTTimestampExpiredDay(MVNForumConfig
0278: .getMaxPasswordDays());
0279: }
0280: int memberOption = 0;//@todo review and support it later
0281: int memberStatus = MVNForumConfig
0282: .getDefaultStatusOfRegisteredMember();// @todo review and support it later, ex: should it be active or not?
0283: String memberActivateCode = "";// not activated
0284: int memberMessageOption = 0;// @todo review and support it later
0285: int memberPostsPerPage = GenericParamUtil.getParameterInt(
0286: request, "MemberPostsPerPage", 10);
0287: if (memberPostsPerPage < 5) {
0288: memberPostsPerPage = 5;
0289: }
0290: String memberTitle = "";
0291: double memberTimeZone = GenericParamUtil.getParameterTimeZone(
0292: request, "MemberTimeZone");
0293: String memberSkin = "";
0294:
0295: // validate data for required fields.
0296:
0297: String memberFirstname = GenericParamUtil.getParameterSafe(
0298: request, "MemberFirstname", MVNForumConfig
0299: .isRequireRegisterFirstname());
0300: String memberLastname = GenericParamUtil.getParameterSafe(
0301: request, "MemberLastname", MVNForumConfig
0302: .isRequireRegisterLastname());
0303: String memberAddress = GenericParamUtil.getParameterSafe(
0304: request, "MemberAddress", MVNForumConfig
0305: .isRequireRegisterAddress());
0306: String memberCity = GenericParamUtil.getParameterSafe(request,
0307: "MemberCity", MVNForumConfig.isRequireRegisterCity());
0308: String memberState = GenericParamUtil.getParameterSafe(request,
0309: "MemberState", MVNForumConfig.isRequireRegisterState());
0310: String memberCountry = GenericParamUtil.getParameterSafe(
0311: request, "MemberCountry", MVNForumConfig
0312: .isRequireRegisterCountry());
0313: String memberPhone = GenericParamUtil.getParameterSafe(request,
0314: "MemberPhone", MVNForumConfig.isRequireRegisterPhone());
0315: String memberMobile = GenericParamUtil.getParameterSafe(
0316: request, "MemberMobile", MVNForumConfig
0317: .isRequireRegisterMobile());
0318: String memberFax = GenericParamUtil.getParameterSafe(request,
0319: "MemberFax", false);
0320: String memberCareer = GenericParamUtil.getParameterSafe(
0321: request, "MemberCareer", MVNForumConfig
0322: .isRequireRegisterCareer());
0323: String memberYahoo = GenericParamUtil.getParameterSafe(request,
0324: "MemberYahoo", MVNForumConfig.isRequireRegisterYahoo());
0325: String memberAol = GenericParamUtil.getParameterSafe(request,
0326: "MemberAol", MVNForumConfig.isRequireRegisterAol());
0327: String memberIcq = GenericParamUtil.getParameterSafe(request,
0328: "MemberIcq", MVNForumConfig.isRequireRegisterIcq());
0329: String memberMsn = GenericParamUtil.getParameterSafe(request,
0330: "MemberMsn", MVNForumConfig.isRequireRegisterMsn());
0331:
0332: String memberLanguage = GenericParamUtil.getParameterSafe(
0333: request, "MemberLanguage", false);
0334:
0335: int memberGender = Integer.parseInt(GenericParamUtil
0336: .getParameterSafe(request, "MemberGender",
0337: MVNForumConfig.isRequireRegisterGender()));
0338:
0339: String memberHomepage = "";
0340: if (MVNForumConfig.isRequireRegisterHomepage()) {
0341: memberHomepage = GenericParamUtil.getParameterUrl(request,
0342: "MemberHomepage");
0343: }
0344: String memberCoolLink1 = "";
0345: if (MVNForumConfig.isRequireRegisterLink_1()) {
0346: memberCoolLink1 = GenericParamUtil.getParameterUrl(request,
0347: "MemberCoolLink1");
0348: }
0349: String memberCoolLink2 = "";
0350: if (MVNForumConfig.isRequireRegisterLink_2()) {
0351: memberCoolLink2 = GenericParamUtil.getParameterUrl(request,
0352: "MemberCoolLink2");
0353: }
0354: Date memberBirthday = new Date(0);
0355: if (MVNForumConfig.isRequireRegisterBirthday()) {
0356: memberBirthday = GenericParamUtil.getParameterDate(request,
0357: "day", "month", "year");
0358: }
0359: /*
0360: long nowtime = System.currentTimeMillis();
0361: long oldest = nowtime - 100*DateUtil.YEAR;
0362: long youngest = nowtime - 10*DateUtil.YEAR;
0363: long age = (nowtime - memberBirthday.getTime())/DateUtil.YEAR;
0364: if (memberBirthday.getTime() > youngest || memberBirthday.getTime() < oldest) {
0365: log.debug("age = " + age + " date = " + memberBirthday + " gettime = " + memberBirthday.getTime());
0366: throw new BadInputException("Your age is not allow: " + age);
0367: }*/
0368:
0369: if (MVNForumConfig.getEnableCaptcha()) {
0370: String captchaResponse = GenericParamUtil.getParameterSafe(
0371: request, "CaptchaResponse", true);
0372: onlineUser.ensureCorrectCaptchaResponse(captchaResponse);
0373: }
0374: Timestamp memberExpireDate = memberCreationDate;// equal Creation Date mean no expiration
0375:
0376: DAOFactory.getMemberDAO().create(memberName, memberPassword,
0377: memberFirstEmail, memberEmail, memberEmailVisible,
0378: memberNameVisible, memberFirstIP, memberLastIP,
0379: 0/*memberViewCount*/, 0/*memberPostCount*/,
0380: memberCreationDate, memberModifiedDate,
0381: memberExpireDate, memberPasswordExpireDate,
0382: memberLastLogon, memberOption, memberStatus,
0383: memberActivateCode, ""/*memberTempPassword*/,
0384: 0/*memberMessageCount*/, memberMessageOption,
0385: memberPostsPerPage, 0/*memberWarnCount*/,
0386: 0/*memberVoteCount*/, 0/*memberVoteTotalStars*/,
0387: 0/*memberRewardPoints*/, memberTitle, memberTimeZone,
0388: ""/*memberSignature*/, ""/*memberAvatar*/,
0389: memberSkin, memberLanguage, memberFirstname,
0390: memberLastname, memberGender, memberBirthday,
0391: memberAddress, memberCity, memberState, memberCountry,
0392: memberPhone, memberMobile, memberFax, memberCareer,
0393: memberHomepage, memberYahoo, memberAol, memberIcq,
0394: memberMsn, memberCoolLink1, memberCoolLink2);
0395:
0396: // Now, create 4 default folders for each member
0397: int memberID = 0;
0398: try {
0399: // NOTE: please note that we cannot get it from the MemberCache, because we have
0400: // bug that delete member, then immediately create this member again, it will
0401: // get the wrong MemberID so we cannot create a new MessageFolder
0402: //memberID = MemberCache.getInstance().getMemberIDFromMemberName(memberName);
0403:
0404: memberID = DAOFactory.getMemberDAO()
0405: .getMemberIDFromMemberName(memberName);
0406: } catch (ObjectNotFoundException e) {
0407: String localizedMessage = MVNForumResourceBundle
0408: .getString(
0409: locale,
0410: "mvncore.exception.ObjectNotFoundException.membername_not_exists",
0411: new Object[] { memberName });
0412: throw new ObjectNotFoundException(localizedMessage);
0413: }
0414:
0415: int folderStatus = 0;
0416: int folderOption = 0;
0417: int folderType = 0;
0418: DAOFactory.getMessageFolderDAO().create(
0419: MVNForumConstant.MESSAGE_FOLDER_INBOX, memberID,
0420: 0/*order*/, folderStatus, folderOption, folderType,
0421: now, now);
0422: DAOFactory.getMessageFolderDAO().create(
0423: MVNForumConstant.MESSAGE_FOLDER_DRAFT, memberID,
0424: 1/*order*/, folderStatus, folderOption, folderType,
0425: now, now);
0426: DAOFactory.getMessageFolderDAO().create(
0427: MVNForumConstant.MESSAGE_FOLDER_SENT, memberID,
0428: 2/*order*/, folderStatus, folderOption, folderType,
0429: now, now);
0430: DAOFactory.getMessageFolderDAO().create(
0431: MVNForumConstant.MESSAGE_FOLDER_TRASH, memberID,
0432: 3/*order*/, folderStatus, folderOption, folderType,
0433: now, now);
0434:
0435: FloodControl.increaseCount(
0436: MVNForumGlobal.FLOOD_ID_NEW_MEMBER_PER_IP, currentIP);
0437:
0438: if (MVNForumConfig.getEnableCaptcha()) {
0439: onlineUser.destroyCurrentCaptcha();
0440: }
0441:
0442: // Add member to the Lucene index
0443: MemberBean memberBean = null;
0444: try {
0445: memberBean = DAOFactory.getMemberDAO().getMember(memberID);
0446: } catch (ObjectNotFoundException ex) {
0447: String localizedMessage = MVNForumResourceBundle
0448: .getString(
0449: locale,
0450: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0451: new Object[] { new Integer(memberID) });
0452: throw new ObjectNotFoundException(localizedMessage);
0453: }
0454: MemberIndexer.scheduleAddMemberTask(memberBean);
0455:
0456: request.setAttribute("MemberBean", memberBean);
0457:
0458: // now, if require activation, then we will send mail
0459: if (MVNForumConfig.getRequireActivation()) {
0460: String serverName = ParamUtil.getServerPath();//ParamUtil.getServer2(request);
0461: try {
0462: SendMailUtil.sendActivationCodeEmail(memberID,
0463: serverName);
0464: } catch (Exception ex) {
0465: log.error("Cannot send mail after registration!", ex);
0466: request
0467: .setAttribute("mvnforum.mail.failed",
0468: "Cannot send activation email after registration!");
0469: //@todo: save the error message to displayed later
0470: }
0471: }
0472:
0473: }
0474:
0475: public void processUpdate(GenericRequest request,
0476: GenericResponse response) throws BadInputException,
0477: ObjectNotFoundException, DatabaseException,
0478: AuthenticationException {
0479:
0480: //AssertionUtil.doAssert(MVNForumConfig.getEnableExternalUserDatabase() == false, "Cannot update user if we enable external user database.");
0481:
0482: SecurityUtil.checkHttpPostMethod(request);
0483:
0484: OnlineUser onlineUser = onlineUserManager
0485: .getOnlineUser(request);
0486: MVNForumPermission permission = onlineUser.getPermission();
0487: permission.ensureIsAuthenticated();
0488:
0489: MyUtil.saveVNTyperMode(request, response);
0490:
0491: int memberID = onlineUser.getMemberID();
0492: MemberBean memberBean = DAOFactory.getMemberDAO().getMember(
0493: memberID);
0494: MemberMapping mapping = MemberMapping.getInstance();
0495: boolean internalUserDatabase = !MVNForumConfig
0496: .getEnableExternalUserDatabase();
0497:
0498: Timestamp now = DateUtil.getCurrentGMTTimestamp();
0499:
0500: int memberEmailVisible = memberBean.getMemberEmailVisible();
0501: int memberNameVisible = memberBean.getMemberNameVisible();
0502: int memberOption = 0;//GenericParamUtil.getParameterInt(request, "MemberOption");
0503: int memberStatus = 0;//@todo review and support it later
0504: int memberMessageOption = 0;//GenericParamUtil.getParameterInt(request, "MemberMessageOption");
0505: int memberPostsPerPage = memberBean.getMemberPostsPerPage();
0506: if (memberPostsPerPage < 5) {
0507: memberPostsPerPage = 5;
0508: }
0509: double memberTimeZone = memberBean.getMemberTimeZone();
0510: String memberSkin = memberBean.getMemberSkin();
0511: String memberLanguage = memberBean.getMemberLanguage();
0512: String memberFirstname = memberBean.getMemberFirstname();
0513: String memberLastname = memberBean.getMemberLastname();
0514: int memberGender = memberBean.getMemberGender();
0515: Date memberBirthday = memberBean.getMemberBirthday();
0516: String memberAddress = memberBean.getMemberAddress();
0517: String memberCity = memberBean.getMemberCity();
0518: String memberState = memberBean.getMemberState();
0519: String memberCountry = memberBean.getMemberCountry();
0520: String memberPhone = memberBean.getMemberPhone();
0521: String memberMobile = memberBean.getMemberMobile();
0522: String memberFax = memberBean.getMemberFax();
0523: String memberCareer = memberBean.getMemberCareer();
0524: String memberHomepage = memberBean.getMemberHomepage();
0525: String memberYahoo = memberBean.getMemberYahoo();
0526: String memberAol = memberBean.getMemberAol();
0527: String memberIcq = memberBean.getMemberIcq();
0528: String memberMsn = memberBean.getMemberMsn();
0529: String memberCoolLink1 = memberBean.getMemberCoolLink1();
0530: String memberCoolLink2 = memberBean.getMemberCoolLink2();
0531:
0532: // column(s) to update
0533: if (internalUserDatabase
0534: || MemberMapping.isLocalField(mapping
0535: .getMemberEmailVisible())) {
0536: memberEmailVisible = GenericParamUtil.getParameterBoolean(
0537: request, "MemberEmailVisible") ? MemberBean.MEMBER_EMAIL_VISIBLE
0538: : MemberBean.MEMBER_EMAIL_INVISIBLE;
0539: }
0540: if (internalUserDatabase
0541: || MemberMapping.isLocalField(mapping
0542: .getMemberNameVisible())) {
0543: memberNameVisible = GenericParamUtil.getParameterBoolean(
0544: request, "MemberNameVisible") ? MemberBean.MEMBER_NAME_VISIBLE
0545: : MemberBean.MEMBER_NAME_INVISIBLE;
0546: }
0547: if (internalUserDatabase
0548: || MemberMapping.isLocalField(mapping
0549: .getMemberPostsPerPage())) {
0550: memberPostsPerPage = GenericParamUtil.getParameterInt(
0551: request, "MemberPostsPerPage");
0552: }
0553: if (internalUserDatabase
0554: || MemberMapping.isLocalField(mapping
0555: .getMemberTimeZone())) {
0556: memberTimeZone = GenericParamUtil.getParameterTimeZone(
0557: request, "MemberTimeZone");
0558: }
0559: if (internalUserDatabase
0560: || MemberMapping.isLocalField(mapping.getMemberSkin())) {
0561: memberSkin = GenericParamUtil.getParameterSafe(request,
0562: "MemberSkin", false);
0563: }
0564: if (internalUserDatabase
0565: || MemberMapping.isLocalField(mapping
0566: .getMemberLanguage())) {
0567: memberLanguage = GenericParamUtil.getParameterSafe(request,
0568: "MemberLanguage", false);
0569: }
0570: if (internalUserDatabase
0571: || MemberMapping.isLocalField(mapping
0572: .getMemberFirstname())) {
0573: memberFirstname = GenericParamUtil.getParameterSafe(
0574: request, "MemberFirstname", true);
0575: }
0576: if (internalUserDatabase
0577: || MemberMapping.isLocalField(mapping
0578: .getMemberLastname())) {
0579: memberLastname = GenericParamUtil.getParameterSafe(request,
0580: "MemberLastname", true);
0581: }
0582: if (internalUserDatabase
0583: || MemberMapping
0584: .isLocalField(mapping.getMemberGender())) {
0585: memberGender = GenericParamUtil.getParameterBoolean(
0586: request, "MemberGender") ? 1 : 0;
0587: }
0588: if (internalUserDatabase
0589: || MemberMapping.isLocalField(mapping
0590: .getMemberBirthday())) {
0591: memberBirthday = GenericParamUtil.getParameterDate(request,
0592: "MemberBirthday");
0593: }
0594: if (internalUserDatabase
0595: || MemberMapping.isLocalField(mapping
0596: .getMemberAddress())) {
0597: memberAddress = GenericParamUtil.getParameterSafe(request,
0598: "MemberAddress", false);
0599: }
0600: if (internalUserDatabase
0601: || MemberMapping.isLocalField(mapping.getMemberCity())) {
0602: memberCity = GenericParamUtil.getParameterSafe(request,
0603: "MemberCity", false);
0604: }
0605: if (internalUserDatabase
0606: || MemberMapping.isLocalField(mapping.getMemberState())) {
0607: memberState = GenericParamUtil.getParameterSafe(request,
0608: "MemberState", false);
0609: }
0610: if (internalUserDatabase
0611: || MemberMapping.isLocalField(mapping
0612: .getMemberCountry())) {
0613: memberCountry = GenericParamUtil.getParameterSafe(request,
0614: "MemberCountry", false);
0615: }
0616: if (internalUserDatabase
0617: || MemberMapping.isLocalField(mapping.getMemberPhone())) {
0618: memberPhone = GenericParamUtil.getParameterSafe(request,
0619: "MemberPhone", false);
0620: }
0621: if (internalUserDatabase
0622: || MemberMapping
0623: .isLocalField(mapping.getMemberMobile())) {
0624: memberMobile = GenericParamUtil.getParameterSafe(request,
0625: "MemberMobile", false);
0626: }
0627: if (internalUserDatabase
0628: || MemberMapping.isLocalField(mapping.getMemberFax())) {
0629: memberFax = GenericParamUtil.getParameterSafe(request,
0630: "MemberFax", false);
0631: }
0632: if (internalUserDatabase
0633: || MemberMapping
0634: .isLocalField(mapping.getMemberCareer())) {
0635: memberCareer = GenericParamUtil.getParameterSafe(request,
0636: "MemberCareer", false);
0637: }
0638: if (internalUserDatabase
0639: || MemberMapping.isLocalField(mapping
0640: .getMemberHomepage())) {
0641: memberHomepage = GenericParamUtil.getParameterUrl(request,
0642: "MemberHomepage");
0643: }
0644: if (internalUserDatabase
0645: || MemberMapping.isLocalField(mapping.getMemberYahoo())) {
0646: memberYahoo = GenericParamUtil.getParameterSafe(request,
0647: "MemberYahoo", false);
0648: }
0649: if (internalUserDatabase
0650: || MemberMapping.isLocalField(mapping.getMemberAol())) {
0651: memberAol = GenericParamUtil.getParameterSafe(request,
0652: "MemberAol", false);
0653: }
0654: if (internalUserDatabase
0655: || MemberMapping.isLocalField(mapping.getMemberIcq())) {
0656: memberIcq = GenericParamUtil.getParameterSafe(request,
0657: "MemberIcq", false);
0658: }
0659: if (internalUserDatabase
0660: || MemberMapping.isLocalField(mapping.getMemberMsn())) {
0661: memberMsn = GenericParamUtil.getParameterSafe(request,
0662: "MemberMsn", false);
0663: }
0664: if (internalUserDatabase
0665: || MemberMapping.isLocalField(mapping
0666: .getMemberCoolLink1())) {
0667: memberCoolLink1 = GenericParamUtil.getParameterUrl(request,
0668: "MemberCoolLink1");
0669: }
0670: if (internalUserDatabase
0671: || MemberMapping.isLocalField(mapping
0672: .getMemberCoolLink2())) {
0673: memberCoolLink2 = GenericParamUtil.getParameterUrl(request,
0674: "MemberCoolLink2");
0675: }
0676:
0677: DAOFactory.getMemberDAO().update(
0678: memberID, // primary key
0679: memberEmailVisible, memberNameVisible,
0680: now/*memberModifiedDate*/, memberOption, memberStatus,
0681: memberMessageOption, memberPostsPerPage,
0682: memberTimeZone, memberSkin, memberLanguage,
0683: memberFirstname, memberLastname, memberGender,
0684: memberBirthday, memberAddress, memberCity, memberState,
0685: memberCountry, memberPhone, memberMobile, memberFax,
0686: memberCareer, memberHomepage, memberYahoo, memberAol,
0687: memberIcq, memberMsn, memberCoolLink1, memberCoolLink2);
0688:
0689: // now, update the new displayed language option
0690: onlineUser.reloadProfile();
0691: MemberBean justAddedMemberBean = null;
0692: try {
0693: justAddedMemberBean = DAOFactory.getMemberDAO().getMember(
0694: memberID);
0695: } catch (ObjectNotFoundException ex) {
0696: Locale locale = I18nUtil.getLocaleInRequest(request);
0697: String localizedMessage = MVNForumResourceBundle
0698: .getString(
0699: locale,
0700: "mvncore.exception.ObjectNotFoundException.memberid_not_exists",
0701: new Object[] { new Integer(memberID) });
0702: throw new ObjectNotFoundException(localizedMessage);
0703: }
0704: MemberIndexer.scheduleUpdateMemberTask(justAddedMemberBean);
0705:
0706: }
0707:
0708: /*
0709: * @todo: use new method of WebHelper
0710: */
0711: public void prepareEditEmail(GenericRequest request)
0712: throws DatabaseException, ObjectNotFoundException,
0713: AuthenticationException {
0714:
0715: OnlineUser onlineUser = onlineUserManager
0716: .getOnlineUser(request);
0717: MVNForumPermission permission = onlineUser.getPermission();
0718: permission.ensureIsAuthenticated();
0719:
0720: int memberID = onlineUser.getMemberID();
0721: MemberBean memberBean = DAOFactory.getMemberDAO().getMember(
0722: memberID);
0723: request
0724: .setAttribute("MemberEmail", memberBean
0725: .getMemberEmail());
0726: }
0727:
0728: public void processUpdateEmail(GenericRequest request)
0729: throws BadInputException, ObjectNotFoundException,
0730: DatabaseException, InterceptorException,
0731: DuplicateKeyException, AuthenticationException,
0732: MessagingException, IOException, TemplateException {
0733:
0734: SecurityUtil.checkHttpPostMethod(request);
0735:
0736: OnlineUser onlineUser = onlineUserManager
0737: .getOnlineUser(request);
0738: MVNForumPermission permission = onlineUser.getPermission();
0739: permission.ensureIsAuthenticated();
0740: Locale locale = I18nUtil.getLocaleInRequest(request);
0741:
0742: int memberID = onlineUser.getMemberID();
0743:
0744: // column(s) to update
0745: String memberEmail = GenericParamUtil.getParameterEmail(
0746: request, "MemberEmail");
0747: String memberEmailConfirm = GenericParamUtil.getParameterEmail(
0748: request, "MemberEmailConfirm");
0749: if (memberEmail.length() > MVNForumGlobal.MAX_MEMBER_EMAIL_LENGTH) {
0750: String localizedMessage = MVNForumResourceBundle
0751: .getString(locale,
0752: "mvncore.exception.BadInputException.member_email_too_long");
0753: throw new BadInputException(localizedMessage);
0754: //throw new BadInputException("MemberEmail cannot be longer than 60 characters.");
0755: }
0756: InterceptorService.getInstance().validateMail(memberEmail);
0757:
0758: // now check the password
0759: MyUtil.ensureCorrectCurrentPassword(request);
0760:
0761: if (!memberEmail.equals(memberEmailConfirm)) {
0762: String localizedMessage = MVNForumResourceBundle
0763: .getString(locale,
0764: "mvncore.exception.BadInputException.confirmed_email_is_not_match");
0765: throw new BadInputException(localizedMessage);
0766: //throw new BadInputException("Email and confirmed email are not the same, please try again.");
0767: }
0768:
0769: // invalidate the activate status
0770: DAOFactory.getMemberDAO().updateActivateCode(memberID, "");
0771:
0772: DAOFactory.getMemberDAO().updateEmail(memberID, memberEmail);
0773:
0774: // now reload the permission if this online user change email (not activated now)
0775: onlineUser.reloadPermission();
0776:
0777: // now, if require activation, then we will send mail
0778: if (MVNForumConfig.getRequireActivation()) {
0779: String serverName = ParamUtil.getServerPath();//ParamUtil.getServer2(request);
0780: SendMailUtil.sendActivationCodeEmail(memberID, serverName);
0781: }
0782: }
0783:
0784: public void processUpdatePassword(GenericRequest request)
0785: throws BadInputException, ObjectNotFoundException,
0786: DatabaseException, AuthenticationException {
0787:
0788: SecurityUtil.checkHttpPostMethod(request);
0789:
0790: OnlineUser onlineUser = onlineUserManager
0791: .getOnlineUser(request);
0792: MVNForumPermission permission = onlineUser.getPermission();
0793: permission.ensureIsAuthenticated();
0794:
0795: int memberID = onlineUser.getMemberID();
0796: Locale locale = I18nUtil.getLocaleInRequest(request);
0797:
0798: // now check the password
0799: MyUtil.ensureCorrectCurrentPassword(request);
0800: /*
0801: // NOTE: that we dont use getParameterPassword here since it will not forward-compatible
0802: String memberOldPassword = GenericParamUtil.getParameter(request, "MemberOldMatkhau", true);
0803: String oldEncodedPassword = Encoder.getMD5_Base64(memberOldPassword);
0804: String currentPassword = DAOFactory.getMemberDAO().getPassword(memberID);
0805: if (!currentPassword.equals(oldEncodedPassword)) {
0806: String localizedMessage = MVNForumResourceBundle.getString(locale, "mvncore.exception.BadInputException.wrong_password");
0807: throw new BadInputException(localizedMessage);
0808: //throw new BadInputException("You have typed the wrong current password, please try again.");
0809: }*/
0810:
0811: // column(s) to update
0812: String memberPassword1 = GenericParamUtil.getParameterPassword(
0813: request, "MemberMatkhau", 3, 0);
0814: String memberPassword2 = GenericParamUtil.getParameterPassword(
0815: request, "MemberMatkhauConfirm", 3, 0);
0816: if (!memberPassword1.equals(memberPassword2)) {
0817: String localizedMessage = MVNForumResourceBundle
0818: .getString(locale,
0819: "mvncore.exception.BadInputException.confirmed_password_is_not_match");
0820: throw new BadInputException(localizedMessage);
0821: //throw new BadInputException("Password and confirmed password are not the same, please try again.");
0822: }
0823: String memberPassword = Encoder.getMD5_Base64(memberPassword1);
0824:
0825: String currentPassword = DAOFactory.getMemberDAO().getPassword(
0826: memberID);
0827: if (currentPassword.equals(memberPassword)) {
0828: String localizedMessage = MVNForumResourceBundle
0829: .getString(
0830: locale,
0831: "mvncore.exception.BadInputException.old_password_and_new_password_cannot_equal");
0832: throw new BadInputException(localizedMessage);
0833: //throw new BadInputException("Old password and new password cannot equal, please try again.");
0834: }
0835:
0836: Timestamp passwordExpireDate = null;
0837: if (MVNForumConfig.getMaxPasswordDays() > 0) {
0838: passwordExpireDate = DateUtil
0839: .getCurrentGMTTimestampExpiredDay(MVNForumConfig
0840: .getMaxPasswordDays());
0841: }
0842: DAOFactory.getMemberDAO().updatePassword(memberID, // primary key
0843: memberPassword, passwordExpireDate);
0844:
0845: String actionDesc = MVNForumResourceBundle.getString(
0846: MVNForumConfig.getEventLogLocale(),
0847: "mvnforum.user.action.desc.ChangePasswordProcess");
0848: eventLogService.logEvent(onlineUser.getMemberName(), request
0849: .getRemoteAddr(),
0850: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
0851: MVNForumConstant.EVENT_LOG_SUB_MODULE_USER,
0852: "change password", actionDesc, EventLogService.MEDIUM);
0853: }
0854:
0855: public void prepareView_forCurrentMember(GenericRequest request)
0856: throws DatabaseException, ObjectNotFoundException,
0857: AuthenticationException {
0858:
0859: OnlineUser onlineUser = onlineUserManager
0860: .getOnlineUser(request);
0861: MVNForumPermission permission = onlineUser.getPermission();
0862: permission.ensureIsAuthenticated();
0863:
0864: // always update the number of new private message count in this case
0865: onlineUser.updateNewMessageCount(true);
0866:
0867: int memberID = onlineUser.getMemberID();
0868: MemberBean memberBean = DAOFactory.getMemberDAO().getMember(
0869: memberID);
0870: request.setAttribute("MemberBean", memberBean);
0871: }
0872:
0873: public void prepareEdit_forCurrentMember(GenericRequest request)
0874: throws DatabaseException, ObjectNotFoundException,
0875: AuthenticationException {
0876:
0877: OnlineUser onlineUser = onlineUserManager
0878: .getOnlineUser(request);
0879: MVNForumPermission permission = onlineUser.getPermission();
0880: permission.ensureIsAuthenticated();
0881:
0882: int memberID = onlineUser.getMemberID();
0883: MemberBean memberBean = DAOFactory.getMemberDAO().getMember(
0884: memberID);
0885: request.setAttribute("MemberBean", memberBean);
0886: }
0887:
0888: /*
0889: * @todo: use new method of WebHelper
0890: */
0891: public void prepareEditSignature(GenericRequest request)
0892: throws DatabaseException, ObjectNotFoundException,
0893: AuthenticationException {
0894:
0895: OnlineUser onlineUser = onlineUserManager
0896: .getOnlineUser(request);
0897: MVNForumPermission permission = onlineUser.getPermission();
0898: permission.ensureIsAuthenticated();
0899:
0900: boolean isPreviewing = GenericParamUtil.getParameterBoolean(
0901: request, "preview");
0902: if (isPreviewing) {
0903: String signature = GenericParamUtil.getParameter(request,
0904: "MemberSignature");
0905: if (signature.length() > 250) {
0906: signature = signature.substring(0, 250);// ensure no more than 250 char (should check in javascript ??)
0907: }
0908: request.setAttribute("MemberSignature", signature);
0909: } else {
0910: int memberID = onlineUser.getMemberID();
0911: MemberBean memberBean = DAOFactory.getMemberDAO()
0912: .getMember(memberID);
0913: request.setAttribute("MemberSignature", memberBean
0914: .getMemberSignature());
0915: }
0916: }
0917:
0918: public void processUpdateSignature(GenericRequest request,
0919: GenericResponse response) throws ObjectNotFoundException,
0920: DatabaseException, AuthenticationException,
0921: InterceptorException {
0922:
0923: SecurityUtil.checkHttpPostMethod(request);
0924:
0925: OnlineUser onlineUser = onlineUserManager
0926: .getOnlineUser(request);
0927: MVNForumPermission permission = onlineUser.getPermission();
0928: permission.ensureIsAuthenticated();
0929:
0930: MyUtil.saveVNTyperMode(request, response);
0931:
0932: int memberID = onlineUser.getMemberID();
0933:
0934: // column(s) to update
0935: String memberSignature = GenericParamUtil.getParameter(request,
0936: "MemberSignature");
0937: memberSignature = DisableHtmlTagFilter.filter(memberSignature);
0938:
0939: memberSignature = InterceptorService.getInstance()
0940: .validateContent(memberSignature);
0941:
0942: DAOFactory.getMemberDAO().updateSignature(memberID, // primary key
0943: memberSignature);
0944:
0945: // clear the member cache
0946: MemberCache.getInstance().clear();
0947: }
0948:
0949: /*
0950: * @todo: use new method of WebHelper
0951: */
0952: public void prepareEditAvatar(GenericRequest request)
0953: throws DatabaseException, ObjectNotFoundException,
0954: AuthenticationException {
0955:
0956: Locale locale = I18nUtil.getLocaleInRequest(request);
0957: if (MVNForumConfig.getEnableAvatar() == false) {
0958: String localizedMessage = MVNForumResourceBundle
0959: .getString(locale,
0960: "java.lang.IllegalStateException.avatar_is_disabled");
0961: throw new IllegalStateException(localizedMessage);
0962: //throw new IllegalStateException("Cannot use avatar because AVATAR feature is disabled by administrator.");
0963: }
0964:
0965: OnlineUser onlineUser = onlineUserManager
0966: .getOnlineUser(request);
0967: MVNForumPermission permission = onlineUser.getPermission();
0968: permission.ensureIsAuthenticated();
0969: permission.ensureCanUseAvatar();
0970:
0971: int memberID = onlineUser.getMemberID();
0972: MemberBean memberBean = DAOFactory.getMemberDAO().getMember(
0973: memberID);
0974: request.setAttribute("MemberBean", memberBean);
0975: }
0976:
0977: /**
0978: * Change picture from our predefined picture
0979: * NOTE: this method will delete uploaded image (if any) of the member
0980: */
0981: public void updateMemberAvatar(GenericRequest request)
0982: throws ObjectNotFoundException, DatabaseException,
0983: AuthenticationException {
0984:
0985: SecurityUtil.checkHttpPostMethod(request);
0986:
0987: Locale locale = I18nUtil.getLocaleInRequest(request);
0988: if (MVNForumConfig.getEnableAvatar() == false) {
0989: String localizedMessage = MVNForumResourceBundle
0990: .getString(locale,
0991: "java.lang.IllegalStateException.avatar_is_disabled");
0992: throw new IllegalStateException(localizedMessage);
0993: //throw new IllegalStateException("Cannot use avatar because AVATAR feature is disabled by administrator.");
0994: }
0995:
0996: OnlineUser onlineUser = onlineUserManager
0997: .getOnlineUser(request);
0998: MVNForumPermission permission = onlineUser.getPermission();
0999: permission.ensureIsAuthenticated();
1000: permission.ensureCanUseAvatar();
1001:
1002: int memberID = onlineUser.getMemberID();
1003:
1004: // first, we delete uploaded image if there is one
1005: /*StringBuffer bufferPicFile = new StringBuffer(128);
1006: bufferPicFile.append(MVNForumConfig.getAvatarDir());
1007: bufferPicFile.append(File.separatorChar).append(memberName).append(".jpg");
1008: String picFile = bufferPicFile.toString();
1009:
1010: log.trace("Delete avatar = " + picFile);
1011: log.trace("String length = " + picFile.length());
1012: File file = new File(picFile);
1013: file.delete();// we dont need to check the returned value
1014: */
1015: try {
1016: binaryStorageService.deleteData(
1017: BinaryStorageService.CATEGORY_AVATAR, String
1018: .valueOf(memberID), null);
1019: } catch (IOException e) {
1020: log.error("Cannot delete avatar.", e);
1021: }
1022:
1023: // then we update the database with new one
1024: String memberPicture = GenericParamUtil.getParameterFilter(
1025: request, "MemberAvatar");
1026: DAOFactory.getMemberDAO().updateAvatar(memberID, memberPicture);
1027:
1028: // clear the member cache
1029: MemberCache.getInstance().clear();
1030: }
1031:
1032: /**
1033: * upload user own avatar
1034: */
1035: public void uploadAvatar(javax.servlet.ServletConfig config,
1036: GenericRequest request) throws AuthenticationException,
1037: IOException, DatabaseException {
1038:
1039: Locale locale = I18nUtil.getLocaleInRequest(request);
1040:
1041: if (MVNForumConfig.getEnableAvatar() == false) {
1042: String localizedMessage = MVNForumResourceBundle
1043: .getString(locale,
1044: "java.lang.IllegalStateException.avatar_is_disabled");
1045: throw new IllegalStateException(localizedMessage);
1046: //throw new IllegalStateException("Cannot use avatar because AVATAR feature is disabled by administrator.");
1047: }
1048:
1049: OnlineUser onlineUser = onlineUserManager
1050: .getOnlineUser(request);
1051: MVNForumPermission permission = onlineUser.getPermission();
1052: permission.ensureIsAuthenticated();
1053: permission.ensureCanUseAvatar();
1054:
1055: int memberID = onlineUser.getMemberID();
1056: //String memberName = onlineUser.getMemberName();
1057:
1058: int sizeMax = 60000; // 60KB
1059: int sizeThreshold = 100000;// max memory used = 100K (more than needed)
1060:
1061: List fileItems;
1062: try {
1063: fileItems = fileUploadParserService.parseRequest(request,
1064: sizeMax, sizeThreshold, null, "UTF-8");
1065: } catch (FileUploadException ex) {
1066: log.error("Cannot upload", ex);
1067: String localizedMessage = MVNForumResourceBundle.getString(
1068: locale, "java.io.IOException.cannot_upload",
1069: new Object[] { ex.getMessage() });
1070: throw new IOException(localizedMessage);
1071: //throw new IOException("Cannot upload. Detailed reason: " + ex.getMessage());
1072: }
1073:
1074: // make sure only one file upload
1075: int fileUploadCount = 0;
1076: FileItem myFile = null;
1077: for (int i = 0; i < fileItems.size(); i++) {
1078: myFile = (FileItem) fileItems.get(i);
1079: if (!myFile.isFormField()) {
1080: break;
1081: //maybe we don't care about throws an AssertionError so comment this
1082: //fileUploadCount++;
1083: }
1084:
1085: AssertionUtil
1086: .doAssert(
1087: fileUploadCount <= 1,
1088: "Assertion: Cannot upload more than 1 file while processing upload avatar for Member.");
1089: }
1090:
1091: if (myFile == null || myFile.isFormField() == true) {
1092: String localizedMessage = MVNForumResourceBundle
1093: .getString(locale,
1094: "java.lang.AssertionError.cannot_process_upload_avatar_with_form_field");
1095: throw new AssertionError(localizedMessage);
1096: //throw new AssertionError("Cannot process uploaded avatar with a form field.");
1097: }
1098:
1099: // now everything all right, go ahead and create thumbnail
1100:
1101: //@Trong
1102: // InputStream inputStream = myFile.getInputStream();
1103: // StringBuffer bufferPicFile = new StringBuffer(128);
1104:
1105: //@Trong
1106: // bufferPicFile.append(MVNForumConfig.getAvatarDir());
1107: // log.debug("Upload avatar to the folder " + MVNForumConfig.getAvatarDir());
1108: // bufferPicFile.append(File.separatorChar).append(memberName).append(".jpg");
1109: // String thumbnailFile = bufferPicFile.toString();
1110:
1111: //log.trace("uploaded file = " + thumbnailFile);
1112:
1113: //@Trong
1114: //The below method closes the inputStream after it have done its work.
1115: //ImageUtil.createThumbnail(inputStream, thumbnailFile, 150/*maxWidth*/, 150/*maxHeight*/);// can throw BadInputException
1116:
1117: //@Trong
1118: // now the image has been save, go ahead and update database
1119: //DAOFactory.getMemberDAO().updateAvatar(memberID, MemberBean.MEMBER_AVATAR_USING_UPLOAD);
1120:
1121: String binaryMimeType = myFile.getContentType();
1122: binaryMimeType = DisableHtmlTagFilter.filter(binaryMimeType);
1123: int binaryFileSize = (int) myFile.getSize();
1124: String fullFilePath = myFile.getName();
1125: String binaryFilename = FileUtil.getFileName(fullFilePath);
1126: binaryFilename = DisableHtmlTagFilter.filter(binaryFilename);
1127: String binaryCreationIP = request.getRemoteAddr();
1128:
1129: binaryStorageService.storeData(
1130: BinaryStorageService.CATEGORY_AVATAR, String
1131: .valueOf(memberID), binaryFilename, myFile
1132: .getInputStream(), binaryFileSize, 0, 0,
1133: binaryMimeType, binaryCreationIP);
1134:
1135: // clear the member cache
1136: MemberCache.getInstance().clear();
1137: }
1138:
1139: public void prepareForgotPassword(GenericRequest request)
1140: throws DatabaseException, AuthenticationException {
1141:
1142: OnlineUser onlineUser = onlineUserManager
1143: .getOnlineUser(request);
1144: if (MVNForumConfig.getEnableCaptcha()) {
1145: onlineUser.buildNewCaptcha();
1146: }
1147: }
1148:
1149: public void forgotPassword(GenericRequest request)
1150: throws BadInputException, ObjectNotFoundException,
1151: DatabaseException, MessagingException, DatabaseException,
1152: AuthenticationException, IOException, TemplateException {
1153:
1154: SecurityUtil.checkHttpPostMethod(request);
1155:
1156: // use for the captcha feature
1157: OnlineUser onlineUser = onlineUserManager
1158: .getOnlineUser(request);
1159: Locale locale = I18nUtil.getLocaleInRequest(request);
1160:
1161: int memberID = 0;
1162: String memberName = GenericParamUtil.getParameter(request,
1163: "MemberName");
1164: StringUtil.checkGoodName(memberName);
1165: String memberEmail = GenericParamUtil.getParameter(request,
1166: "MemberEmail");
1167: if (memberEmail.length() > 0) {
1168: memberEmail = GenericParamUtil.getParameterEmail(request,
1169: "MemberEmail");
1170: }
1171:
1172: if (memberName.length() > 0) {// user enter his MemberName
1173: // we find the email of this memberID, not the provided email
1174: try {
1175: memberID = MemberCache.getInstance()
1176: .getMemberIDFromMemberName(memberName);
1177: } catch (ObjectNotFoundException e) {
1178: String localizedMessage = MVNForumResourceBundle
1179: .getString(
1180: locale,
1181: "mvncore.exception.ObjectNotFoundException.membername_not_exists",
1182: new Object[] { memberName });
1183: throw new ObjectNotFoundException(localizedMessage);
1184: }
1185: MemberBean bean = DAOFactory.getMemberDAO().getMember(
1186: memberID);
1187: memberEmail = bean.getMemberEmail();
1188: } else if (memberEmail.length() > 0) {// user enter his email
1189: // we find the MemberID of this mail, now we sure that user didnt enter his MemberID
1190: memberID = DAOFactory.getMemberDAO()
1191: .getMemberIDFromMemberEmail(memberEmail);
1192: MemberBean bean = DAOFactory.getMemberDAO().getMember(
1193: memberID);
1194: memberName = bean.getMemberName();
1195: } else {// user didnt enter any thing
1196: String localizedMessage = MVNForumResourceBundle
1197: .getString(locale,
1198: "mvncore.exception.BadInputException.your_member_name_or_email_is_not_entered");
1199: throw new BadInputException(localizedMessage);
1200: //throw new BadInputException("You must enter at least your MemberName or email");
1201: }
1202:
1203: // now we have the correct pair of MemberID and MemberEmail
1204:
1205: // Check the assumption above
1206: MemberBean memberBean = DAOFactory.getMemberDAO().getMember(
1207: memberID);
1208: if (!memberEmail.equalsIgnoreCase(memberBean.getMemberEmail())) {
1209: String localizedMessage = MVNForumResourceBundle.getString(
1210: locale, "java.lang.AssertionError.serious_bug");
1211: throw new AssertionError(localizedMessage);
1212: //throw new AssertionError("Assertion when process forgot password. This is a serious bug. Please contact the Web site administrator to report the bug.");
1213: }
1214: // end check
1215:
1216: // Now check the captcha
1217: if (MVNForumConfig.getEnableCaptcha()) {
1218: String captchaResponse = GenericParamUtil.getParameterSafe(
1219: request, "CaptchaResponse", false);
1220: onlineUser.ensureCorrectCaptchaResponse(captchaResponse);
1221: }
1222:
1223: String currentTempPassword = DAOFactory.getMemberDAO()
1224: .getTempPassword(memberID);
1225:
1226: // if the current value length is less then 5, we assume that it is not set
1227: // and we generate the new value only in this case. This will prevent the
1228: // different values are sent out and confuse user.
1229: if (currentTempPassword.length() < 5) {
1230: //generate a temp password
1231: currentTempPassword = RandomGenerator.getRandomMD5_Base64();
1232: DAOFactory.getMemberDAO().updateTempPassword(memberID,
1233: currentTempPassword);
1234: }
1235:
1236: // next, encode to make sure it could be put on a link
1237: String urlEncodedTempPassword = URLEncoder.encode(
1238: currentTempPassword, "UTF-8");
1239:
1240: // we have pass the assertion check, go ahead
1241: String serverName = ParamUtil.getServerPath();//ParamUtil.getServer2(request);
1242:
1243: StringBuffer passwordResetUrl = new StringBuffer(256);
1244: passwordResetUrl.append(serverName);
1245: passwordResetUrl.append(request.getContextPath());
1246: passwordResetUrl.append(UserModuleConfig.getUrlPattern());
1247: passwordResetUrl.append("/resetpassword?temppassword=");
1248: passwordResetUrl.append(urlEncodedTempPassword);
1249: passwordResetUrl.append("&member=");
1250: passwordResetUrl.append(memberName);
1251:
1252: // Prepare the FreeMarker configuration;
1253: Configuration cfg = MVNForumConfig.getFreeMarkerConfiguration();
1254:
1255: //Below is a code to map content of email to template
1256: Map root = new HashMap();
1257: root.put("serverName", serverName);
1258: root.put("MVNForumInfo", mvnForumInfo.getProductDesc());
1259: root.put("passwordResetUrl", passwordResetUrl.toString());
1260: root.put("memberName", memberName);
1261: root.put("currentTempPassword", currentTempPassword);
1262:
1263: StringWriter subjectWriter = new StringWriter(256);
1264: Template subjectTemplate = cfg
1265: .getTemplate(
1266: MVNForumGlobal.TEMPLATE_FORGOTPASSWORD_SUBJECT,
1267: "UTF-8");
1268: subjectTemplate.process(root, subjectWriter);
1269: String subject = subjectWriter.toString();
1270:
1271: StringWriter bodyWriter = new StringWriter(1024);
1272: Template bodyTemplate = cfg.getTemplate(
1273: MVNForumGlobal.TEMPLATE_FORGOTPASSWORD_BODY, "UTF-8");
1274: bodyTemplate.process(root, bodyWriter);
1275: String body = bodyWriter.toString();
1276:
1277: log.debug("subject = " + subject);
1278: log.debug("body = " + body);
1279: try {
1280: MailMessageStruct mailMessageStruct = new MailMessageStruct();
1281: mailMessageStruct.setFrom(MVNForumConfig
1282: .getWebMasterEmail());
1283: mailMessageStruct.setTo(memberEmail);
1284: mailMessageStruct.setSubject(subject);
1285: mailMessageStruct.setMessage(body);
1286:
1287: MailUtil.sendMail(mailMessageStruct);
1288: } catch (UnsupportedEncodingException e) {
1289: log.error("Cannot support encoding", e);
1290: }
1291:
1292: // Only destroy captcha when send mail successfully
1293: if (MVNForumConfig.getEnableCaptcha()) {
1294: onlineUser.destroyCurrentCaptcha();
1295: }
1296: }
1297:
1298: public void resetPassword(GenericRequest request)
1299: throws BadInputException, ObjectNotFoundException,
1300: DatabaseException, InterceptorException {
1301:
1302: SecurityUtil.checkHttpPostMethod(request);
1303:
1304: Locale locale = I18nUtil.getLocaleInRequest(request);
1305:
1306: String memberName = GenericParamUtil.getParameter(request,
1307: "member", true);
1308: StringUtil.checkGoodName(memberName);
1309: // IMPORTANT: MUST check that temp password is not empty, because temppassword = empty
1310: // means cannot reset password
1311: String memberTempPassword = GenericParamUtil.getParameter(
1312: request, "temppassword", true);
1313:
1314: int memberID = 0;
1315: try {
1316: memberID = MemberCache.getInstance()
1317: .getMemberIDFromMemberName(memberName);
1318: } catch (ObjectNotFoundException e) {
1319: String localizedMessage = MVNForumResourceBundle
1320: .getString(
1321: locale,
1322: "mvncore.exception.ObjectNotFoundException.membername_not_exists",
1323: new Object[] { memberName });
1324: throw new ObjectNotFoundException(localizedMessage);
1325: }
1326:
1327: String currentTempPassword = DAOFactory.getMemberDAO()
1328: .getTempPassword(memberID);
1329: if (memberTempPassword.equals(currentTempPassword) == false) {
1330: String localizedMessage = MVNForumResourceBundle
1331: .getString(locale,
1332: "mvncore.exception.BadInputException.wrong_temporary_password");
1333: throw new BadInputException(localizedMessage);
1334: //throw new BadInputException("Your temporary password is not correct, please try the forgot password feature.");
1335: }
1336:
1337: String memberPassword1 = GenericParamUtil.getParameterPassword(
1338: request, "MemberMatkhau", 3, 0);
1339: String memberPassword2 = GenericParamUtil.getParameterPassword(
1340: request, "MemberMatkhauConfirm", 3, 0);
1341:
1342: InterceptorService.getInstance().validatePassword(
1343: memberPassword1);
1344:
1345: if (!memberPassword1.equals(memberPassword2)) {
1346: String localizedMessage = MVNForumResourceBundle
1347: .getString(locale,
1348: "mvncore.exception.BadInputException.confirmed_password_is_not_match");
1349: throw new BadInputException(localizedMessage);
1350: //throw new BadInputException("Password and confirmed password are not the same, please try again.");
1351: }
1352: String memberPassword = Encoder.getMD5_Base64(memberPassword1);
1353:
1354: Timestamp passwordExpireDate = null;
1355: if (MVNForumConfig.getMaxPasswordDays() > 0) {
1356: passwordExpireDate = DateUtil
1357: .getCurrentGMTTimestampExpiredDay(MVNForumConfig
1358: .getMaxPasswordDays());
1359: }
1360: DAOFactory.getMemberDAO().updatePassword(memberID,
1361: memberPassword, passwordExpireDate);
1362: DAOFactory.getMemberDAO().updateTempPassword(memberID, "");// reset the temp password
1363: }
1364:
1365: public void sendActivateCode(GenericRequest request)
1366: throws BadInputException, ObjectNotFoundException,
1367: DatabaseException, MessagingException, IOException,
1368: TemplateException {
1369:
1370: SecurityUtil.checkHttpPostMethod(request);
1371:
1372: Locale locale = I18nUtil.getLocaleInRequest(request);
1373: int memberID = 0;
1374: String memberName = GenericParamUtil.getParameter(request,
1375: "MemberName", true);
1376: StringUtil.checkGoodName(memberName);
1377: String memberEmail = GenericParamUtil.getParameterEmail(
1378: request, "MemberEmail");
1379:
1380: // we find the email of this memberID, not the provided email
1381: try {
1382: memberID = MemberCache.getInstance()
1383: .getMemberIDFromMemberName(memberName);
1384: } catch (ObjectNotFoundException e) {
1385: String localizedMessage = MVNForumResourceBundle
1386: .getString(
1387: locale,
1388: "mvncore.exception.ObjectNotFoundException.membername_not_exists",
1389: new Object[] { memberName });
1390: throw new ObjectNotFoundException(localizedMessage);
1391: }
1392:
1393: // Check if the email is correct
1394: MemberBean memberBean = DAOFactory.getMemberDAO().getMember(
1395: memberID);
1396: if (!memberEmail.equalsIgnoreCase(memberBean.getMemberEmail())) {
1397: String localizedMessage = MVNForumResourceBundle
1398: .getString(locale,
1399: "mvncore.exception.BadInputException.provided_email_not_equals_member_email");
1400: throw new BadInputException(localizedMessage);
1401: //throw new BadInputException("Your provided email does not equals to the member's email in our database. Please try again.");
1402: }
1403:
1404: // end check, send mail now
1405: String serverName = ParamUtil.getServerPath();//ParamUtil.getServer2(request);
1406: SendMailUtil.sendActivationCodeEmail(memberID, serverName);
1407: }
1408:
1409: public void activateMember(GenericRequest request)
1410: throws BadInputException, ObjectNotFoundException,
1411: DatabaseException, AuthenticationException {
1412:
1413: SecurityUtil.checkHttpPostMethod(request);
1414:
1415: String memberName = GenericParamUtil.getParameter(request,
1416: "member", true);
1417: StringUtil.checkGoodName(memberName);
1418: Locale locale = I18nUtil.getLocaleInRequest(request);
1419:
1420: // IMPORTANT: MUST check that ActivateCode is not empty, because ActivateCode = empty
1421: // means invalid
1422: String memberActivateCode = GenericParamUtil.getParameter(
1423: request, "activatecode", true);
1424: if (memberActivateCode
1425: .equals(MemberBean.MEMBER_ACTIVATECODE_ACTIVATED)) {
1426: String localizedMessage = MVNForumResourceBundle
1427: .getString(locale,
1428: "mvncore.exception.BadInputException.cannot_activate.invalid_activation_code");
1429: throw new BadInputException(localizedMessage);
1430: //throw new BadInputException("Cannot activate member with invalid activation code.");
1431: }
1432: int memberID = 0;
1433: try {
1434: memberID = MemberCache.getInstance()
1435: .getMemberIDFromMemberName(memberName);
1436: } catch (ObjectNotFoundException e) {
1437: String localizedMessage = MVNForumResourceBundle
1438: .getString(
1439: locale,
1440: "mvncore.exception.ObjectNotFoundException.membername_not_exists",
1441: new Object[] { memberName });
1442: throw new ObjectNotFoundException(localizedMessage);
1443: }
1444:
1445: // Now, check that this member is not activated, to prevent the
1446: // situation that other people try to annoy this member
1447: if (DAOFactory.getMemberDAO().getActivateCode(memberID).equals(
1448: MemberBean.MEMBER_ACTIVATECODE_ACTIVATED)) {
1449: String localizedMessage = MVNForumResourceBundle
1450: .getString(locale,
1451: "mvncore.exception.BadInputException.cannot_activate.is_activated_member");
1452: throw new BadInputException(localizedMessage);
1453: //throw new BadInputException("Cannot activate an activated member.");
1454: }
1455:
1456: String currentActivateCode = DAOFactory.getMemberDAO()
1457: .getActivateCode(memberID);
1458: if (memberActivateCode.equals(currentActivateCode) == false) {
1459: String localizedMessage = MVNForumResourceBundle
1460: .getString(locale,
1461: "mvncore.exception.BadInputException.cannot_activate.wrong_activation_code");
1462: throw new BadInputException(localizedMessage);
1463: //throw new BadInputException("Your activation code is not correct, please try the Member Account Activation feature.");
1464: }
1465:
1466: DAOFactory.getMemberDAO().updateActivateCode(memberID,
1467: MemberBean.MEMBER_ACTIVATECODE_ACTIVATED);// activate member
1468:
1469: // now reload the permission if this online user is the activated user
1470: OnlineUser onlineUser = onlineUserManager
1471: .getOnlineUser(request);
1472: if (memberID == onlineUser.getMemberID()) {
1473: onlineUser.reloadPermission();
1474: }
1475: }
1476:
1477: /*************************************************
1478: * For public view
1479: *************************************************/
1480: public void prepareView_forPublic(GenericRequest request)
1481: throws BadInputException, ObjectNotFoundException,
1482: DatabaseException {
1483:
1484: String memberName = GenericParamUtil.getParameter(request,
1485: "member", false);
1486: Locale locale = I18nUtil.getLocaleInRequest(request);
1487: // primary key column(s)
1488: int memberID = -1;
1489: if (memberName.length() == 0) {
1490: memberID = GenericParamUtil.getParameterInt(request,
1491: "memberid");
1492: } else {// has MemberName
1493: /**@todo: improve this for better performance(dont use this method,
1494: * and write 2 new methods)*/
1495: StringUtil.checkGoodName(memberName);// check for better security
1496: try {
1497: memberID = MemberCache.getInstance()
1498: .getMemberIDFromMemberName(memberName);
1499: } catch (ObjectNotFoundException e) {
1500: String localizedMessage = MVNForumResourceBundle
1501: .getString(
1502: locale,
1503: "mvncore.exception.ObjectNotFoundException.membername_not_exists",
1504: new Object[] { memberName });
1505: throw new ObjectNotFoundException(localizedMessage);
1506: }
1507: }
1508:
1509: try {
1510: DAOFactory.getMemberDAO().increaseViewCount(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: //MemberBean memberBean = DAOFactory.getMemberDAO().getMember(memberID);
1521: MemberBean memberBean = MemberCache.getInstance().getMember(
1522: memberID);
1523:
1524: request.setAttribute("MemberBean", memberBean);
1525: }
1526:
1527: /**
1528: * This method supports sorting base on many criteria
1529: */
1530: public void prepareListMembers_forPublic(GenericRequest request)
1531: throws DatabaseException, BadInputException,
1532: AuthenticationException {
1533:
1534: Locale locale = I18nUtil.getLocaleInRequest(request);
1535: if (MVNForumConfig.getEnableListMembers() == false) {
1536: String localizedMessage = MVNForumResourceBundle
1537: .getString(locale,
1538: "java.lang.IllegalStateException.list_members_is_disabled");
1539: throw new IllegalStateException(localizedMessage);
1540: //throw new IllegalStateException("Cannot list members because LIST_MEMBERS feature is disabled by administrator.");
1541: }
1542:
1543: OnlineUser onlineUser = onlineUserManager
1544: .getOnlineUser(request);
1545:
1546: if (onlineUser.isGuest()) {
1547: if (MVNForumConfig.getEnableGuestViewListUsers() == false) {
1548: String localizedMessage = MVNForumResourceBundle
1549: .getString(locale,
1550: "java.lang.IllegalStateException.guest_cannot_view_list_users");
1551: throw new IllegalStateException(localizedMessage);
1552: }
1553: }
1554: //MVNForumPermission permission = onlineUser.getPermission();
1555: //@todo: some permission checking is needed ???
1556:
1557: // for sort and order stuff
1558: String sort = GenericParamUtil.getParameter(request, "sort");
1559: String order = GenericParamUtil.getParameter(request, "order");
1560: if (sort.length() == 0)
1561: sort = "MemberCreationDate";
1562: if (order.length() == 0)
1563: order = "DESC";
1564:
1565: // we continue
1566: int postsPerPage = onlineUser.getPostsPerPage();
1567: int offset = 0;
1568: try {
1569: offset = GenericParamUtil.getParameterUnsignedInt(request,
1570: "offset");
1571: } catch (BadInputException e) {
1572: // do nothing
1573: }
1574:
1575: int totalMembers = DAOFactory.getMemberDAO()
1576: .getNumberOfMembers();
1577: if (offset > totalMembers) {
1578: String localizedMessage = MVNForumResourceBundle
1579: .getString(locale,
1580: "mvncore.exception.BadInputException.offset_greater_than_total_rows");
1581: throw new BadInputException(localizedMessage);
1582: //throw new BadInputException("The offset is not allowed to be greater than total rows.");
1583: }
1584:
1585: Collection memberBeans = DAOFactory.getMemberDAO()
1586: .getMembers_withSortSupport_limit(offset, postsPerPage,
1587: sort, order, MemberDAO.ALL_MEMBER_STATUS);
1588:
1589: request.setAttribute("MemberBeans", memberBeans);
1590: request.setAttribute("TotalMembers", new Integer(totalMembers));
1591: }
1592:
1593: // just for showing member's avatar
1594: public void getAvatar(HttpServletRequest request,
1595: HttpServletResponse response) throws BadInputException,
1596: DatabaseException, IOException {
1597:
1598: if (MVNForumConfig.getEnableAvatar() == false) {
1599: response.sendError(HttpServletResponse.SC_FORBIDDEN);
1600: return;
1601: }
1602:
1603: int memberID = ParamUtil.getParameterInt(request, "memberid");
1604:
1605: MemberBean member = null;
1606: try {
1607: member = DAOFactory.getMemberDAO().getMember(memberID);
1608: } catch (ObjectNotFoundException e) {
1609: response.sendError(HttpServletResponse.SC_BAD_REQUEST);
1610: return;
1611: }
1612:
1613: String memberAvatar = member.getMemberAvatar();
1614: if (memberAvatar.equals(MemberBean.MEMBER_AVATAR_USING_UPLOAD)
1615: || memberAvatar
1616: .startsWith(BinaryStorageService.BINARY_STORAGE)
1617: || memberAvatar
1618: .startsWith(MVNForumGlobal.UPLOADED_AVATAR_DIR)) {
1619: memberAvatar = member.getMemberName() + ".jpg";
1620: } else {
1621: response.sendError(HttpServletResponse.SC_BAD_REQUEST);
1622: return;
1623: }
1624: String imageMimeType = "image/jpeg";
1625:
1626: File avatarFile = new File(MVNForumConfig.getAvatarDir()
1627: + File.separator + memberAvatar);
1628: if (!avatarFile.exists()) {
1629: response.sendError(HttpServletResponse.SC_NOT_FOUND);
1630: return;
1631: }
1632: if (!avatarFile.isFile()) {
1633: response.sendError(HttpServletResponse.SC_NO_CONTENT);
1634: return;
1635: }
1636:
1637: long lastModified = avatarFile.lastModified();
1638: long ifModifiedSince = request
1639: .getDateHeader("If-Modified-Since");
1640: //log.debug("\n ** Last Modified : " + lastModified + " If Modified Since : " + ifModifiedSince + " **");
1641: if (ifModifiedSince != -1) {
1642: if (/*(request.getHeader("If-None-Match") == null)
1643: && */(lastModified <= ifModifiedSince)) {
1644: // The entity has not been modified since the date
1645: // specified by the client. This is not an error case.
1646: response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
1647: return;
1648: }
1649: }
1650:
1651: OutputStream outputStream = null;
1652: try {
1653: String httpModified = DateUtil.getHTTPHeaderTime(new Date(
1654: lastModified));
1655: response.setContentType(imageMimeType);
1656: response.setHeader("Location", memberAvatar);
1657: response.setHeader("Last-Modified", httpModified);
1658: //response.setHeader("Content-Disposition", "attachment; filename=" + memberAvatar);//always download
1659: //response.setHeader("Content-Length", String.valueOf(avatarFile.length()));//problem with compression
1660:
1661: // now, the header inited, just write the file content on the output
1662: try {
1663: outputStream = response.getOutputStream();
1664: //FileUtil.popFile(avatarFile, outputStream);
1665: InputStream inputStream = binaryStorageService
1666: .getInputStream(
1667: BinaryStorageService.CATEGORY_AVATAR,
1668: String.valueOf(memberID), null);
1669: IOUtils.copy(inputStream, outputStream);
1670: } catch (IOException ex) {
1671: // CANNOT throw Exception after we output to the response
1672: log
1673: .error(
1674: "Error while trying to send avatar from server",
1675: ex);
1676: }
1677:
1678: if (outputStream != null) {
1679: outputStream.flush();
1680: outputStream.close();
1681: outputStream = null;// no close twice
1682: }
1683: } catch (IOException ex) {
1684: throw ex;
1685: } finally {
1686: if (outputStream != null) {
1687: try {
1688: outputStream.close();
1689: } catch (IOException ex) {
1690: }
1691: }
1692: }
1693: }
1694:
1695: public void processUpdateCMSPassword(GenericRequest request,
1696: String memberCurrentMakhau, String memberPassword1,
1697: String memberPassword2) throws BadInputException,
1698: ObjectNotFoundException, DatabaseException,
1699: AuthenticationException {
1700:
1701: SecurityUtil.checkHttpPostMethod(request);
1702:
1703: OnlineUser onlineUser = onlineUserManager
1704: .getOnlineUser(request);
1705: MVNForumPermission permission = onlineUser.getPermission();
1706: permission.ensureIsAuthenticated();
1707:
1708: int memberID = onlineUser.getMemberID();
1709: Locale locale = I18nUtil.getLocaleInRequest(request);
1710:
1711: // now check the password
1712: MyUtil.ensureCorrectCurrentPassword(request,
1713: memberCurrentMakhau, "");
1714: if (memberPassword1.equals(memberPassword2) == false) {
1715: String localizedMessage = MVNForumResourceBundle
1716: .getString(locale,
1717: "mvncore.exception.BadInputException.confirmed_password_is_not_match");
1718: throw new BadInputException(localizedMessage);
1719: //throw new BadInputException("Password and confirmed password are not the same, please try again.");
1720: }
1721:
1722: String memberPassword = Encoder.getMD5_Base64(memberPassword1);
1723: String currentPassword = DAOFactory.getMemberDAO().getPassword(
1724: memberID);
1725: if (currentPassword.equals(memberPassword)) {
1726: String localizedMessage = MVNForumResourceBundle
1727: .getString(
1728: locale,
1729: "mvncore.exception.BadInputException.old_password_and_new_password_cannot_equal");
1730: throw new BadInputException(localizedMessage);
1731: //throw new BadInputException("Old password and new password cannot equal, please try again.");
1732: }
1733:
1734: Timestamp passwordExpireDate = null;
1735: if (MVNForumConfig.getMaxPasswordDays() > 0) {
1736: passwordExpireDate = DateUtil
1737: .getCurrentGMTTimestampExpiredDay(MVNForumConfig
1738: .getMaxPasswordDays());
1739: }
1740: DAOFactory.getMemberDAO().updatePassword(memberID, // primary key
1741: memberPassword, passwordExpireDate);
1742:
1743: String actionDesc = MVNForumResourceBundle.getString(
1744: MVNForumConfig.getEventLogLocale(),
1745: "mvnforum.user.action.desc.ChangePasswordProcess");
1746: eventLogService.logEvent(onlineUser.getMemberName(), request
1747: .getRemoteAddr(),
1748: MVNForumConstant.EVENT_LOG_MAIN_MODULE,
1749: MVNForumConstant.EVENT_LOG_SUB_MODULE_USER,
1750: "change password", actionDesc, EventLogService.MEDIUM);
1751:
1752: }
1753: }
|