source: trunk/www/main.jsp @ 7536

Last change on this file since 7536 was 7536, checked in by Nicklas Nordborg, 4 years ago

References #2131: Add support for installing multiple authentication managers

Added an "external" version of the default username+password login form. This is is disabled by default but need to be used when another external authentication manager has been installed and some users still need to be able to login with username+password.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.2 KB
Line 
1<%-- $Id: main.jsp 7536 2018-11-28 07:49:22Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
5  Copyright (C) 2007 Nicklas Nordborg
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 is the front page of BASE. It displays a login form
25  and some of the relevant news items.
26
27  @param login The value to display in the login input field.
28  @param error An error message that should be displayed
29
30  @author Nicklas
31  @version 2.0
32--%>
33<%@ page pageEncoding="UTF-8" session="false"
34  import="net.sf.basedb.core.Application"
35  import="net.sf.basedb.core.SessionControl"
36  import="net.sf.basedb.core.DbControl"
37  import="net.sf.basedb.core.News"
38  import="net.sf.basedb.core.ItemQuery"
39  import="net.sf.basedb.core.ItemResultIterator"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
43  import="net.sf.basedb.util.extensions.ActionIterator"
44  import="net.sf.basedb.clients.web.Base"
45  import="net.sf.basedb.clients.web.util.HTML"
46  import="net.sf.basedb.util.formatter.Formatter"
47  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
48  import="net.sf.basedb.clients.web.extensions.JspContext"
49  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
50  import="net.sf.basedb.clients.web.servlet.RssNewsFeed"
51  import="net.sf.basedb.clients.web.extensions.login.LoginFormAction"
52  import="net.sf.basedb.clients.web.extensions.login.FieldInfo"
53  import="net.sf.basedb.clients.web.extensions.login.PasswordLoginFormFactory"
54  import="net.sf.basedb.util.Values"
55  import="java.util.Date"
56  import="java.util.Map"
57  import="java.util.TreeMap"
58%>
59<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
60<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
61<%! 
62// If value is null, return "", else <prefix>+<value>+<suffix>
63String valueIfNotNull(String prefix, String value, String suffix)
64{
65  return value == null ? "" : prefix+value+suffix;
66}
67%>
68<%
69final String login = Values.getString(request.getParameter("login"), "");
70final String error = Values.getString(request.getParameter("error"), null);
71final String requestedLoginForm = Values.getString(request.getParameter("loginForm"), null);
72final String root = request.getContextPath()+"/";
73
74final SessionControl sc = Base.getSessionControl(pageContext, true);
75final String ID = sc.getId();
76final Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
77final DbControl dc = sc.newDbControl();
78
79try
80{
81  String broadcastTitle = (String)application.getAttribute("broadcast.title");
82  String broadcastMessage = (String)application.getAttribute("broadcast.message");
83  boolean denyLogin = Boolean.TRUE.equals(application.getAttribute("broadcast.deny-login"));
84  ItemResultIterator<News> news = null;
85  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
86  ExtensionsInvoker<LoginFormAction> invoker = (ExtensionsInvoker<LoginFormAction>)ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form");
87
88  LoginFormAction loginAction = null;
89  String selectedLoginForm = null;
90  Map<String, String> allForms = new TreeMap<String, String>();
91 
92  ActionIterator<LoginFormAction> it = invoker.iterate();
93  while (it.hasNext())
94  {
95    LoginFormAction action = it.next();
96    if (action != null)
97    {
98      String formId = action.getId();
99      if (formId == null) formId = it.getExtension().getId();
100      String displayName = action.getDisplayName();
101      if (displayName == null) displayName = it.getExtension().getAbout().getName();
102      allForms.put(formId, displayName);
103     
104      if (loginAction == null || formId.equals(requestedLoginForm))
105      {
106        loginAction = action;
107        selectedLoginForm = formId;
108      }
109    }
110  }
111  if (loginAction == null)
112  {
113    loginAction = PasswordLoginFormFactory.INSTANCE;
114    selectedLoginForm = loginAction.getId();
115  }
116
117  FieldInfo loginField = loginAction.getLoginField();
118  FieldInfo passwordField = loginAction.getPasswordField();
119  FieldInfo extraField = loginAction.getExtraField();
120  %>
121  <base:page type="default">
122  <base:head styles="login.css" scripts="exception.js,~login.js">
123    <ext:scripts context="<%=jspContext%>" />
124    <ext:stylesheets context="<%=jspContext%>" />
125  </base:head>
126  <base:body style="padding-top: 5em;" data-login-form="<%=HTML.encodeTags(selectedLoginForm)%>" data-requested-form="<%=HTML.encodeTags(requestedLoginForm) %>">
127    <form name="login" action="login.jsp" method="post">
128    <input type="hidden" name="ID" value="<%=ID%>">
129    <input type="hidden" name="useAutoStartPage" value="1">
130    <input type="hidden" name="deviceToken" value="">
131   
132    <table style="margin: auto; width: 700px;">
133    <tr>
134    <td>
135      <%
136      if (loginAction.getHelp() != null)
137      {
138        %>
139        <div class="messagecontainer help" style="margin-bottom: 1em; font-style: italic;" id="login-help">
140        <%=loginAction.getHelp() %>
141        </div>
142        <%
143      }
144      if (error != null) 
145      {
146        %>
147        <div class="messagecontainer error" style="margin-top: 1em; margin-bottom: 1em;"><%=error%></div>
148        <%
149      }
150      if (allForms.size() > 1)
151      {
152        %>
153        <div style="text-align: right; margin-bottom: 0.25em;">
154          <b>Login with</b>
155          <select name="loginForm" id="loginForm" style="min-width: 10em;">
156          <%
157          for (Map.Entry<String, String> entry : allForms.entrySet())
158          {
159            String formId = entry.getKey();
160            %>
161            <option value="<%=formId%>" <%=formId.equals(selectedLoginForm) ? "selected" : ""%>><%=HTML.encodeTags(entry.getValue()) %>
162            <%
163          }
164          %>
165          </select>
166        </div>
167        <%
168      }
169      else if (selectedLoginForm != null)
170      {
171        %>
172        <input type="hidden" name="loginForm" value="<%=selectedLoginForm%>">
173        <%
174      }
175      %>
176      <table style="width: 100%; border-collapse: separate;">
177      <tr>
178        <td class="base-logo"><img src="images/baselogo.png" alt="BASE logo"></td>
179        <td style="width: 515px;">
180          <div id="loginform">
181          <table style="width: 100%;">
182            <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
183              <th class="bg-filled-100"><%=loginField.getPrompt() %></th>
184              <td colspan="2"><input class="text" name="login" id="login"
185                type="<%=loginField.hasHiddenCharacters() ? "password" : "text"%>"
186                value="<%=loginAction.rememberLastLogin() ? HTML.encodeTags(login) : ""%>" 
187                <%=denyLogin ? "disabled" : ""%>
188                <%=valueIfNotNull("style=\"", loginField.getStyle(), "\"") %>
189                <%=valueIfNotNull("title=\"", loginField.getTooltip(), "\"") %>
190                <%=valueIfNotNull("placeholder=\"", loginField.getPlaceHolder(), "\"") %>
191                <%=loginAction.rememberLastLogin() ? "" : "autocomplete=\"off\" data-use-last-login=\"0\""%>
192                maxlength="100" 
193                tabindex="1">
194              </td>
195            </tr>
196            <tr <%=valueIfNotNull("class=\"", passwordField.getClazz(), "\"")%> id="password-row">
197              <th class="bg-filled-100"><%=passwordField.getPrompt() %></th>
198              <td><input class="text" name="password" id="password"
199                type="<%=passwordField.hasHiddenCharacters() ? "password" : "text"%>"
200                <%=denyLogin ? "disabled" : ""%>
201                <%=valueIfNotNull("style=\"", passwordField.getStyle(), "\"") %>
202                <%=valueIfNotNull("title=\"", passwordField.getTooltip(), "\"") %>
203                <%=valueIfNotNull("placeholder=\"", passwordField.getPlaceHolder(), "\"") %>
204                maxlength="80"
205                tabindex="2">
206              </td>
207              <td <%=extraField != null?"rowspan=\"2\"" : "" %> style="vertical-align: bottom;"><base:button 
208                id="btnLogin"
209                subclass="<%=denyLogin ? "disabled" : ""%>"
210                image="login.png" title="Login" 
211                tooltip="<%=HTML.encodeTags(broadcastTitle)%>" tabindex="4" /></td>
212            </tr>
213            <%
214            if (extraField != null)
215            {
216              %>
217              <tr <%=valueIfNotNull("class=\"", extraField.getClazz(), "\"")%> id="extra-row">
218                <th class="bg-filled-100"><%=extraField.getPrompt() %></th>
219                <td><input class="text" name="extraField" id="extraField"
220                  type="<%=extraField.hasHiddenCharacters() ? "password" : "text"%>"
221                  <%=denyLogin ? "disabled" : ""%>
222                  <%=valueIfNotNull("style=\"", extraField.getStyle(), "\"") %>
223                  <%=valueIfNotNull("title=\"", extraField.getTooltip(), "\"") %>
224                  <%=valueIfNotNull("placeholder=\"", extraField.getPlaceHolder(), "\"") %>
225                  maxlength="80"
226                  tabindex="3">
227                </td>
228              </tr>
229              <%
230            }
231            %>
232            <tr>
233              <th class="bg-filled-100 subprompt"></th>
234              <td colspan="2">
235              <%
236              String forgotPassword = sc.getClientDefaultSetting("server.forgotten.password");
237              String getAccount = sc.getClientDefaultSetting("server.get.account");
238              if (forgotPassword != null)
239              {
240                %>
241                <base:icon id="forgotPassword" image="bullet.png" 
242                  tooltip="Click here if you have forgotten your password">Forgot your password?</base:icon>
243                <%
244              }
245              if (getAccount != null)
246              {
247                %>
248                <base:icon id="getAccount" image="bullet.png" 
249                  tooltip="Click here if you want to get an account on this server">Get an account!</base:icon>
250                <%
251              }
252              %>
253              </td>
254            </tr>
255            </table>
256          </div>
257        </td>
258      </tr>
259      </table>
260      <%
261      if (denyLogin)
262      {
263        %>
264        <div class="messagecontainer help" id="denyLogin">
265          <b><%=HTML.encodeTags(broadcastTitle) %> (login disabled)</b><br>
266          <%=HTML.niceFormat(broadcastMessage)%>
267          <base:buttongroup style="margin-top: 1em;">
268            <base:button id="btnLoginAnyway" title="Login anyway" image="login.png" tooltip="At your own risk!" />
269          </base:buttongroup>
270        </div>
271        <%
272      }
273      %>
274      <%
275      String aboutServer = sc.getClientDefaultSetting("server.about");
276      if (aboutServer != null)
277      {
278        %>
279        <h3 style="margin-top: 1em;">About this server</h3>
280        <p>
281          <%=aboutServer%>
282        </p>
283        <base:icon id="aboutServer" image="bullet.png">More about this server</base:icon>
284        <%
285      }
286      %>
287     
288      <h3 style="margin-top: 1em;">News and announcements
289      <%
290      if (RssNewsFeed.isEnabled()) 
291      {
292        %>
293        <a href="info/news.rss" 
294          title="Subscribe to news from this BASE server"
295          ><base:icon image="rss.png" style="float: right;" /></a>
296        <%
297      }
298      %>
299      </h3>
300      <div id="news" class="news">
301      <%
302      if (broadcastTitle != null)
303      {
304        %>
305        <div class="item note sticky">
306          <div class="headline">
307            <span class="date"><%=dateFormatter.format(new Date())%></span>
308            <%=HTML.encodeTags(broadcastTitle)%><%=denyLogin ? " (login disabled)" : "" %>
309          </div>
310          <div class="text"><%=HTML.niceFormat(broadcastMessage)%></div>
311        </div>
312        <% 
313      }
314     
315      ItemQuery<News> query = News.getQuery();
316      query.order(Orders.desc(Hql.property("sticky")));
317      query.order(Orders.desc(Hql.property("newsDate")));
318      query.order(Orders.desc(Hql.property("id")));
319      query.setCacheResult(true);
320      query.setReturnTotalCount(true);
321      news = query.iterate(dc);
322      int numListed = 0;
323      while (news.hasNext())
324      {
325        News n = news.next();
326        if (numListed >= 10 && !n.isSticky()) break;
327        %>
328        <div class="item <%=n.isSticky() ? "note sticky" : ""%>">
329          <div class="headline">
330            <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
331            <%=HTML.encodeTags(n.getName())%>
332          </div>
333          <div class="text"><%=HTML.niceFormat(n.getDescription())%></div>
334        </div>
335        <%
336        numListed++;
337      }
338      if (numListed < news.getTotalCount())
339      {
340        %>
341        <base:icon image="bullet.png" /><a href="info/news.jsp" 
342          title="Show older news..."><%=news.getTotalCount()-numListed%> more</a>
343        <%
344      }
345      %>
346      </div>
347    </td>
348    </tr>
349    </table>
350
351    </form>
352  </base:body>
353  </base:page>
354  <%
355}
356finally
357{
358  if (dc != null) dc.close();
359}
360%>
361
Note: See TracBrowser for help on using the repository browser.