source: branches/3.19-stable/www/switch.jsp @ 8036

Last change on this file since 8036 was 8036, checked in by Nicklas Nordborg, 10 months ago

References #2278: Improvements to login page for better extensions

Added support for dynamic attributes to the LoginFormBean and FieldInfo classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.0 KB
Line 
1<%-- $Id: switch.jsp 8036 2022-05-25 06:31:55Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006, 2007 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.Application"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.News"
30  import="net.sf.basedb.core.ItemQuery"
31  import="net.sf.basedb.core.ItemResultList"
32  import="net.sf.basedb.core.query.Orders"
33  import="net.sf.basedb.core.query.Hql"
34  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
35  import="net.sf.basedb.util.extensions.ActionIterator"
36  import="net.sf.basedb.clients.web.Base"
37  import="net.sf.basedb.clients.web.util.HTML"
38  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
39  import="net.sf.basedb.clients.web.extensions.JspContext"
40  import="net.sf.basedb.clients.web.extensions.DynamicActionAttributeSupport"
41  import="net.sf.basedb.clients.web.extensions.login.LoginFormAction"
42  import="net.sf.basedb.clients.web.extensions.login.PasswordLoginFormFactory"
43  import="net.sf.basedb.clients.web.extensions.login.FieldInfo"
44  import="net.sf.basedb.util.Values"
45  import="java.util.Map"
46  import="java.util.TreeMap"
47%>
48<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
49<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
50<%! 
51// If value is null, return "", else <prefix>+<value>+<suffix>
52String valueIfNotNull(String prefix, String value, String suffix)
53{
54  return value == null ? "" : prefix+value+suffix;
55}
56%>
57<%
58final String login = Values.getString(request.getParameter("login"), "");
59final String requestedLoginForm = Values.getString(request.getParameter("loginForm"), null);
60
61final SessionControl sc = Base.getSessionControl(pageContext, true);
62final String ID = sc.getId();
63final DbControl dc = sc.newDbControl(":Switch user");
64try
65{
66  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
67  ExtensionsInvoker<LoginFormAction> invoker = ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form");
68
69  LoginFormAction loginAction = null;
70  String selectedLoginForm = null;
71  Map<String, String> allForms = new TreeMap<String, String>();
72
73  ActionIterator<LoginFormAction> it = invoker.iterate();
74  while (it.hasNext())
75  {
76    LoginFormAction action = it.next();
77    if (action != null)
78    {
79      String formId = action.getId();
80      if (formId == null) formId = it.getExtension().getId();
81      String displayName = action.getDisplayName();
82      if (displayName == null) displayName = it.getExtension().getAbout().getName();
83      allForms.put(formId, displayName);
84     
85      if (loginAction == null || formId.equals(requestedLoginForm))
86      {
87        loginAction = action;
88        selectedLoginForm = formId;
89      }
90    }
91  }
92  if (loginAction == null)
93  {
94    loginAction = PasswordLoginFormFactory.INSTANCE;
95    selectedLoginForm = loginAction.getId();
96  }
97  FieldInfo loginField = loginAction.getLoginField();
98  FieldInfo passwordField = loginAction.getPasswordField();
99  FieldInfo extraField = loginAction.getExtraField();
100  %>
101  <base:page type="popup" title="Switch user">
102  <base:head styles="login.css" scripts="~login.js">
103    <ext:scripts context="<%=jspContext%>" />
104    <ext:stylesheets context="<%=jspContext%>" />
105  </base:head>
106  <base:body data-login-form="<%=HTML.encodeTags(selectedLoginForm)%>" data-requested-form="<%=HTML.encodeTags(requestedLoginForm) %>">
107    <h1>Switch user <base:help helpid="switchuser" /></h1>
108    <form name="login" action="login.jsp" method="post"
109      <%=DynamicActionAttributeSupport.getAttributesString(loginAction)%>
110    >
111    <input type="hidden" name="ID" value="<%=ID%>">
112    <input type="hidden" name="again" value="1">
113    <input type="hidden" name="redirect" value="">
114    <input type="hidden" name="useAutoStartPage" value="0">
115    <input type="hidden" name="deviceToken" value="">
116 
117    <div class="content">
118      <table class="fullform input100 bottomborder" id="the-login-form" style="display: none;">
119      <%
120      if (allForms.size() > 1)
121      {
122        %>
123        <tr>
124          <th>Login with</th>
125          <td>
126          <select name="loginForm" id="loginForm" style="min-width: 10em;">
127          <%
128          for (Map.Entry<String, String> entry : allForms.entrySet())
129          {
130            String formId = entry.getKey();
131            %>
132            <option value="<%=formId%>" <%=formId.equals(selectedLoginForm) ? "selected" : ""%>><%=HTML.encodeTags(entry.getValue()) %>
133            <%
134          }
135          %>
136          </select>
137          </td>
138        </tr>
139        <%
140      }
141      %>
142      <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
143        <th><%=loginField.getPrompt() %></th>
144        <td><input class="text" name="login" id="login"
145          type="<%=loginField.hasHiddenCharacters() ? "password" : "text"%>"
146          value="<%=loginAction.rememberLastLogin() ? HTML.encodeTags(login) : ""%>" 
147          <%=valueIfNotNull("style=\"", loginField.getStyle(), "\"") %>
148          <%=valueIfNotNull("title=\"", loginField.getTooltip(), "\"") %>
149          <%=valueIfNotNull("placeholder=\"", loginField.getPlaceHolder(), "\"") %>
150          <%=loginAction.rememberLastLogin() ? "" : "autocomplete=\"off\""%>
151          data-use-last-login="0"
152          maxlength="100" 
153          tabindex="0"
154          <%=DynamicActionAttributeSupport.getAttributesString(loginField)%>
155          >
156        </td>
157      </tr>
158      <tr <%=valueIfNotNull("class=\"", passwordField.getClazz(), "\"")%> id="password-row">
159        <th><%=passwordField.getPrompt() %></th>
160        <td><input class="text" name="password" id="password"
161          type="<%=passwordField.hasHiddenCharacters() ? "password" : "text"%>"
162          <%=valueIfNotNull("style=\"", passwordField.getStyle(), "\"") %>
163          <%=valueIfNotNull("title=\"", passwordField.getTooltip(), "\"") %>
164          <%=valueIfNotNull("placeholder=\"", passwordField.getPlaceHolder(), "\"") %>
165          maxlength="80"
166          tabindex="0"
167          <%=DynamicActionAttributeSupport.getAttributesString(passwordField)%>
168          >
169        </td>
170      </tr>
171      <%
172      if (extraField != null)
173      {
174        %>
175        <tr <%=valueIfNotNull("class=\"", extraField.getClazz(), "\"")%> id="extra-row">
176          <th><%=extraField.getPrompt() %></th>
177          <td><input class="text" name="extraField" id="extraField"
178            type="<%=extraField.hasHiddenCharacters() ? "password" : "text"%>"
179            <%=valueIfNotNull("style=\"", extraField.getStyle(), "\"") %>
180            <%=valueIfNotNull("title=\"", extraField.getTooltip(), "\"") %>
181            <%=valueIfNotNull("placeholder=\"", extraField.getPlaceHolder(), "\"") %>
182            maxlength="80"
183            tabindex="0"
184            <%=DynamicActionAttributeSupport.getAttributesString(extraField)%>
185            >
186          </td>
187        </tr>
188        <%
189      }
190      %>
191      <tr>
192        <th><label for="remainOnPage">Remain on this page</label></th>
193        <td><input type="checkbox" name="remainOnPage" id="remainOnPage" checked value="1"></td>
194      </tr>
195      <%
196      if (loginAction.getHelp() != null)
197      {
198        %>
199        <tr class="dynamic bg-filled-50 topborder">
200          <td colspan="2">
201          <div class="padded">
202            <div class="messagecontainer help" style="font-style: italic;" id="login-help">
203            <%=loginAction.getHelp() %>
204            </div>
205          </div>
206          </td>
207        </tr>
208        <%
209      }
210      else
211      {
212        %>
213        <tr class="dynamic">
214          <th></th>
215          <td></td>
216        </tr>
217        <%
218      }
219      %>
220      </table>
221     
222    </div>
223    </form>
224   
225    <base:buttongroup subclass="dialogbuttons">
226      <base:button id="btnLogin" image="login.png" title="Login" />
227      <base:button id="close" title="Cancel" />
228    </base:buttongroup>
229
230  </base:body>
231  </base:page>
232  <%
233}
234finally
235{
236  if (dc != null) dc.close();
237}
238%>
239
Note: See TracBrowser for help on using the repository browser.