source: trunk/www/my_base/user/submit_user.jsp @ 7295

Last change on this file since 7295 was 7295, checked in by Nicklas Nordborg, 5 years ago

References #2043: Activating/deactivating roles on the fly in a login session

Added a "Inactive roles" tab in the "Preferences" dialog. This allows a user to set roles that should be inactive by default after logging in.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.3 KB
Line 
1<%-- $Id: submit_user.jsp 7295 2017-02-20 07:09:27Z 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.clients.web.formatter.FormatterSettings"
48  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
49  import="java.util.Arrays"
50  import="java.util.Collections"
51  import="java.util.List"
52%>
53<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
54<%
55SessionControl sc = Base.getExistingSessionControl(pageContext, true);
56String ID = sc.getId();
57String cmd = request.getParameter("cmd");
58String message = "";
59String root = request.getContextPath()+"/";
60
61DbControl dc = sc.newDbControl();
62try
63{
64  if ("SaveSettings".equals(cmd))
65  {
66    String email = Values.getStringOrNull(request.getParameter("email"));
67    if (email != null && !HTML.isValidEmail(email))
68    {
69      throw new WebException("popup", "Invalid email address",
70        "The email address {1} is not a valid email address.",
71        HTML.encodeTags(email)
72      );
73    }
74    User user = (User)sc.getSessionSetting("user");
75    dc.reattachItem(user, false);
76
77    // Contact information tab
78    user.setEmail(email);
79    if (EmailUtil.isEnabled())
80    {
81      user.setSendMessagesAsEmail(email != null && Values.getBoolean(request.getParameter("sendMessagesAsEmail")));
82    }
83    user.setOrganisation(Values.getStringOrNull(request.getParameter("organisation")));
84    user.setAddress(Values.getStringOrNull(request.getParameter("address")));
85    user.setPhone(Values.getStringOrNull(request.getParameter("phone")));
86    user.setFax(Values.getStringOrNull(request.getParameter("fax")));
87    user.setUrl(Values.getStringOrNull(request.getParameter("url")));
88
89    // Password tab
90    String password = Values.getStringOrNull(request.getParameter("password"));
91    if (password != null) user.setPassword(password);
92
93    // Other settings tab
94    user.setDescription(Values.getStringOrNull(request.getParameter("description")));
95
96    // Extended properties
97    List<ExtendedProperty> extendedProperties = ExtendedProperties.getProperties("UserData");
98    if (extendedProperties != null)
99    {
100      for (ExtendedProperty ep : extendedProperties)
101      {
102        if (ep.isRestrictedEdit()) continue;
103        String name = ep.getName();
104        Formatter formatter = FormatterFactory.getExtendedPropertyFormatter(sc, ep);
105        Object value = formatter.parseString(Values.getStringOrNull(request.getParameter("ep."+name)));
106        user.setExtended(name, value);
107      }
108    }
109
110    dc.commit();
111    sc.setSessionSetting("user", null);
112    message = "Information saved";
113  }
114  else if ("SavePreferences".equals(cmd))
115  {
116    int newScale = Values.getInt(request.getParameter("scale"), 100);
117    sc.setUserClientSetting("appearance.scale", Integer.toString(newScale));
118    sc.setUserClientSetting("appearance.fontsize", Values.getString(request.getParameter("fontsize"), "size_m.css"));
119    sc.setSessionSetting("appearance.scale", new Float(newScale / 100.0));
120    sc.setUserClientSetting("text.long", request.getParameter("longTexts"));
121    ItemContext cc = sc.getCurrentContext(Item.USERCLIENTSETTING);
122    int maxRecent = Base.getMaxRecent(sc);
123 
124    String toolbar = request.getParameter("toolbar");
125    boolean hasImages = true;
126    boolean hasText = true;
127    if ("text".equals(toolbar))
128    {
129      hasImages = false;
130    }
131    else if ("images".equals(toolbar))
132    {
133      hasText = false;
134    }
135    sc.setUserClientSetting("toolbar.images", hasImages ? "1" : "0");
136    sc.setUserClientSetting("toolbar.text", hasText ? "1" : "0");
137    String minColor = Values.getString(request.getParameter("mincolor"), "0000FF");
138    String midColor = Values.getString(request.getParameter("midcolor"), "FFFFFF");
139    String maxColor = Values.getString(request.getParameter("maxcolor"), "FFFF00");
140    sc.setUserClientSetting("ratiocolor.min", minColor);
141    sc.setUserClientSetting("ratiocolor.mid", midColor);
142    sc.setUserClientSetting("ratiocolor.max", maxColor);
143    cc.setRecent("colors", minColor + "," + midColor + "," + maxColor, maxRecent);
144   
145    String dateFormat = request.getParameter("date_format");
146    String dateTimeFormat = request.getParameter("datetime_format");
147    FormatterSettings.setDateFormat(sc, dateFormat);
148    FormatterSettings.setDateTimeFormat(sc, dateTimeFormat);
149    cc.setRecent("dateFormats", dateFormat, maxRecent);
150    cc.setRecent("dateTimeFormats", dateTimeFormat, maxRecent);
151
152    int numDecimals = Values.getInt(request.getParameter("decimals"), 2);
153    FormatterSettings.setNumDecimals(sc, numDecimals);
154   
155    sc.setUserClientSetting("dialogs.remember-positions", Values.getBoolean(request.getParameter("remember_positions")) ? "1" : "0");
156   
157    sc.setUserClientSetting("start-page-id", Values.getStringOrNull(request.getParameter("start_page")));
158   
159    // Plugins tab
160    sc.setUserClientSetting("plugins.sendmessage", Values.getString(request.getParameter("sendmessage"), "0"));
161    sc.setUserClientSetting("plugins.removejob", Values.getString(request.getParameter("removejob"), "0"));
162    sc.setUserClientSetting("plugins.showWarnings", Values.getString(request.getParameter("show_warnings"), "0"));
163   
164    // Recent items tab
165    int newMaxUsed = Values.getInt(request.getParameter("maxUsed"), 4);
166    sc.setUserClientSetting("appearance.recent", Integer.toString(newMaxUsed));
167    sc.setSessionSetting("appearance.recent", newMaxUsed);
168    int newMaxViewed = Values.getInt(request.getParameter("maxViewed"), 6);
169    sc.setUserClientSetting("menu.mostRecent.maxViewed", Integer.toString(newMaxViewed));
170    sc.setUserClientSetting("menu.mostRecent.loadNames", Values.getString(request.getParameter("loadNames"), "0"));
171
172    String[] stickyItems = request.getParameterValues("sticky_items");
173    sc.setUserClientSetting("menu.mostRecent", 
174      stickyItems == null ? "" : Values.getString(Arrays.asList(stickyItems), ":", true));
175   
176    // Roles tab
177    String[] inactiveRoles = request.getParameterValues("inactiveRoles");
178    sc.setUserClientSetting("inactiveRoles", inactiveRoles == null ? null : Values.getString(Arrays.asList(inactiveRoles), ":", true));
179   
180    message = "Preferences saved";
181  }
182  else if ("ReloadPermissions".equals(cmd))
183  {
184    sc.reloadPermissions();
185    sc.reloadSettings(true, false);
186    sc.setSessionSetting("menu.standard.html", null);
187    message = "Permissions reloaded";
188  }
189  else if ("ResetFilters".equals(cmd))
190  {
191    boolean inDatabase = Values.getBoolean(request.getParameter("database"));
192    String itemType = Values.getStringOrNull(request.getParameter("item_type"));
193    Item item = itemType == null ? null : Item.valueOf(itemType);
194    int numDeleted = sc.deleteCurrentContexts(item, true, inDatabase);
195    message = numDeleted + " list settings deleted";
196  }
197  else
198  {
199    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
200  }
201}
202finally
203{
204  if (dc != null) dc.close();
205}
206response.sendRedirect(root + "common/close_popup.jsp?ID="+ID+"&refresh_opener=1&&message="+HTML.urlEncode(message));
207%>
208
Note: See TracBrowser for help on using the repository browser.