1 | <%-- $Id: submit_user.jsp 7605 2019-02-26 10:10:15Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | Copyright (C) 2005 Nicklas Nordborg |
---|
4 | Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg |
---|
5 | Copyright (C) 2007 Johan Enell, Nicklas Nordborg, Martin Svensson |
---|
6 | |
---|
7 | This file is part of BASE - BioArray Software Environment. |
---|
8 | Available at http://base.thep.lu.se/ |
---|
9 | |
---|
10 | BASE is free software; you can redistribute it and/or |
---|
11 | modify it under the terms of the GNU General Public License |
---|
12 | as published by the Free Software Foundation; either version 3 |
---|
13 | of the License, or (at your option) any later version. |
---|
14 | |
---|
15 | BASE is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License |
---|
21 | along with BASE. If not, see <http://www.gnu.org/licenses/>. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | This page will save user information and preferences. |
---|
25 | |
---|
26 | @param cmd The command to execute |
---|
27 | - SaveSettings: Save the settings from the settings.jsp page. |
---|
28 | - SavePreferences: Save preferences from the preferences.jsp page. |
---|
29 | |
---|
30 | @author Nicklas |
---|
31 | @version 2.0 |
---|
32 | --%> |
---|
33 | <%@ page pageEncoding="UTF-8" session="false" |
---|
34 | import="net.sf.basedb.core.SessionControl" |
---|
35 | import="net.sf.basedb.core.DbControl" |
---|
36 | import="net.sf.basedb.core.Item" |
---|
37 | import="net.sf.basedb.core.User" |
---|
38 | import="net.sf.basedb.core.ItemContext" |
---|
39 | import="net.sf.basedb.core.ExtendedProperty" |
---|
40 | import="net.sf.basedb.core.ExtendedProperties" |
---|
41 | import="net.sf.basedb.util.EmailUtil" |
---|
42 | import="net.sf.basedb.clients.web.Base" |
---|
43 | import="net.sf.basedb.clients.web.WebException" |
---|
44 | import="net.sf.basedb.clients.web.util.HTML" |
---|
45 | import="net.sf.basedb.util.Values" |
---|
46 | import="net.sf.basedb.util.formatter.Formatter" |
---|
47 | import="net.sf.basedb.util.extensions.ExtensionsInvoker" |
---|
48 | import="net.sf.basedb.clients.web.formatter.FormatterSettings" |
---|
49 | import="net.sf.basedb.clients.web.formatter.FormatterFactory" |
---|
50 | import="net.sf.basedb.clients.web.extensions.edit.OnSaveAction" |
---|
51 | import="net.sf.basedb.clients.web.extensions.edit.OnSaveRenderer" |
---|
52 | import="net.sf.basedb.clients.web.extensions.edit.EditUtil" |
---|
53 | import="net.sf.basedb.clients.web.extensions.ExtensionsControl" |
---|
54 | import="net.sf.basedb.clients.web.extensions.JspContext" |
---|
55 | import="java.util.Arrays" |
---|
56 | import="java.util.Collections" |
---|
57 | import="java.util.List" |
---|
58 | import="java.util.Map" |
---|
59 | %> |
---|
60 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
61 | <% |
---|
62 | SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
63 | String ID = sc.getId(); |
---|
64 | String cmd = request.getParameter("cmd"); |
---|
65 | String message = ""; |
---|
66 | String root = request.getContextPath()+"/"; |
---|
67 | |
---|
68 | String forward = null; |
---|
69 | DbControl dc = sc.newDbControl(); |
---|
70 | try |
---|
71 | { |
---|
72 | if ("SaveSettings".equals(cmd)) |
---|
73 | { |
---|
74 | String email = Values.getStringOrNull(request.getParameter("email")); |
---|
75 | if (email != null && !HTML.isValidEmail(email)) |
---|
76 | { |
---|
77 | throw new WebException("popup", "Invalid email address", |
---|
78 | "The email address {1} is not a valid email address.", |
---|
79 | HTML.encodeTags(email) |
---|
80 | ); |
---|
81 | } |
---|
82 | User user = sc.getSessionSetting("user"); |
---|
83 | dc.reattachItem(user, false); |
---|
84 | |
---|
85 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, null, user); |
---|
86 | ExtensionsInvoker<OnSaveAction> invoker = ExtensionsControl.useExtensions(jspContext, EditUtil.EP_PREFIX_SAVE+"user-information"); |
---|
87 | try |
---|
88 | { |
---|
89 | // Contact information tab |
---|
90 | user.setEmail(email); |
---|
91 | boolean useDeviceVerification = Values.getBoolean(request.getParameter("useDeviceVerification")); |
---|
92 | if (!useDeviceVerification) user.disableDeviceVerification(); |
---|
93 | if (EmailUtil.isEnabled()) |
---|
94 | { |
---|
95 | user.setSendMessagesAsEmail(email != null && Values.getBoolean(request.getParameter("sendMessagesAsEmail"))); |
---|
96 | if (useDeviceVerification && !user.getUseDeviceVerification()) |
---|
97 | { |
---|
98 | // Send a verification code for verifying the email address |
---|
99 | forward = "verify_email.jsp?ID="+ID; |
---|
100 | } |
---|
101 | } |
---|
102 | user.setOrganisation(Values.getStringOrNull(request.getParameter("organisation"))); |
---|
103 | user.setAddress(Values.getStringOrNull(request.getParameter("address"))); |
---|
104 | user.setPhone(Values.getStringOrNull(request.getParameter("phone"))); |
---|
105 | user.setFax(Values.getStringOrNull(request.getParameter("fax"))); |
---|
106 | user.setUrl(Values.getStringOrNull(request.getParameter("url"))); |
---|
107 | |
---|
108 | // Password tab |
---|
109 | String password = Values.getStringOrNull(request.getParameter("password")); |
---|
110 | if (password != null) user.setPassword(password); |
---|
111 | |
---|
112 | // Other settings tab |
---|
113 | user.setDescription(Values.getStringOrNull(request.getParameter("description"))); |
---|
114 | |
---|
115 | // Extended properties |
---|
116 | List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData", true); |
---|
117 | if (extendedProperties != null) |
---|
118 | { |
---|
119 | Map<String, String[]> parameters = request.getParameterMap(); |
---|
120 | for (ExtendedProperty ep : extendedProperties) |
---|
121 | { |
---|
122 | if (ep.isRestrictedEdit()) continue; |
---|
123 | String name = ep.getName(); |
---|
124 | if (parameters.containsKey("ep."+name)) |
---|
125 | { |
---|
126 | Formatter<?> formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep); |
---|
127 | Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name))); |
---|
128 | user.setExtended(name, value); |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | // OnSave extensions |
---|
134 | invoker.render(OnSaveRenderer.ON_SAVE); |
---|
135 | dc.commit(); |
---|
136 | invoker.render(OnSaveRenderer.ON_COMMIT); |
---|
137 | message = "Information saved"; |
---|
138 | } |
---|
139 | catch (Exception ex) |
---|
140 | { |
---|
141 | invoker.render(OnSaveRenderer.onRollback(ex)); |
---|
142 | throw ex; |
---|
143 | } |
---|
144 | finally |
---|
145 | { |
---|
146 | sc.setSessionSetting("user", null); |
---|
147 | } |
---|
148 | } |
---|
149 | else if ("VerifyEmail".equals(cmd)) |
---|
150 | { |
---|
151 | String verificationCode = request.getParameter("verificationCode"); |
---|
152 | User user = sc.getSessionSetting("user"); |
---|
153 | dc.reattachItem(user, false); |
---|
154 | user.enableDeviceVerification(verificationCode); |
---|
155 | message = "The email has been verified"; |
---|
156 | dc.commit(); |
---|
157 | } |
---|
158 | else if ("SavePreferences".equals(cmd)) |
---|
159 | { |
---|
160 | User user = User.getById(dc, sc.getLoggedInUserId()); |
---|
161 | JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, null, user); |
---|
162 | ExtensionsInvoker<OnSaveAction> invoker = ExtensionsControl.useExtensions(jspContext, EditUtil.EP_PREFIX_SAVE+"user-information"); |
---|
163 | try |
---|
164 | { |
---|
165 | int newScale = Values.getInt(request.getParameter("scale"), 100); |
---|
166 | sc.setUserClientSetting("appearance.scale", Integer.toString(newScale)); |
---|
167 | sc.setUserClientSetting("appearance.fontsize", Values.getString(request.getParameter("fontsize"), "size_m.css")); |
---|
168 | sc.setSessionSetting("appearance.scale", new Float(newScale / 100.0)); |
---|
169 | sc.setUserClientSetting("text.long", request.getParameter("longTexts")); |
---|
170 | ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING); |
---|
171 | int maxRecent = Base.getMaxRecent(sc); |
---|
172 | |
---|
173 | String toolbar = request.getParameter("toolbar"); |
---|
174 | boolean hasImages = true; |
---|
175 | boolean hasText = true; |
---|
176 | if ("text".equals(toolbar)) |
---|
177 | { |
---|
178 | hasImages = false; |
---|
179 | } |
---|
180 | else if ("images".equals(toolbar)) |
---|
181 | { |
---|
182 | hasText = false; |
---|
183 | } |
---|
184 | sc.setUserClientSetting("toolbar.images", hasImages ? "1" : "0"); |
---|
185 | sc.setUserClientSetting("toolbar.text", hasText ? "1" : "0"); |
---|
186 | String minColor = Values.getString(request.getParameter("mincolor"), "0000FF"); |
---|
187 | String midColor = Values.getString(request.getParameter("midcolor"), "FFFFFF"); |
---|
188 | String maxColor = Values.getString(request.getParameter("maxcolor"), "FFFF00"); |
---|
189 | sc.setUserClientSetting("ratiocolor.min", minColor); |
---|
190 | sc.setUserClientSetting("ratiocolor.mid", midColor); |
---|
191 | sc.setUserClientSetting("ratiocolor.max", maxColor); |
---|
192 | cc.setRecent("colors", minColor + "," + midColor + "," + maxColor, maxRecent); |
---|
193 | |
---|
194 | String dateFormat = request.getParameter("date_format"); |
---|
195 | String dateTimeFormat = request.getParameter("datetime_format"); |
---|
196 | FormatterSettings.setDateFormat(sc, dateFormat); |
---|
197 | FormatterSettings.setDateTimeFormat(sc, dateTimeFormat); |
---|
198 | cc.setRecent("dateFormats", dateFormat, maxRecent); |
---|
199 | cc.setRecent("dateTimeFormats", dateTimeFormat, maxRecent); |
---|
200 | |
---|
201 | int numDecimals = Values.getInt(request.getParameter("decimals"), 2); |
---|
202 | FormatterSettings.setNumDecimals(sc, numDecimals); |
---|
203 | |
---|
204 | sc.setUserClientSetting("dialogs.remember-positions", Values.getBoolean(request.getParameter("remember_positions")) ? "1" : "0"); |
---|
205 | |
---|
206 | sc.setUserClientSetting("start-page-id", Values.getStringOrNull(request.getParameter("start_page"))); |
---|
207 | |
---|
208 | // Plugins tab |
---|
209 | sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0")); |
---|
210 | sc.setUserClientSetting("plugins.removejob", Values.getString(request.getParameter("removejob"), "0")); |
---|
211 | sc.setUserClientSetting("plugins.showWarnings", Values.getString(request.getParameter("show_warnings"), "0")); |
---|
212 | |
---|
213 | // Recent items tab |
---|
214 | int newMaxUsed = Values.getInt(request.getParameter("maxUsed"), 4); |
---|
215 | sc.setUserClientSetting("appearance.recent", Integer.toString(newMaxUsed)); |
---|
216 | sc.setSessionSetting("appearance.recent", newMaxUsed); |
---|
217 | int newMaxViewed = Values.getInt(request.getParameter("maxViewed"), 6); |
---|
218 | sc.setUserClientSetting("menu.mostRecent.maxViewed", Integer.toString(newMaxViewed)); |
---|
219 | sc.setUserClientSetting("menu.mostRecent.loadNames", Values.getString(request.getParameter("loadNames"), "0")); |
---|
220 | |
---|
221 | String[] stickyItems = request.getParameterValues("sticky_items"); |
---|
222 | sc.setUserClientSetting("menu.mostRecent", |
---|
223 | stickyItems == null ? "" : Values.getString(Arrays.asList(stickyItems), ":", true)); |
---|
224 | |
---|
225 | // Roles tab |
---|
226 | String[] inactiveRoles = request.getParameterValues("inactiveRoles"); |
---|
227 | sc.setUserClientSetting("inactiveRoles", inactiveRoles == null ? null : Values.getString(Arrays.asList(inactiveRoles), ":", true)); |
---|
228 | |
---|
229 | // OnSave extensions |
---|
230 | invoker.render(OnSaveRenderer.ON_SAVE); |
---|
231 | dc.commit(); |
---|
232 | invoker.render(OnSaveRenderer.ON_COMMIT); |
---|
233 | message = "Preferences saved"; |
---|
234 | } |
---|
235 | catch (Exception ex) |
---|
236 | { |
---|
237 | invoker.render(OnSaveRenderer.onRollback(ex)); |
---|
238 | throw ex; |
---|
239 | } |
---|
240 | } |
---|
241 | else if ("ReloadPermissions".equals(cmd)) |
---|
242 | { |
---|
243 | sc.reloadPermissions(); |
---|
244 | sc.reloadSettings(true, false); |
---|
245 | sc.setSessionSetting("menu.standard.html", null); |
---|
246 | message = "Permissions reloaded"; |
---|
247 | } |
---|
248 | else if ("ResetFilters".equals(cmd)) |
---|
249 | { |
---|
250 | boolean inDatabase = Values.getBoolean(request.getParameter("database")); |
---|
251 | String itemType = Values.getStringOrNull(request.getParameter("item_type")); |
---|
252 | Item item = itemType == null ? null : Item.valueOf(itemType); |
---|
253 | int numDeleted = sc.deleteCurrentContexts(item, true, inDatabase); |
---|
254 | message = numDeleted + " list settings deleted"; |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd); |
---|
259 | } |
---|
260 | } |
---|
261 | finally |
---|
262 | { |
---|
263 | if (dc != null) dc.close(); |
---|
264 | } |
---|
265 | |
---|
266 | if (forward != null) |
---|
267 | { |
---|
268 | pageContext.forward(forward); |
---|
269 | } |
---|
270 | else |
---|
271 | { |
---|
272 | response.sendRedirect(root + "common/close_popup.jsp?ID="+ID+"&refresh_opener=1&&message="+HTML.urlEncode(message)); |
---|
273 | } |
---|
274 | %> |
---|
275 | |
---|