KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $$Id: FogotPassAction.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 package org.jresearch.gossip.actions.user;
26
27 import java.sql.SQLException JavaDoc;
28
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import javax.servlet.http.HttpSession JavaDoc;
32
33 import org.apache.struts.action.ActionForm;
34 import org.apache.struts.action.ActionForward;
35 import org.apache.struts.action.ActionMapping;
36 import org.apache.struts.action.ActionMessage;
37 import org.apache.struts.action.ActionMessages;
38 import org.apache.struts.util.MessageResources;
39 import org.jresearch.gossip.IConst;
40 import org.jresearch.gossip.actions.BaseAction;
41 import org.jresearch.gossip.beans.user.User;
42 import org.jresearch.gossip.configuration.Configurator;
43 import org.jresearch.gossip.dao.UserDAO;
44 import org.jresearch.gossip.exception.SystemException;
45 import org.jresearch.gossip.forms.FogotPasswordForm;
46 import org.jresearch.gossip.mail.MailMessage;
47 import org.jresearch.gossip.mail.MailQueue;
48
49 /**
50  * DOCUMENT ME!
51  *
52  * @author $author$
53  * @version $Revision: 1.3 $
54  */

55 public final class FogotPassAction extends BaseAction {
56
57     /**
58      * DOCUMENT ME!
59      *
60      * @param mapping
61      * DOCUMENT ME!
62      * @param form
63      * DOCUMENT ME!
64      * @param request
65      * DOCUMENT ME!
66      * @param response
67      * DOCUMENT ME!
68      *
69      * @return DOCUMENT ME!
70      */

71     public ActionForward process(ActionMapping mapping, ActionForm form,
72             HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
73             throws SystemException {
74         if (IConst.VALUES.FALSE.equals(Configurator.getInstance().get(
75                 IConst.CONFIG.ENABLE_FORUM_SIGN_ON))) {
76             return (mapping.findForward(IConst.TOKEN.DENIED));
77         }
78
79         // Extract attributes we will need
80
HttpSession JavaDoc session = request.getSession();
81         ActionMessages errors = new ActionMessages();
82         UserDAO userDAO = UserDAO.getInstance();
83
84         FogotPasswordForm fpForm = (FogotPasswordForm) form;
85
86         try {
87
88             User updateduser = userDAO.setNewPassword(fpForm.getEmail(), fpForm
89                     .getUid());
90
91             if (updateduser.getStatus() == 0) {
92                 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
93                         "user.EMERROR"));
94             } else {
95                 /*
96                  * MailMessage(String messagetext, String subject, String
97                  * addrfrom, String namefrom, String addrto, String nameto)
98                  */

99                 MessageResources messages = getResources(request);
100
101                 /*
102                  * {0} - login {1} - new password {2} - site url {3} - site name
103                  */

104                 StringBuffer JavaDoc siteUrl = new StringBuffer JavaDoc();
105                 siteUrl.append(request.getServerName());
106                 siteUrl.append(":");
107                 siteUrl.append(request.getServerPort());
108                 siteUrl.append(request.getContextPath());
109                 siteUrl.append(Configurator.getInstance().get(
110                         IConst.CONFIG.MODULE_PREFIX));
111                 siteUrl.append("/");
112
113                 Object JavaDoc[] messArgs = new Object JavaDoc[] { updateduser.getName(),
114                         updateduser.getPassword(), siteUrl.toString(),
115                         Configurator.getInstance().get(IConst.CONFIG.SITE_NAME) };
116
117                 MailQueue queue = (MailQueue) session.getServletContext()
118                         .getAttribute(IConst.CONTEXT.MAIL_QUEUE);
119                 queue.push(new MailMessage(messages.getMessage(Configurator
120                         .getInstance().getLocale(IConst.CONFIG.DEFAULT_LOCALE),
121                         "mails.NEW_PASSWORD", messArgs), messages.getMessage(
122                         Configurator.getInstance().getLocale(
123                                 IConst.CONFIG.DEFAULT_LOCALE),
124                         "global.FORGOTPASS"), Configurator.getInstance().get(
125                         IConst.CONFIG.ADMINMAIL), messages.getMessage(
126                         Configurator.getInstance().getLocale(
127                                 IConst.CONFIG.DEFAULT_LOCALE),
128                         "mails.FORUM_ADMIN"), updateduser.getInfo().getEmail(),
129                         updateduser.getName()));
130                 setStatusMessage(request, "user.EMCONFIRM");
131                 log(request, "logs.LOG11", updateduser.getName());
132             }
133         } catch (SQLException JavaDoc sqle) {
134             getServlet().log("Connection.process", sqle);
135             throw new SystemException(sqle);
136         }
137
138         // Report any errors we have discovered back to the original form
139
if (!errors.isEmpty()) {
140             saveErrors(request, errors);
141
142             return (mapping.getInputForward());
143         }
144
145         return (mapping.findForward(IConst.TOKEN.WELCOME));
146     }
147 }
Popular Tags