001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/common/RemoteUserUtil.java,v 1.8 2007/10/10 02:16:33 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.8 $
005: * $Date: 2007/10/10 02:16:33 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Phong Ta Quoc
039: */
040: package com.mvnforum.common;
041:
042: import java.sql.Date;
043: import java.sql.Timestamp;
044:
045: import net.myvietnam.mvncore.exception.*;
046:
047: import net.myvietnam.mvncore.util.DateUtil;
048: import net.myvietnam.mvncore.util.ParamUtil;
049: import net.myvietnam.mvncore.web.GenericRequest;
050:
051: import org.apache.commons.logging.Log;
052: import org.apache.commons.logging.LogFactory;
053:
054: import com.mvnforum.MVNForumConfig;
055: import com.mvnforum.MVNForumConstant;
056: import com.mvnforum.auth.OnlineUserManager;
057: import com.mvnforum.db.*;
058: import com.mvnforum.search.member.MemberIndexer;
059:
060: public class RemoteUserUtil {
061:
062: private static Log log = LogFactory.getLog(RemoteUserUtil.class);
063:
064: private RemoteUserUtil() {
065: }
066:
067: public static void createAccount(String memberName,
068: GenericRequest request) throws ObjectNotFoundException,
069: CreateException, DatabaseException, DuplicateKeyException,
070: ForeignKeyNotFoundException {
071:
072: Timestamp now = DateUtil.getCurrentGMTTimestamp();
073: Date memberBirthday = new Date(now.getTime());
074:
075: // You should think of creating the email based on your company policy
076: String email = memberName + "@yourdomain.com";
077:
078: DAOFactory.getMemberDAO().create(memberName,
079: OnlineUserManager.PASSWORD_OF_METHOD_CUSTOMIZATION,
080: email, email, MemberBean.MEMBER_EMAIL_VISIBLE,
081: MemberBean.MEMBER_NAME_VISIBLE,
082: request.getRemoteAddr(), request.getRemoteAddr(),
083: 0/* memberViewCount */, 0/* memberPostCount */,
084: now /*memberCreationDate*/,
085: now /*memberModifiedDate*/, now /*memberExpireDate*/,
086: now /*memberPasswordExpireDate*/,
087: now/* memberLastLogon */, 0,
088: MemberBean.MEMBER_STATUS_ENABLE,
089: ""/* memberActivateCode */,
090: ""/* memberTempPassword */,
091: 0/* memberMessageCount */, 0, 10,
092: 0/* memberWarnCount */, 0/* memberVoteCount */,
093: 0/* memberVoteTotalStars */,
094: 0/* memberRewardPoints */, ""/* memberTitle */,
095: 0/* memberTimeZone */, ""/* memberSignature */,
096: ""/* memberAvatar */, ""/* memberSkin */,
097: ""/* memberLanguage */, ""/* memberFirstname */,
098: ""/* memberLastname */,
099: MemberBean.MEMBER_GENDER_MALE/* memberGender */,
100: memberBirthday, ""/* memberAddress */,
101: ""/* memberCity */, ""/* memberState */,
102: ""/* memberCountry */, ""/* memberPhone */,
103: ""/* memberMobile */, ""/* memberFax */,
104: ""/* memberCareer */, ""/* memberHomepage */,
105: ""/* memberYahoo */, ""/* memberAol */,
106: ""/* memberIcq */, ""/* memberMsn */,
107: ""/* memberCoolLink1 */, ""/* memberCoolLink2 */);
108:
109: // Now, create 4 default folders for each member
110: int memberID = MemberCache.getInstance()
111: .getMemberIDFromMemberName(memberName);
112: int folderStatus = 0;
113: int folderOption = 0;
114: int folderType = 0;
115: DAOFactory.getMessageFolderDAO().create(
116: MVNForumConstant.MESSAGE_FOLDER_INBOX, memberID,
117: 0/* order */, folderStatus, folderOption, folderType,
118: now, now);
119: DAOFactory.getMessageFolderDAO().create(
120: MVNForumConstant.MESSAGE_FOLDER_DRAFT, memberID,
121: 1/* order */, folderStatus, folderOption, folderType,
122: now, now);
123: DAOFactory.getMessageFolderDAO().create(
124: MVNForumConstant.MESSAGE_FOLDER_SENT, memberID,
125: 2/* order */, folderStatus, folderOption, folderType,
126: now, now);
127: DAOFactory.getMessageFolderDAO().create(
128: MVNForumConstant.MESSAGE_FOLDER_TRASH, memberID,
129: 3/* order */, folderStatus, folderOption, folderType,
130: now, now);
131:
132: // Add member to the lucene index
133: MemberBean memberBean = DAOFactory.getMemberDAO().getMember(
134: memberID);
135: MemberIndexer.scheduleAddMemberTask(memberBean);
136:
137: // now, if require activation, then we will send mail
138: // Note that because after this page succeed,
139: // we redirect to usermanagement so not use mvnforum.mail.failed now
140: if (MVNForumConfig.getRequireActivation()) {
141: String serverName = ParamUtil.getServerPath(); // ParamUtil.getServer2(request);
142: try {
143: SendMailUtil.sendActivationCodeEmail(memberID,
144: serverName);
145: } catch (Exception ex) {
146: log.error("Cannot send mail after registration!", ex);
147: request
148: .setAttribute("mvnforum.mail.failed",
149: "Cannot send activation email after registration!");
150: // @todo: save the error message to displayed later
151: }
152: }
153: }
154: }
|