KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > user > ConfirmPendingRegistrationAction


1 /*
2  * $$Id: ConfirmPendingRegistrationAction.java,v 1.3 2005/06/07 12:32:29 bel70 Exp $$
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * The contents of this file are subject to the Mozilla Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License
8  * at http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific language governing rights and
13  * limitations under the License.
14  *
15  * The Original Code is JGossip forum code.
16  *
17  * The Initial Developer of the Original Code is the JResearch, Org.
18  * Portions created by the Initial Developer are Copyright (C) 2004
19  * the Initial Developer. All Rights Reserved.
20  *
21  * Contributor(s):
22  * Dmitry Belov <bel@jresearch.org>
23  *
24  * ***** END LICENSE BLOCK ***** */

25 /*
26  * Created on 01.06.2003
27  *
28  */

29 package org.jresearch.gossip.actions.user;
30
31 import java.sql.SQLException JavaDoc;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35 import javax.servlet.http.HttpSession JavaDoc;
36
37 import org.apache.struts.action.ActionForm;
38 import org.apache.struts.action.ActionForward;
39 import org.apache.struts.action.ActionMapping;
40 import org.apache.struts.action.ActionMessage;
41 import org.apache.struts.action.ActionMessages;
42 import org.apache.struts.util.MessageResources;
43 import org.jresearch.gossip.IConst;
44 import org.jresearch.gossip.actions.BaseAction;
45 import org.jresearch.gossip.beans.user.User;
46 import org.jresearch.gossip.configuration.Configurator;
47 import org.jresearch.gossip.dao.UserDAO;
48 import org.jresearch.gossip.exception.SystemException;
49 import org.jresearch.gossip.forms.PendingRegistrationForm;
50 import org.jresearch.gossip.forms.ProfileForm;
51 import org.jresearch.gossip.mail.MailMessage;
52 import org.jresearch.gossip.mail.MailQueue;
53
54 /**
55  * DOCUMENT ME!
56  *
57  * @author Bel
58  */

59 public class ConfirmPendingRegistrationAction extends BaseAction {
60
61     /**
62      * DOCUMENT ME!
63      *
64      * @param mapping
65      * DOCUMENT ME!
66      * @param form
67      * DOCUMENT ME!
68      * @param request
69      * DOCUMENT ME!
70      * @param response
71      * DOCUMENT ME!
72      *
73      * @return DOCUMENT ME!
74      */

75     public ActionForward process(ActionMapping mapping, ActionForm form,
76             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
77             throws SystemException {
78         if (IConst.VALUES.FALSE.equals(Configurator.getInstance().get(
79                 IConst.CONFIG.ENABLE_FORUM_SIGN_ON))
80                 || IConst.VALUES.FALSE.equals(Configurator.getInstance().get(
81                         IConst.CONFIG.ENABLE_FORUM_REGISTRATION))
82                 || IConst.VALUES.FALSE.equals(Configurator.getInstance().get(
83                         IConst.CONFIG.ENABLE_EMAIL_CONFIRMATION))) {
84             return (mapping.findForward(IConst.TOKEN.DENIED));
85         }
86
87         HttpSession JavaDoc session = request.getSession();
88         UserDAO dao = UserDAO.getInstance();
89         PendingRegistrationForm pprForm = (PendingRegistrationForm) form;
90         try {
91
92             ProfileForm profile = new ProfileForm();
93             profile.setLogin(pprForm.getLogin());
94             profile.setEmail(pprForm.getEmail());
95             String JavaDoc password = dao.generatePassword();
96             profile.setPassword(password);
97             profile.setPassword2(password);
98
99             if (dao.checkPendingUser(pprForm.getLogin(), pprForm.getCode())
100                     && dao.addUser(profile)) {
101                 dao.deletePendingUser(pprForm.getLogin());
102                 User newuser = dao.getUser(profile.getLogin(), profile
103                         .getPassword());
104                 log(request, "logs.LOG7", newuser.getName());
105
106                 if (newuser.getStatus() > 0) {
107                     newuser.setIp(request.getRemoteAddr());
108                     session.setAttribute(IConst.SESSION.USER_KEY, newuser);
109                     /*
110                      * MailMessage(String messagetext, String subject, String
111                      * addrfrom, String namefrom, String addrto, String nameto)
112                      */

113                     MessageResources messages = getResources(request);
114                     Configurator config = Configurator.getInstance();
115
116                     /*
117                      * {0} - login {1} - new password {2} - site url {3} - site
118                      * name
119                      */

120                     StringBuffer JavaDoc siteUrl = new StringBuffer JavaDoc();
121                     siteUrl.append(request.getServerName());
122                     siteUrl.append(":");
123                     siteUrl.append(request.getServerPort());
124                     siteUrl.append(request.getContextPath());
125                     siteUrl.append(config.get(IConst.CONFIG.MODULE_PREFIX));
126                     siteUrl.append("/");
127
128                     Object JavaDoc[] messArgs = new Object JavaDoc[] { newuser.getName(),
129                             profile.getPassword(), siteUrl.toString(),
130                             config.get(IConst.CONFIG.SITE_NAME) };
131
132                     MailQueue queue = (MailQueue) session.getServletContext()
133                             .getAttribute(IConst.CONTEXT.MAIL_QUEUE);
134                     queue.push(new MailMessage(messages.getMessage(Configurator
135                             .getInstance().getLocale(
136                                     IConst.CONFIG.DEFAULT_LOCALE),
137                             "mails.NEW_ACCOUNT", messArgs), messages
138                             .getMessage(Configurator.getInstance().getLocale(
139                                     IConst.CONFIG.DEFAULT_LOCALE),
140                                     "mails.NEW_USER_SUBJ", config
141                                             .get(IConst.CONFIG.SITE_NAME)),
142                             config.get(IConst.CONFIG.ADMINMAIL),
143                             messages.getMessage(Configurator.getInstance()
144                                     .getLocale(IConst.CONFIG.DEFAULT_LOCALE),
145                                     "mails.FORUM_ADMIN"), newuser.getInfo()
146                                     .getEmail(), newuser.getName()));
147                 }
148             } else {
149                 ActionMessages errors = new ActionMessages();
150
151                 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
152                         "errors.ERR6"));
153
154                 saveErrors(request, errors);
155
156                 return (mapping.getInputForward());
157             }
158         } catch (SQLException JavaDoc sqle) {
159             getServlet().log("Connection.process", sqle);
160             throw new SystemException(sqle);
161         }
162
163         return (mapping.findForward(IConst.TOKEN.WELCOME));
164     }
165 }
Popular Tags