source: trunk/www/switch.jsp @ 7531

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

References #2131: Add support for installing multiple authentication managers

The "Switch user" dialog should now work with multiple login forms.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 7.8 KB
Line 
1<%-- $Id: switch.jsp 7531 2018-11-26 12:06:20Z 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.login.LoginFormAction"
41  import="net.sf.basedb.clients.web.extensions.login.LoginFormBean"
42  import="net.sf.basedb.clients.web.extensions.login.FieldInfo"
43  import="net.sf.basedb.util.Values"
44  import="java.util.Map"
45  import="java.util.TreeMap"
46%>
47<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
48<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
49<%! 
50// If value is null, return "", else <prefix>+<value>+<suffix>
51String valueIfNotNull(String prefix, String value, String suffix)
52{
53  return value == null ? "" : prefix+value+suffix;
54}
55%>
56<%
57final String login = Values.getString(request.getParameter("login"), "");
58final String requestedLoginForm = Values.getString(request.getParameter("loginForm"), null);
59
60final SessionControl sc = Base.getSessionControl(pageContext, true);
61final String ID = sc.getId();
62final DbControl dc = sc.newDbControl();
63try
64{
65  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
66  ExtensionsInvoker<LoginFormAction> invoker = (ExtensionsInvoker<LoginFormAction>)ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form");
67
68  LoginFormAction loginAction = null;
69  String selectedLoginForm = null;
70  Map<String, String> allForms = new TreeMap<String, String>();
71
72  ActionIterator<LoginFormAction> it = invoker.iterate();
73  while (it.hasNext())
74  {
75    LoginFormAction action = it.next();
76    if (action != null)
77    {
78      String formId = action.getId();
79      if (formId == null) formId = it.getExtension().getId();
80      String displayName = action.getDisplayName();
81      if (displayName == null) displayName = it.getExtension().getAbout().getName();
82      allForms.put(formId, displayName);
83     
84      if (loginAction == null || formId.equals(requestedLoginForm))
85      {
86        loginAction = action;
87        selectedLoginForm = formId;
88      }
89    }
90  }
91  if (loginAction == null)
92  {
93    LoginFormBean bean  = new LoginFormBean();
94    bean.setRememberLastLogin(true);
95    bean.setLoginField(FieldInfo.DEFAULT_LOGIN);
96    bean.setPasswordField(FieldInfo.DEFAULT_PASSWORD);
97    loginAction = bean;
98    selectedLoginForm = "password";
99  }
100  FieldInfo loginField = loginAction.getLoginField();
101  FieldInfo passwordField = loginAction.getPasswordField();
102  FieldInfo extraField = loginAction.getExtraField();
103  %>
104  <base:page type="popup" title="Switch user">
105  <base:head styles="login.css" scripts="~login.js">
106    <ext:scripts context="<%=jspContext%>" />
107    <ext:stylesheets context="<%=jspContext%>" />
108  </base:head>
109  <base:body data-login-form="<%=HTML.encodeTags(selectedLoginForm)%>" data-requested-form="<%=HTML.encodeTags(requestedLoginForm) %>">
110    <h1>Switch user <base:help helpid="switchuser" /></h1>
111    <form name="login" action="login.jsp" method="post">
112    <input type="hidden" name="ID" value="<%=ID%>">
113    <input type="hidden" name="again" value="1">
114    <input type="hidden" name="redirect" value="">
115    <input type="hidden" name="useAutoStartPage" value="0">
116    <input type="hidden" name="deviceToken" value="">
117 
118    <div class="content">
119      <table class="fullform input100 bottomborder ">
120      <%
121      if (allForms.size() > 0)
122      {
123        %>
124        <tr>
125          <th>Login with</th>
126          <td>
127          <select name="loginForm" id="loginForm" style="min-width: 10em;">
128          <%
129          for (Map.Entry<String, String> entry : allForms.entrySet())
130          {
131            String formId = entry.getKey();
132            %>
133            <option value="<%=formId%>" <%=formId.equals(selectedLoginForm) ? "selected" : ""%>><%=HTML.encodeTags(entry.getValue()) %>
134            <%
135          }
136          %>
137          </select>
138          </td>
139        </tr>
140        <%
141      }
142      %>
143      <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
144        <th><%=loginField.getPrompt() %></th>
145        <td><input class="text" name="login" id="login"
146          type="<%=loginField.hasHiddenCharacters() ? "password" : "text"%>"
147          value="<%=loginAction.rememberLastLogin() ? HTML.encodeTags(login) : ""%>" 
148          <%=valueIfNotNull("style=\"", loginField.getStyle(), "\"") %>
149          <%=valueIfNotNull("title=\"", loginField.getTooltip(), "\"") %>
150          <%=valueIfNotNull("placeholder=\"", loginField.getPlaceHolder(), "\"") %>
151          <%=loginAction.rememberLastLogin() ? "" : "autocomplete=\"off\""%>
152          data-use-last-login="0"
153          maxlength="100" 
154          tabindex="0">
155        </td>
156      </tr>
157      <tr <%=valueIfNotNull("class=\"", passwordField.getClazz(), "\"")%> id="password-row">
158        <th><%=passwordField.getPrompt() %></th>
159        <td><input class="text" name="password" id="password"
160          type="<%=passwordField.hasHiddenCharacters() ? "password" : "text"%>"
161          <%=valueIfNotNull("style=\"", passwordField.getStyle(), "\"") %>
162          <%=valueIfNotNull("title=\"", passwordField.getTooltip(), "\"") %>
163          <%=valueIfNotNull("placeholder=\"", passwordField.getPlaceHolder(), "\"") %>
164          maxlength="80"
165          tabindex="0">
166        </td>
167      </tr>
168      <%
169      if (extraField != null)
170      {
171        %>
172        <tr <%=valueIfNotNull("class=\"", extraField.getClazz(), "\"")%> id="extra-row">
173          <th><%=extraField.getPrompt() %></th>
174          <td><input class="text" name="extraField" id="extraField"
175            type="<%=extraField.hasHiddenCharacters() ? "password" : "text"%>"
176            <%=valueIfNotNull("style=\"", extraField.getStyle(), "\"") %>
177            <%=valueIfNotNull("title=\"", extraField.getTooltip(), "\"") %>
178            <%=valueIfNotNull("placeholder=\"", extraField.getPlaceHolder(), "\"") %>
179            maxlength="80"
180            tabindex="0">
181          </td>
182        </tr>
183        <%
184      }
185      %>
186      <tr>
187        <th><label for="remainOnPage">Remain on this page</label></th>
188        <td><input type="checkbox" name="remainOnPage" id="remainOnPage" checked value="1"></td>
189      </tr>
190      <%
191      if (loginAction.getHelp() != null)
192      {
193        %>
194        <tr class="dynamic bg-filled-50 topborder">
195          <td colspan="2">
196          <div class="padded">
197            <div class="messagecontainer help" style="font-style: italic;" id="login-help">
198            <%=loginAction.getHelp() %>
199            </div>
200          </div>
201          </td>
202        </tr>
203        <%
204      }
205      else
206      {
207        %>
208        <tr class="dynamic">
209          <th></th>
210          <td></td>
211        </tr>
212        <%
213      }
214      %>
215      </table>
216     
217    </div>
218    </form>
219   
220    <base:buttongroup subclass="dialogbuttons">
221      <base:button id="btnLogin" image="login.png" title="Login" />
222      <base:button id="close" title="Cancel" />
223    </base:buttongroup>
224
225  </base:body>
226  </base:page>
227  <%
228}
229finally
230{
231  if (dc != null) dc.close();
232}
233%>
234
Note: See TracBrowser for help on using the repository browser.