KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $$Id: SaveProfileAction.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 06.06.2003
27  *
28  */

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

59 public class SaveProfileAction 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 JGossipException {
78         HttpSession JavaDoc session = request.getSession();
79
80         User user = (User) session.getAttribute(IConst.SESSION.USER_KEY);
81         UserDAO dao = UserDAO.getInstance();
82         ProfileForm pForm = (ProfileForm) form;
83         String JavaDoc forward = IConst.TOKEN.PAGE;
84         try {
85             if (Configurator.getInstance().getBoolean(
86                     IConst.CONFIG.ENABLE_EXT_SIGN_ON)
87                     && !dao.isUserExist(user.getName())) {
88                 // add new forum user
89
pForm.setLogin(user.getName());
90                 pForm.setPassword(user.getName());
91                 pForm.setPassword2(user.getName());
92                 dao.addUser(pForm);
93                 user = dao.getUser(pForm.getLogin(), pForm.getPassword());
94                 if (user.getStatus() == UserStatus.GUEST) {
95                     session.setAttribute(IConst.SESSION.USER_KEY, user);
96                     throw new LogicException(getResources(request).getMessage(
97                             "errors.ERR22")
98                             + user.getName());
99                 }
100                 user.setIp(request.getRemoteAddr());
101                 forward = IConst.TOKEN.WELCOME;
102                 log(request, "logs.LOG7", user.getName());
103             } else {
104                 // update user info
105
dao.updateUser(pForm, user.getName());
106                 user = dao.getUserEncoded(user.getName(), user.getPassword());
107                 user.setIp(request.getRemoteAddr());
108                 log(request, "logs.LOG19");
109
110             }
111
112             if (Configurator.getInstance().getBoolean(
113                     IConst.CONFIG.ENABLE_AUTO_LOGIN)) {
114                 // set autolog cookies if needed...
115
if (user.getSettings().isAutologin()) {
116                     Cookie JavaDoc userCookie = new Cookie JavaDoc(IConst.COOKIE.USER_COOKIE,
117                             user.getName() + "*" + user.getPassword());
118                     userCookie.setMaxAge(IConst.COOKIE.SECONDS_PER_YEAR);
119                     ((HttpServletResponse JavaDoc) response).addCookie(userCookie);
120                 }
121             }
122             session.setAttribute(IConst.SESSION.USER_KEY, user);
123             setStatusMessage(request, "status.UPDATE_DETAILS");
124         } catch (SQLException JavaDoc sqle) {
125             getServlet().log("Connection.process", sqle);
126             throw new SystemException(sqle);
127         }
128         Logger log = JGossipLog.getInstance().getAppLogger();
129         if (log.isDebugEnabled()) {
130             log.debug("forward is " + forward);
131         }
132         return mapping.findForward(forward);
133     }
134 }
Popular Tags