source: trunk/www/switch.jsp @ 7500

Last change on this file since 7500 was 7500, checked in by Nicklas Nordborg, 3 years ago

References #2124: Add support for a third field in the login form

Added an extra field getExtraField() to the LoginFormAction interface. A default implementation should provide backwards compatibility to existing implementations.

The login forms have been updated to display the extra field if it is present. The entered value is added to the LoginRequest as an attribute with name extraValue.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 6.4 KB
Line 
1<%-- $Id: switch.jsp 7500 2018-08-08 10:57:12Z 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.clients.web.Base"
36  import="net.sf.basedb.clients.web.util.HTML"
37  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
38  import="net.sf.basedb.clients.web.extensions.JspContext"
39  import="net.sf.basedb.clients.web.extensions.login.LoginFormAction"
40  import="net.sf.basedb.clients.web.extensions.login.LoginFormBean"
41  import="net.sf.basedb.clients.web.extensions.login.FieldInfo"
42  import="net.sf.basedb.util.Values"
43%>
44<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
45<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
46<%! 
47// If value is null, return "", else <prefix>+<value>+<suffix>
48String valueIfNotNull(String prefix, String value, String suffix)
49{
50  return value == null ? "" : prefix+value+suffix;
51}
52%>
53<%
54final String login = Values.getString(request.getParameter("login"), "");
55
56final SessionControl sc = Base.getSessionControl(pageContext, true);
57final String ID = sc.getId();
58final DbControl dc = sc.newDbControl();
59try
60{
61  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
62  ExtensionsInvoker<LoginFormAction> invoker = (ExtensionsInvoker<LoginFormAction>)ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form");
63  LoginFormAction loginAction = null;
64  for (LoginFormAction action : invoker)
65  {
66    if (action != null)
67    {
68      loginAction = action;
69      break;
70    }
71  }
72  if (loginAction == null)
73  {
74    LoginFormBean bean  = new LoginFormBean();
75    bean.setRememberLastLogin(true);
76    bean.setLoginField(FieldInfo.DEFAULT_LOGIN);
77    bean.setPasswordField(FieldInfo.DEFAULT_PASSWORD);
78    loginAction = bean;
79  }
80  FieldInfo loginField = loginAction.getLoginField();
81  FieldInfo passwordField = loginAction.getPasswordField();
82  FieldInfo extraField = loginAction.getExtraField();
83  %>
84  <base:page type="popup" title="Switch user">
85  <base:head styles="login.css" scripts="~login.js">
86    <ext:scripts context="<%=jspContext%>" />
87    <ext:stylesheets context="<%=jspContext%>" />
88  </base:head>
89  <base:body>
90    <h1>Switch user <base:help helpid="switchuser" /></h1>
91    <form name="login" action="login.jsp" method="post">
92    <input type="hidden" name="ID" value="<%=ID%>">
93    <input type="hidden" name="again" value="1">
94    <input type="hidden" name="redirect" value="">
95    <input type="hidden" name="useAutoStartPage" value="0">
96    <input type="hidden" name="deviceToken" value="">
97 
98    <div class="content">
99      <table class="fullform input100 bottomborder ">
100      <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
101        <th><%=loginField.getPrompt() %></th>
102        <td><input class="text" name="login" id="login"
103          type="<%=loginField.hasHiddenCharacters() ? "password" : "text"%>"
104          value="<%=loginAction.rememberLastLogin() ? HTML.encodeTags(login) : ""%>" 
105          <%=valueIfNotNull("style=\"", loginField.getStyle(), "\"") %>
106          <%=valueIfNotNull("title=\"", loginField.getTooltip(), "\"") %>
107          <%=valueIfNotNull("placeholder=\"", loginField.getPlaceHolder(), "\"") %>
108          <%=loginAction.rememberLastLogin() ? "" : "autocomplete=\"off\""%>
109          data-use-last-login="0"
110          maxlength="100" 
111          tabindex="0">
112        </td>
113      </tr>
114      <tr <%=valueIfNotNull("class=\"", passwordField.getClazz(), "\"")%> id="password-row">
115        <th><%=passwordField.getPrompt() %></th>
116        <td><input class="text" name="password" id="password"
117          type="<%=passwordField.hasHiddenCharacters() ? "password" : "text"%>"
118          <%=valueIfNotNull("style=\"", passwordField.getStyle(), "\"") %>
119          <%=valueIfNotNull("title=\"", passwordField.getTooltip(), "\"") %>
120          <%=valueIfNotNull("placeholder=\"", passwordField.getPlaceHolder(), "\"") %>
121          maxlength="80"
122          tabindex="0">
123        </td>
124      </tr>
125      <%
126      if (extraField != null)
127      {
128        %>
129        <tr <%=valueIfNotNull("class=\"", extraField.getClazz(), "\"")%> id="extra-row">
130          <th><%=extraField.getPrompt() %></th>
131          <td><input class="text" name="extraField" id="extraField"
132            type="<%=extraField.hasHiddenCharacters() ? "password" : "text"%>"
133            <%=valueIfNotNull("style=\"", extraField.getStyle(), "\"") %>
134            <%=valueIfNotNull("title=\"", extraField.getTooltip(), "\"") %>
135            <%=valueIfNotNull("placeholder=\"", extraField.getPlaceHolder(), "\"") %>
136            maxlength="80"
137            tabindex="0">
138          </td>
139        </tr>
140        <%
141      }
142      %>
143      <tr>
144        <th><label for="remainOnPage">Remain on this page</label></th>
145        <td><input type="checkbox" name="remainOnPage" id="remainOnPage" checked value="1"></td>
146      </tr>
147      <%
148      if (loginAction.getHelp() != null)
149      {
150        %>
151        <tr class="dynamic bg-filled-50 topborder">
152          <td colspan="2">
153          <div class="padded">
154            <div class="messagecontainer help" style="font-style: italic;" id="login-help">
155            <%=loginAction.getHelp() %>
156            </div>
157          </div>
158          </td>
159        </tr>
160        <%
161      }
162      else
163      {
164        %>
165        <tr class="dynamic">
166          <th></th>
167          <td></td>
168        </tr>
169        <%
170      }
171      %>
172      </table>
173     
174    </div>
175    </form>
176   
177    <base:buttongroup subclass="dialogbuttons">
178      <base:button id="btnLogin" image="login.png" title="Login" />
179      <base:button id="close" title="Cancel" />
180    </base:buttongroup>
181
182  </base:body>
183  </base:page>
184  <%
185}
186finally
187{
188  if (dc != null) dc.close();
189}
190%>
191
Note: See TracBrowser for help on using the repository browser.