2 * Copyright (C) 2001, 2002 The Mir-coders group
4 * This file is part of Mir.
6 * Mir is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Mir is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Mir; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * In addition, as a special exception, The Mir-coders gives permission to link
21 * the code of this program with any library licensed under the Apache Software License,
22 * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library
23 * (or with modified versions of the above that use the same license as the above),
24 * and distribute linked combinations including the two. You must obey the
25 * GNU General Public License in all respects for all of the code used other than
26 * the above mentioned libraries. If you modify this file, you may extend this
27 * exception to your version of the file, but you are not obligated to do so.
28 * If you do not wish to do so, delete this exception statement from your version.
31 package mircoders.servlet;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
38 import mir.log.LoggerWrapper;
39 import mir.servlet.ServletModule;
40 import mir.servlet.ServletModuleExc;
41 import mir.servlet.ServletModuleFailure;
42 import mir.servlet.ServletModuleUserExc;
43 import mir.storage.StorageObjectFailure;
44 import mir.util.HTTPRequestParser;
45 import mircoders.module.ModuleUsers;
46 import mircoders.storage.DatabaseUsers;
47 import freemarker.template.SimpleHash;
50 * ServletModuleUsers -
51 * liefert HTML fuer Users
57 public class ServletModuleUsers extends ServletModule
59 private static ServletModuleUsers instance = new ServletModuleUsers();
60 public static ServletModule getInstance() { return instance; }
62 private ServletModuleUsers() {
64 logger = new LoggerWrapper("ServletModule.Users");
66 templateListString = configuration.getString("ServletModule.Users.ListTemplate");
67 templateObjektString = configuration.getString("ServletModule.Users.ObjektTemplate");
68 templateConfirmString = configuration.getString("ServletModule.Users.ConfirmTemplate");
71 mainModule = new ModuleUsers(DatabaseUsers.getInstance());
73 catch (StorageObjectFailure e) {
74 logger.debug("initialization of ServletModuleUsers failed!: " + e.getMessage());
78 public void edit(HttpServletRequest req, HttpServletResponse res) throws ServletModuleExc
80 String idParam = req.getParameter("id");
83 throw new ServletModuleExc("ServletModuleUser.edit: invalid call: (id) not specified");
86 deliver(req, res, mainModule.getById(idParam), templateObjektString);
89 throw new ServletModuleFailure(e);
93 public void add(HttpServletRequest req, HttpServletResponse res)
94 throws ServletModuleExc
97 SimpleHash mergeData = new SimpleHash();
98 mergeData.put("new", "1");
99 deliver(req, res, mergeData, templateObjektString);
101 catch (Throwable e) {
102 throw new ServletModuleFailure(e);
106 public String checkPassword(HTTPRequestParser aRequestParser) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure
108 if ( (aRequestParser.getParameter("newpassword") != null &&
109 aRequestParser.getParameter("newpassword").length() > 0) ||
110 (aRequestParser.getParameter("newpassword2") != null &&
111 aRequestParser.getParameter("newpassword2").length() > 0)
113 String newPassword = aRequestParser.getParameterWithDefault("newpassword", "");
114 String newPassword2 = aRequestParser.getParameterWithDefault("newpassword2", "");
116 if (newPassword.length() == 0 || newPassword2.length() == 0) {
117 throw new ServletModuleUserExc("user.error.missingpasswords", new String[] {});
120 if (!newPassword.equals(newPassword2)) {
121 throw new ServletModuleUserExc("user.error.passwordmismatch", new String[] {});
130 public void insert(HttpServletRequest aRequest, HttpServletResponse aResponse)
131 throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure
134 HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
135 Map withValues = getIntersectingValues(aRequest, mainModule.getStorageObject());
137 String newPassword=checkPassword(requestParser);
138 if (newPassword!=null)
139 withValues.put("password", newPassword);
141 throw new ServletModuleUserExc("user.error.missingpassword", new String[] {});
143 String id = mainModule.add(withValues);
144 if (requestParser.hasParameter("returnurl"))
145 redirect(aResponse, requestParser.getParameter("returnurl"));
147 list(aRequest, aResponse);
149 catch (Throwable e) {
150 throw new ServletModuleFailure(e);
154 public void update(HttpServletRequest aRequest, HttpServletResponse aResponse) throws ServletModuleExc, ServletModuleUserExc, ServletModuleFailure
157 HTTPRequestParser requestParser = new HTTPRequestParser(aRequest);
159 Map withValues = getIntersectingValues(aRequest, mainModule.getStorageObject());
161 String newPassword=checkPassword(requestParser);
162 if (newPassword!=null)
163 withValues.put("password", newPassword);
165 mainModule.set(withValues);
167 if (requestParser.hasParameter("returnurl"))
168 redirect(aResponse, requestParser.getParameter("returnurl"));
170 list(aRequest, aResponse);
172 catch (Throwable e) {
173 throw new ServletModuleFailure(e);