KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jresearch > gossip > actions > admin > user > AddUserAction


1 /*
2  * $$Id: AddUserAction.java,v 1.3 2005/06/07 12:31:53 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.admin.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.ProfileForm;
50 import org.jresearch.gossip.mail.MailMessage;
51 import org.jresearch.gossip.mail.MailQueue;
52
53 /**
54  * DOCUMENT ME!
55  *
56  * @author Bel
57  */

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

74     public ActionForward process(ActionMapping mapping, ActionForm form,
75             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
76             throws SystemException {
77         if (IConst.VALUES.FALSE.equals(Configurator.getInstance().get(
78                 IConst.CONFIG.ENABLE_FORUM_SIGN_ON))) {
79             return (mapping.findForward(IConst.TOKEN.DENIED));
80         }
81
82         HttpSession JavaDoc session = request.getSession();
83         UserDAO dao = UserDAO.getInstance();
84
85         try {
86
87             ProfileForm pf = (ProfileForm) form;
88             String JavaDoc tempPass = dao.generatePassword();
89             pf.setPassword(tempPass);
90             pf.setPassword2(tempPass);
91
92             if (dao.addUser(pf)) {
93                 User newuser = dao.getUser(pf.getLogin(), pf.getPassword());
94                 log(request, "logs.LOG29", newuser.getName());
95                 setStatusMessage(request, "status.USER_ADDED", newuser
96                         .getName());
97
98                 /*
99                  * MailMessage(String messagetext, String subject, String
100                  * addrfrom, String namefrom, String addrto, String nameto)
101                  */

102                 MessageResources messages = getResources(request);
103                 Configurator config = Configurator.getInstance();
104
105                 /*
106                  * {0} - login {1} - new password {2} - site url {3} - site name
107                  */

108                 StringBuffer JavaDoc siteUrl = new StringBuffer JavaDoc();
109                 siteUrl.append(request.getServerName());
110                 siteUrl.append(":");
111                 siteUrl.append(request.getServerPort());
112                 siteUrl.append(request.getContextPath());
113                 siteUrl.append(config.get(IConst.CONFIG.MODULE_PREFIX));
114                 siteUrl.append("/");
115
116                 Object JavaDoc[] messArgs = new Object JavaDoc[] { newuser.getName(), tempPass,
117                         siteUrl.toString(), config.get(IConst.CONFIG.SITE_NAME) };
118
119                 MailQueue queue = (MailQueue) session.getServletContext()
120                         .getAttribute(IConst.CONTEXT.MAIL_QUEUE);
121                 queue.push(new MailMessage(messages.getMessage(Configurator
122                         .getInstance().getLocale(IConst.CONFIG.DEFAULT_LOCALE),
123                         "mails.NEW_ACCOUNT", messArgs), messages.getMessage(
124                         Configurator.getInstance().getLocale(
125                                 IConst.CONFIG.DEFAULT_LOCALE),
126                         "mails.NEW_USER_SUBJ", config
127                                 .get(IConst.CONFIG.SITE_NAME)), config
128                         .get(IConst.CONFIG.ADMINMAIL), messages.getMessage(
129                         Configurator.getInstance().getLocale(
130                                 IConst.CONFIG.DEFAULT_LOCALE),
131                         "mails.FORUM_ADMIN"), newuser.getInfo().getEmail(),
132                         newuser.getName()));
133             } else {
134                 ActionMessages errors = new ActionMessages();
135                 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
136                         "errors.ERR6"));
137
138                 saveErrors(request, errors);
139
140                 return (mapping.getInputForward());
141             }
142         } catch (SQLException JavaDoc sqle) {
143             getServlet().log("Connection.process", sqle);
144             throw new SystemException(sqle);
145         }
146
147         return (mapping.findForward(IConst.TOKEN.WELCOME));
148     }
149 }
Popular Tags