source: branches/3.19-stable/www/main.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 Id
File size: 13.1 KB
Line 
1<%-- $Id: main.jsp 8036 2022-05-25 06:31: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.FieldInfo"
53  import="net.sf.basedb.clients.web.extensions.login.PasswordLoginFormFactory"
54  import="net.sf.basedb.clients.web.extensions.DynamicActionAttributeSupport"
55  import="net.sf.basedb.util.Values"
56  import="java.util.Date"
57  import="java.util.Map"
58  import="java.util.TreeMap"
59  import="java.util.UUID"
60%>
61<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
62<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
63<%! 
64// If value is null, return "", else <prefix>+<value>+<suffix>
65String valueIfNotNull(String prefix, String value, String suffix)
66{
67  return value == null ? "" : prefix+value+suffix;
68}
69%>
70<%
71final String login = Values.getString(request.getParameter("login"), "");
72final String error = Values.getString(request.getParameter("error"), null);
73final boolean again = Values.getBoolean(request.getParameter("again"));
74final String requestedLoginForm = Values.getString(request.getParameter("loginForm"), null);
75final String root = request.getContextPath()+"/";
76
77final SessionControl sc = Base.getSessionControl(pageContext, true);
78final String ID = sc.getId();
79final Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
80final DbControl dc = sc.newDbControl(":Main login form");
81
82try
83{
84  String broadcastTitle = (String)application.getAttribute("broadcast.title");
85  String broadcastMessage = (String)application.getAttribute("broadcast.message");
86  boolean denyLogin = Boolean.TRUE.equals(application.getAttribute("broadcast.deny-login"));
87 
88  ItemResultIterator<News> news = null;
89  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
90  ExtensionsInvoker<LoginFormAction> invoker = ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form");
91
92  LoginFormAction loginAction = null;
93  String selectedLoginForm = null;
94  Map<String, String> allForms = new TreeMap<String, String>();
95 
96  ActionIterator<LoginFormAction> it = invoker.iterate();
97  while (it.hasNext())
98  {
99    LoginFormAction action = it.next();
100    if (action != null)
101    {
102      String formId = action.getId();
103      if (formId == null) formId = it.getExtension().getId();
104      String displayName = action.getDisplayName();
105      if (displayName == null) displayName = it.getExtension().getAbout().getName();
106      allForms.put(formId, displayName);
107     
108      if (loginAction == null || formId.equals(requestedLoginForm))
109      {
110        loginAction = action;
111        selectedLoginForm = formId;
112      }
113    }
114  }
115  if (loginAction == null)
116  {
117    loginAction = PasswordLoginFormFactory.INSTANCE;
118    selectedLoginForm = loginAction.getId();
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="~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      <%=DynamicActionAttributeSupport.getAttributesString(loginAction)%>
133    >
134    <input type="hidden" name="ID" value="<%=ID%>">
135    <input type="hidden" name="again" value="<%=again?1:0%>">
136    <input type="hidden" name="useAutoStartPage" value="1">
137    <input type="hidden" name="deviceToken" value="<%=UUID.randomUUID().toString()%>">
138   
139    <table style="margin: auto; max-width: 700px; display: none;" id="the-login-form">
140    <tr>
141    <td>
142      <%
143      if (allForms.size() > 1)
144      {
145        %>
146        <div style="text-align: right; margin-bottom: 0.25em;">
147          <b>Login with</b>
148          <select name="loginForm" id="loginForm" style="min-width: 10em;">
149          <%
150          for (Map.Entry<String, String> entry : allForms.entrySet())
151          {
152            String formId = entry.getKey();
153            %>
154            <option value="<%=formId%>" <%=formId.equals(selectedLoginForm) ? "selected" : ""%>><%=HTML.encodeTags(entry.getValue()) %>
155            <%
156          }
157          %>
158          </select>
159        </div>
160        <%
161      }
162      else if (selectedLoginForm != null)
163      {
164        %>
165        <input type="hidden" name="loginForm" value="<%=selectedLoginForm%>">
166        <%
167      }
168      if (loginAction.getHelp() != null)
169      {
170        %>
171        <div class="messagecontainer help" style="margin-bottom: 1em; font-style: italic;" id="login-help">
172        <%=loginAction.getHelp() %>
173        </div>
174        <%
175      }
176      if (error != null) 
177      {
178        %>
179        <div class="messagecontainer error" style="margin-top: 1em; margin-bottom: 1em;"><%=error%></div>
180        <%
181      }
182      %>
183      <table style="width: 100%; border-collapse: separate;">
184      <tr>
185        <td class="base-logo"><img src="images/baselogo.png" alt="BASE logo"></td>
186        <td style="width: 515px;">
187          <div id="loginform">
188          <table style="width: 100%;">
189            <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
190              <th class="bg-filled-100"><%=loginField.getPrompt() %></th>
191              <td colspan="2"><input class="text" name="login" id="login"
192                type="<%=loginField.hasHiddenCharacters() ? "password" : "text"%>"
193                value="<%=loginAction.rememberLastLogin() ? HTML.encodeTags(login) : ""%>" 
194                <%=denyLogin ? "disabled" : ""%>
195                <%=valueIfNotNull("style=\"", loginField.getStyle(), "\"") %>
196                <%=valueIfNotNull("title=\"", loginField.getTooltip(), "\"") %>
197                <%=valueIfNotNull("placeholder=\"", loginField.getPlaceHolder(), "\"") %>
198                <%=loginAction.rememberLastLogin() ? "" : "autocomplete=\"off\" data-use-last-login=\"0\""%>
199                maxlength="100" 
200                tabindex="1"
201                <%=DynamicActionAttributeSupport.getAttributesString(loginField)%>
202                >
203              </td>
204            </tr>
205            <tr <%=valueIfNotNull("class=\"", passwordField.getClazz(), "\"")%> id="password-row">
206              <th class="bg-filled-100"><%=passwordField.getPrompt() %></th>
207              <td><input class="text" name="password" id="password"
208                type="<%=passwordField.hasHiddenCharacters() ? "password" : "text"%>"
209                <%=denyLogin ? "disabled" : ""%>
210                <%=valueIfNotNull("style=\"", passwordField.getStyle(), "\"") %>
211                <%=valueIfNotNull("title=\"", passwordField.getTooltip(), "\"") %>
212                <%=valueIfNotNull("placeholder=\"", passwordField.getPlaceHolder(), "\"") %>
213                maxlength="80"
214                tabindex="2"
215                <%=DynamicActionAttributeSupport.getAttributesString(passwordField)%>
216                >
217              </td>
218              <td <%=extraField != null?"rowspan=\"2\"" : "" %> style="vertical-align: bottom;">
219                  <base:buttongroup>
220                    <base:button 
221                      id="btnLogin"
222                      subclass="<%=denyLogin ? "disabled" : ""%>"
223                      image="login.png" title="Login" 
224                      tooltip="<%=HTML.encodeTags(broadcastTitle)%>" tabindex="4" 
225                    />
226                    <base:button 
227                      id="close" title="Cancel" tabindex="5"
228                      visible="<%=again %>"
229                    />
230                  </base:buttongroup>
231              </td>
232            </tr>
233            <%
234            if (extraField != null)
235            {
236              %>
237              <tr <%=valueIfNotNull("class=\"", extraField.getClazz(), "\"")%> id="extra-row">
238                <th class="bg-filled-100"><%=extraField.getPrompt() %></th>
239                <td><input class="text" name="extraField" id="extraField"
240                  type="<%=extraField.hasHiddenCharacters() ? "password" : "text"%>"
241                  <%=denyLogin ? "disabled" : ""%>
242                  <%=valueIfNotNull("style=\"", extraField.getStyle(), "\"") %>
243                  <%=valueIfNotNull("title=\"", extraField.getTooltip(), "\"") %>
244                  <%=valueIfNotNull("placeholder=\"", extraField.getPlaceHolder(), "\"") %>
245                  maxlength="80"
246                  tabindex="3"
247                  <%=DynamicActionAttributeSupport.getAttributesString(extraField)%>
248                  >
249                </td>
250              </tr>
251              <%
252            }
253            %>
254            <tr>
255              <th class="bg-filled-100 subprompt"></th>
256              <td colspan="2">
257              <%
258              String forgotPassword = sc.getClientDefaultSetting("server.forgotten.password");
259              String getAccount = sc.getClientDefaultSetting("server.get.account");
260              if (forgotPassword != null)
261              {
262                %>
263                <base:icon id="forgotPassword" image="bullet.png" 
264                  tooltip="Click here if you have forgotten your password">Forgot your password?</base:icon>
265                <%
266              }
267              if (getAccount != null)
268              {
269                %>
270                <base:icon id="getAccount" image="bullet.png" 
271                  tooltip="Click here if you want to get an account on this server">Get an account!</base:icon>
272                <%
273              }
274              %>
275              </td>
276            </tr>
277            </table>
278          </div>
279        </td>
280      </tr>
281      </table>
282      <%
283      if (denyLogin)
284      {
285        %>
286        <div class="messagecontainer help" id="denyLogin">
287          <b><%=HTML.encodeTags(broadcastTitle) %> (login disabled)</b><br>
288          <%=HTML.niceFormat(broadcastMessage)%>
289          <base:buttongroup style="margin-top: 1em;">
290            <base:button id="btnLoginAnyway" title="Login anyway" image="login.png" tooltip="At your own risk!" />
291          </base:buttongroup>
292        </div>
293        <%
294      }
295      if (!again)
296      {
297        String aboutServer = sc.getClientDefaultSetting("server.about");
298        if (aboutServer != null)
299        {
300          %>
301          <h3 style="margin-top: 1em;">About this server</h3>
302          <p>
303            <%=aboutServer%>
304          </p>
305          <base:icon id="aboutServer" image="bullet.png">More about this server</base:icon>
306          <%
307        }
308        %>
309        <h3 style="margin-top: 1em;">News and announcements
310        <%
311        if (RssNewsFeed.isEnabled()) 
312        {
313          %>
314          <a href="info/news.rss" 
315            title="Subscribe to news from this BASE server"
316            ><base:icon image="rss.png" style="float: right;" /></a>
317          <%
318        }
319        %>
320        </h3>
321        <div id="news" class="news">
322        <%
323        if (broadcastTitle != null)
324        {
325          %>
326          <div class="item note sticky">
327            <div class="headline">
328              <span class="date"><%=dateFormatter.format(new Date())%></span>
329              <%=HTML.encodeTags(broadcastTitle)%><%=denyLogin ? " (login disabled)" : "" %>
330            </div>
331            <div class="text"><%=HTML.niceFormat(broadcastMessage)%></div>
332          </div>
333          <% 
334        }
335       
336        ItemQuery<News> query = News.getQuery();
337        query.order(Orders.desc(Hql.property("sticky")));
338        query.order(Orders.desc(Hql.property("newsDate")));
339        query.order(Orders.desc(Hql.property("id")));
340        query.setCacheResult(true);
341        query.setReturnTotalCount(true);
342        news = query.iterate(dc);
343        int numListed = 0;
344        while (news.hasNext())
345        {
346          News n = news.next();
347          if (numListed >= 10 && !n.isSticky()) break;
348          %>
349          <div class="item <%=n.isSticky() ? "note sticky" : ""%>">
350            <div class="headline">
351              <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
352              <%=HTML.encodeTags(n.getName())%>
353            </div>
354            <div class="text"><%=HTML.niceFormat(n.getDescription())%></div>
355          </div>
356          <%
357          numListed++;
358        }
359        if (numListed < news.getTotalCount())
360        {
361          %>
362          <base:icon image="bullet.png" /><a href="info/news.jsp" 
363            title="Show older news..."><%=news.getTotalCount()-numListed%> more</a>
364          <%
365        }
366        %>
367        </div>
368        <%
369      }
370      %>
371    </td>
372    </tr>
373    </table>
374
375    </form>
376  </base:body>
377  </base:page>
378  <%
379}
380finally
381{
382  if (dc != null) dc.close();
383}
384%>
385
Note: See TracBrowser for help on using the repository browser.