source: trunk/www/main.jsp @ 7530

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

References #2131: Add support for installing multiple authentication managers

The most recently used login form should now be remembered and automatically loaded the next time.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 12.3 KB
Line 
1<%-- $Id: main.jsp 7530 2018-11-26 11:40:55Z 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.LoginFormBean"
53  import="net.sf.basedb.clients.web.extensions.login.FieldInfo"
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    LoginFormBean bean  = new LoginFormBean();
114    bean.setRememberLastLogin(true);
115    bean.setLoginField(FieldInfo.DEFAULT_LOGIN);
116    bean.setPasswordField(FieldInfo.DEFAULT_PASSWORD);
117    loginAction = bean;
118    selectedLoginForm = "password";
119  }
120
121  FieldInfo loginField = loginAction.getLoginField();
122  FieldInfo passwordField = loginAction.getPasswordField();
123  FieldInfo extraField = loginAction.getExtraField();
124  %>
125  <base:page type="default">
126  <base:head styles="login.css" scripts="exception.js,~login.js">
127    <ext:scripts context="<%=jspContext%>" />
128    <ext:stylesheets context="<%=jspContext%>" />
129  </base:head>
130  <base:body style="padding-top: 5em;" data-login-form="<%=HTML.encodeTags(selectedLoginForm)%>" data-requested-form="<%=HTML.encodeTags(requestedLoginForm) %>">
131    <form name="login" action="login.jsp" method="post">
132    <input type="hidden" name="ID" value="<%=ID%>">
133    <input type="hidden" name="useAutoStartPage" value="1">
134    <input type="hidden" name="deviceToken" value="">
135   
136    <table style="margin: auto; width: 700px;">
137    <tr>
138    <td>
139      <%
140      if (loginAction.getHelp() != null)
141      {
142        %>
143        <div class="messagecontainer help" style="margin-bottom: 1em; font-style: italic;" id="login-help">
144        <%=loginAction.getHelp() %>
145        </div>
146        <%
147      }
148      if (error != null) 
149      {
150        %>
151        <div class="messagecontainer error" style="margin-top: 1em; margin-bottom: 1em;"><%=error%></div>
152        <%
153      }
154      if (allForms.size() > 1)
155      {
156        %>
157        <div style="text-align: right; margin-bottom: 0.25em;">
158          <b>Login with</b>
159          <select name="loginForm" id="loginForm" style="min-width: 10em;">
160          <%
161          for (Map.Entry<String, String> entry : allForms.entrySet())
162          {
163            String formId = entry.getKey();
164            %>
165            <option value="<%=formId%>" <%=formId.equals(selectedLoginForm) ? "selected" : ""%>><%=HTML.encodeTags(entry.getValue()) %>
166            <%
167          }
168          %>
169          </select>
170        </div>
171        <%
172      }
173      else if (selectedLoginForm != null)
174      {
175        %>
176        <input type="hidden" name="loginForm" value="<%=selectedLoginForm%>">
177        <%
178      }
179      %>
180      <table style="width: 100%; border-collapse: separate;">
181      <tr>
182        <td class="base-logo"><img src="images/baselogo.png" alt="BASE logo"></td>
183        <td style="width: 515px;">
184          <div id="loginform">
185          <table style="width: 100%;">
186            <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
187              <th class="bg-filled-100"><%=loginField.getPrompt() %></th>
188              <td colspan="2"><input class="text" name="login" id="login"
189                type="<%=loginField.hasHiddenCharacters() ? "password" : "text"%>"
190                value="<%=loginAction.rememberLastLogin() ? HTML.encodeTags(login) : ""%>" 
191                <%=denyLogin ? "disabled" : ""%>
192                <%=valueIfNotNull("style=\"", loginField.getStyle(), "\"") %>
193                <%=valueIfNotNull("title=\"", loginField.getTooltip(), "\"") %>
194                <%=valueIfNotNull("placeholder=\"", loginField.getPlaceHolder(), "\"") %>
195                <%=loginAction.rememberLastLogin() ? "" : "autocomplete=\"off\" data-use-last-login=\"0\""%>
196                maxlength="100" 
197                tabindex="1">
198              </td>
199            </tr>
200            <tr <%=valueIfNotNull("class=\"", passwordField.getClazz(), "\"")%> id="password-row">
201              <th class="bg-filled-100"><%=passwordField.getPrompt() %></th>
202              <td><input class="text" name="password" id="password"
203                type="<%=passwordField.hasHiddenCharacters() ? "password" : "text"%>"
204                <%=denyLogin ? "disabled" : ""%>
205                <%=valueIfNotNull("style=\"", passwordField.getStyle(), "\"") %>
206                <%=valueIfNotNull("title=\"", passwordField.getTooltip(), "\"") %>
207                <%=valueIfNotNull("placeholder=\"", passwordField.getPlaceHolder(), "\"") %>
208                maxlength="80"
209                tabindex="2">
210              </td>
211              <td <%=extraField != null?"rowspan=\"2\"" : "" %> style="vertical-align: bottom;"><base:button 
212                id="btnLogin"
213                subclass="<%=denyLogin ? "disabled" : ""%>"
214                image="login.png" title="Login" 
215                tooltip="<%=HTML.encodeTags(broadcastTitle)%>" tabindex="4" /></td>
216            </tr>
217            <%
218            if (extraField != null)
219            {
220              %>
221              <tr <%=valueIfNotNull("class=\"", extraField.getClazz(), "\"")%> id="extra-row">
222                <th class="bg-filled-100"><%=extraField.getPrompt() %></th>
223                <td><input class="text" name="extraField" id="extraField"
224                  type="<%=extraField.hasHiddenCharacters() ? "password" : "text"%>"
225                  <%=denyLogin ? "disabled" : ""%>
226                  <%=valueIfNotNull("style=\"", extraField.getStyle(), "\"") %>
227                  <%=valueIfNotNull("title=\"", extraField.getTooltip(), "\"") %>
228                  <%=valueIfNotNull("placeholder=\"", extraField.getPlaceHolder(), "\"") %>
229                  maxlength="80"
230                  tabindex="3">
231                </td>
232              </tr>
233              <%
234            }
235            %>
236            <tr>
237              <th class="bg-filled-100 subprompt"></th>
238              <td colspan="2">
239              <%
240              String forgotPassword = sc.getClientDefaultSetting("server.forgotten.password");
241              String getAccount = sc.getClientDefaultSetting("server.get.account");
242              if (forgotPassword != null)
243              {
244                %>
245                <base:icon id="forgotPassword" image="bullet.png" 
246                  tooltip="Click here if you have forgotten your password">Forgot your password?</base:icon>
247                <%
248              }
249              if (getAccount != null)
250              {
251                %>
252                <base:icon id="getAccount" image="bullet.png" 
253                  tooltip="Click here if you want to get an account on this server">Get an account!</base:icon>
254                <%
255              }
256              %>
257              </td>
258            </tr>
259            </table>
260          </div>
261        </td>
262      </tr>
263      </table>
264      <%
265      if (denyLogin)
266      {
267        %>
268        <div class="messagecontainer help" id="denyLogin">
269          <b><%=HTML.encodeTags(broadcastTitle) %> (login disabled)</b><br>
270          <%=HTML.niceFormat(broadcastMessage)%>
271          <base:buttongroup style="margin-top: 1em;">
272            <base:button id="btnLoginAnyway" title="Login anyway" image="login.png" tooltip="At your own risk!" />
273          </base:buttongroup>
274        </div>
275        <%
276      }
277      %>
278      <%
279      String aboutServer = sc.getClientDefaultSetting("server.about");
280      if (aboutServer != null)
281      {
282        %>
283        <h3 style="margin-top: 1em;">About this server</h3>
284        <p>
285          <%=aboutServer%>
286        </p>
287        <base:icon id="aboutServer" image="bullet.png">More about this server</base:icon>
288        <%
289      }
290      %>
291     
292      <h3 style="margin-top: 1em;">News and announcements
293      <%
294      if (RssNewsFeed.isEnabled()) 
295      {
296        %>
297        <a href="info/news.rss" 
298          title="Subscribe to news from this BASE server"
299          ><base:icon image="rss.png" style="float: right;" /></a>
300        <%
301      }
302      %>
303      </h3>
304      <div id="news" class="news">
305      <%
306      if (broadcastTitle != null)
307      {
308        %>
309        <div class="item note sticky">
310          <div class="headline">
311            <span class="date"><%=dateFormatter.format(new Date())%></span>
312            <%=HTML.encodeTags(broadcastTitle)%><%=denyLogin ? " (login disabled)" : "" %>
313          </div>
314          <div class="text"><%=HTML.niceFormat(broadcastMessage)%></div>
315        </div>
316        <% 
317      }
318     
319      ItemQuery<News> query = News.getQuery();
320      query.order(Orders.desc(Hql.property("sticky")));
321      query.order(Orders.desc(Hql.property("newsDate")));
322      query.order(Orders.desc(Hql.property("id")));
323      query.setCacheResult(true);
324      query.setReturnTotalCount(true);
325      news = query.iterate(dc);
326      int numListed = 0;
327      while (news.hasNext())
328      {
329        News n = news.next();
330        if (numListed >= 10 && !n.isSticky()) break;
331        %>
332        <div class="item <%=n.isSticky() ? "note sticky" : ""%>">
333          <div class="headline">
334            <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
335            <%=HTML.encodeTags(n.getName())%>
336          </div>
337          <div class="text"><%=HTML.niceFormat(n.getDescription())%></div>
338        </div>
339        <%
340        numListed++;
341      }
342      if (numListed < news.getTotalCount())
343      {
344        %>
345        <base:icon image="bullet.png" /><a href="info/news.jsp" 
346          title="Show older news..."><%=news.getTotalCount()-numListed%> more</a>
347        <%
348      }
349      %>
350      </div>
351    </td>
352    </tr>
353    </table>
354
355    </form>
356  </base:body>
357  </base:page>
358  <%
359}
360finally
361{
362  if (dc != null) dc.close();
363}
364%>
365
Note: See TracBrowser for help on using the repository browser.