2 * Copyright (C) 2001, 2002 The Mir-coders group
\r
4 * This file is part of Mir.
\r
6 * Mir is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 2 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Mir is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with Mir; if not, write to the Free Software
\r
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 * In addition, as a special exception, The Mir-coders gives permission to link
\r
21 * the code of this program with the com.oreilly.servlet library, any library
\r
22 * licensed under the Apache Software License, The Sun (tm) Java Advanced
\r
23 * Imaging library (JAI), The Sun JIMI library (or with modified versions of
\r
24 * the above that use the same license as the above), and distribute linked
\r
25 * combinations including the two. You must obey the GNU General Public
\r
26 * License in all respects for all of the code used other than the above
\r
27 * mentioned libraries. If you modify this file, you may extend this exception
\r
28 * to your version of the file, but you are not obligated to do so. If you do
\r
29 * not wish to do so, delete this exception statement from your version.
\r
32 package mircoders.servlet;
\r
34 import java.util.Map;
\r
36 import javax.servlet.http.HttpServletRequest;
\r
37 import javax.servlet.http.HttpServletResponse;
\r
39 import mir.log.LoggerWrapper;
\r
40 import mir.module.ModuleException;
\r
41 import mir.servlet.*;
\r
42 import mir.storage.StorageObjectFailure;
\r
43 import mir.util.HTTPRequestParser;
\r
44 import mircoders.module.ModuleUsers;
\r
45 import mircoders.storage.DatabaseUsers;
\r
46 import freemarker.template.SimpleHash;
\r
49 * ServletModuleUsers -
\r
50 * liefert HTML fuer Users
\r
56 public class ServletModuleUsers extends ServletModule
\r
58 private static ServletModuleUsers instance = new ServletModuleUsers();
\r
59 public static ServletModule getInstance() { return instance; }
\r
61 private ServletModuleUsers() {
\r
63 logger = new LoggerWrapper("ServletModule.Users");
\r
65 templateListString = configuration.getString("ServletModule.Users.ListTemplate");
\r
66 templateObjektString = configuration.getString("ServletModule.Users.ObjektTemplate");
\r
67 templateConfirmString = configuration.getString("ServletModule.Users.ConfirmTemplate");
\r
70 mainModule = new ModuleUsers(DatabaseUsers.getInstance());
\r
72 catch (StorageObjectFailure e) {
\r
73 logger.debug("initialization of ServletModuleUsers failed!: " + e.getMessage());
\r
77 public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc
\r
79 String idParam = req.getParameter("id");
\r
81 if (idParam == null)
\r
82 throw new ServletModuleExc("ServletModuleUser.edit: invalid call: (id) not specified");
\r
85 deliver(req, res, mainModule.getById(idParam), templateObjektString);
\r
87 catch (Throwable e) {
\r
88 throw new ServletModuleFailure(e);
\r
92 public void add(HttpServletRequest req, HttpServletResponse res)
\r
93 throws ServletModuleExc
\r
96 SimpleHash mergeData = new SimpleHash();
\r
97 mergeData.put("new", "1");
\r
98 deliver(req, res, mergeData, templateObjektString);
\r
100 catch (Throwable e) {
\r
101 throw new ServletModuleFailure(e);
\r
105 public String checkPassword(HTTPRequestParser aRequestParser) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure
\r
107 if ( (aRequestParser.getParameter("newpassword") != null &&
\r
108 aRequestParser.getParameter("newpassword").length() > 0) ||
\r
109 (aRequestParser.getParameter("newpassword2") != null &&
\r
110 aRequestParser.getParameter("newpassword2").length() > 0)
\r
112 String newPassword = aRequestParser.getParameterWithDefault("newpassword", "");
\r
113 String newPassword2 = aRequestParser.getParameterWithDefault("newpassword2", "");
\r
115 if (newPassword.length() == 0 || newPassword2.length() == 0) {
\r
116 throw new ServletModuleUserExc("The new password must be entered twice!");
\r
119 if (!newPassword.equals(newPassword2)) {
\r
120 throw new ServletModuleUserExc("New password differes from confirmation");
\r
123 return newPassword;
\r
129 public void insert(HttpServletRequest aRequest, HttpServletResponse aResponse)
\r
130 throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure
\r
133 HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
\r
134 Map withValues = getIntersectingValues(aRequest, mainModule.getStorageObject());
\r
136 String newPassword=checkPassword(requestParser);
\r
137 if (newPassword!=null)
\r
138 withValues.put("password", newPassword);
\r
140 throw new ServletModuleUserExc("Password is empty");
\r
142 String id = mainModule.add(withValues);
\r
143 if (requestParser.hasParameter("returnurl"))
\r
144 redirect(aResponse, requestParser.getParameter("returnurl"));
\r
146 list(aRequest, aResponse);
\r
148 catch (Throwable e) {
\r
149 throw new ServletModuleFailure(e);
\r
153 public void update(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure
\r
156 HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
\r
158 Map withValues = getIntersectingValues(aRequest, mainModule.getStorageObject());
\r
160 String newPassword=checkPassword(requestParser);
\r
161 if (newPassword!=null)
\r
162 withValues.put("password", newPassword);
\r
164 mainModule.set(withValues);
\r
166 if (requestParser.hasParameter("returnurl"))
\r
167 redirect(aResponse, requestParser.getParameter("returnurl"));
\r
169 list(aRequest, aResponse);
\r
171 catch (Throwable e) {
\r
172 throw new ServletModuleFailure(e);
\r