source: trunk/www/main.jsp @ 7500

Last change on this file since 7500 was 7500, checked in by Nicklas Nordborg, 5 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 Id
File size: 10.8 KB
Line 
1<%-- $Id: main.jsp 7500 2018-08-08 10:57:12Z 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.clients.web.Base"
44  import="net.sf.basedb.clients.web.util.HTML"
45  import="net.sf.basedb.util.formatter.Formatter"
46  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
47  import="net.sf.basedb.clients.web.extensions.JspContext"
48  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
49  import="net.sf.basedb.clients.web.servlet.RssNewsFeed"
50  import="net.sf.basedb.clients.web.extensions.login.LoginFormAction"
51  import="net.sf.basedb.clients.web.extensions.login.LoginFormBean"
52  import="net.sf.basedb.clients.web.extensions.login.FieldInfo"
53  import="net.sf.basedb.util.Values"
54  import="java.util.Date"
55%>
56<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
57<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
58<%! 
59// If value is null, return "", else <prefix>+<value>+<suffix>
60String valueIfNotNull(String prefix, String value, String suffix)
61{
62  return value == null ? "" : prefix+value+suffix;
63}
64%>
65<%
66final String login = Values.getString(request.getParameter("login"), "");
67final String error = Values.getString(request.getParameter("error"), null);
68final String root = request.getContextPath()+"/";
69
70final SessionControl sc = Base.getSessionControl(pageContext, true);
71final String ID = sc.getId();
72final Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
73final DbControl dc = sc.newDbControl();
74
75try
76{
77  String broadcastTitle = (String)application.getAttribute("broadcast.title");
78  String broadcastMessage = (String)application.getAttribute("broadcast.message");
79  boolean denyLogin = Boolean.TRUE.equals(application.getAttribute("broadcast.deny-login"));
80  ItemResultIterator<News> news = null;
81  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext);
82  ExtensionsInvoker<LoginFormAction> invoker = (ExtensionsInvoker<LoginFormAction>)ExtensionsControl.useExtensions(jspContext, "net.sf.basedb.clients.web.login-form");
83
84  LoginFormAction loginAction = null;
85  for (LoginFormAction action : invoker)
86  {
87    if (action != null)
88    {
89      loginAction = action;
90      break;
91    }
92  }
93  if (loginAction == null)
94  {
95    LoginFormBean bean  = new LoginFormBean();
96    bean.setRememberLastLogin(true);
97    bean.setLoginField(FieldInfo.DEFAULT_LOGIN);
98    bean.setPasswordField(FieldInfo.DEFAULT_PASSWORD);
99    loginAction = bean;
100  }
101
102  FieldInfo loginField = loginAction.getLoginField();
103  FieldInfo passwordField = loginAction.getPasswordField();
104  FieldInfo extraField = loginAction.getExtraField();
105  %>
106  <base:page type="default">
107  <base:head styles="login.css" scripts="exception.js,~login.js">
108    <ext:scripts context="<%=jspContext%>" />
109    <ext:stylesheets context="<%=jspContext%>" />
110  </base:head>
111  <base:body style="padding-top: 5em;">
112    <form name="login" action="login.jsp" method="post">
113    <input type="hidden" name="ID" value="<%=ID%>">
114    <input type="hidden" name="useAutoStartPage" value="1">
115    <input type="hidden" name="deviceToken" value="">
116   
117    <table style="margin: auto; width: 700px;">
118    <tr>
119    <td>
120      <%
121      if (loginAction.getHelp() != null)
122      {
123        %>
124        <div class="messagecontainer help" style="font-style: italic;" id="login-help">
125        <%=loginAction.getHelp() %>
126        </div>
127        <%
128      }
129      if (error != null) 
130      {
131        %>
132        <div class="messagecontainer error" style="margin-top: 1em;"><%=error%></div>
133        <%
134      }
135      %>
136      <table style="width: 100%; margin-top: 1em; border-collapse: separate;">
137      <tr>
138        <td class="base-logo"><img src="images/baselogo.png" alt="BASE logo"></td>
139        <td style="width: 515px;">
140          <div id="loginform">
141          <table style="width: 100%;">
142            <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
143              <th class="bg-filled-100"><%=loginField.getPrompt() %></th>
144              <td colspan="2"><input class="text" name="login" id="login"
145                type="<%=loginField.hasHiddenCharacters() ? "password" : "text"%>"
146                value="<%=loginAction.rememberLastLogin() ? HTML.encodeTags(login) : ""%>" 
147                <%=denyLogin ? "disabled" : ""%>
148                <%=valueIfNotNull("style=\"", loginField.getStyle(), "\"") %>
149                <%=valueIfNotNull("title=\"", loginField.getTooltip(), "\"") %>
150                <%=valueIfNotNull("placeholder=\"", loginField.getPlaceHolder(), "\"") %>
151                <%=loginAction.rememberLastLogin() ? "" : "autocomplete=\"off\" data-use-last-login=\"0\""%>
152                maxlength="100" 
153                tabindex="1">
154              </td>
155            </tr>
156            <tr <%=valueIfNotNull("class=\"", passwordField.getClazz(), "\"")%> id="password-row">
157              <th class="bg-filled-100"><%=passwordField.getPrompt() %></th>
158              <td><input class="text" name="password" id="password"
159                type="<%=passwordField.hasHiddenCharacters() ? "password" : "text"%>"
160                <%=denyLogin ? "disabled" : ""%>
161                <%=valueIfNotNull("style=\"", passwordField.getStyle(), "\"") %>
162                <%=valueIfNotNull("title=\"", passwordField.getTooltip(), "\"") %>
163                <%=valueIfNotNull("placeholder=\"", passwordField.getPlaceHolder(), "\"") %>
164                maxlength="80"
165                tabindex="2">
166              </td>
167              <td <%=extraField != null?"rowspan=\"2\"" : "" %> style="vertical-align: bottom;"><base:button 
168                id="btnLogin"
169                subclass="<%=denyLogin ? "disabled" : ""%>"
170                image="login.png" title="Login" 
171                tooltip="<%=HTML.encodeTags(broadcastTitle)%>" tabindex="4" /></td>
172            </tr>
173            <%
174            if (extraField != null)
175            {
176              %>
177              <tr <%=valueIfNotNull("class=\"", extraField.getClazz(), "\"")%> id="extra-row">
178                <th class="bg-filled-100"><%=extraField.getPrompt() %></th>
179                <td><input class="text" name="extraField" id="extraField"
180                  type="<%=extraField.hasHiddenCharacters() ? "password" : "text"%>"
181                  <%=denyLogin ? "disabled" : ""%>
182                  <%=valueIfNotNull("style=\"", extraField.getStyle(), "\"") %>
183                  <%=valueIfNotNull("title=\"", extraField.getTooltip(), "\"") %>
184                  <%=valueIfNotNull("placeholder=\"", extraField.getPlaceHolder(), "\"") %>
185                  maxlength="80"
186                  tabindex="3">
187                </td>
188              </tr>
189              <%
190            }
191            %>
192            <tr>
193              <th class="bg-filled-100 subprompt"></th>
194              <td colspan="2">
195              <%
196              String forgotPassword = sc.getClientDefaultSetting("server.forgotten.password");
197              String getAccount = sc.getClientDefaultSetting("server.get.account");
198              if (forgotPassword != null)
199              {
200                %>
201                <base:icon id="forgotPassword" image="bullet.png" 
202                  tooltip="Click here if you have forgotten your password">Forgot your password?</base:icon>
203                <%
204              }
205              if (getAccount != null)
206              {
207                %>
208                <base:icon id="getAccount" image="bullet.png" 
209                  tooltip="Click here if you want to get an account on this server">Get an account!</base:icon>
210                <%
211              }
212              %>
213              </td>
214            </tr>
215            </table>
216          </div>
217        </td>
218      </tr>
219      </table>
220      <%
221      if (denyLogin)
222      {
223        %>
224        <div class="messagecontainer help" id="denyLogin">
225          <b><%=HTML.encodeTags(broadcastTitle) %> (login disabled)</b><br>
226          <%=HTML.niceFormat(broadcastMessage)%>
227          <base:buttongroup style="margin-top: 1em;">
228            <base:button id="btnLoginAnyway" title="Login anyway" image="login.png" tooltip="At your own risk!" />
229          </base:buttongroup>
230        </div>
231        <%
232      }
233      %>
234      <%
235      String aboutServer = sc.getClientDefaultSetting("server.about");
236      if (aboutServer != null)
237      {
238        %>
239        <h3 style="margin-top: 1em;">About this server</h3>
240        <p>
241          <%=aboutServer%>
242        </p>
243        <base:icon id="aboutServer" image="bullet.png">More about this server</base:icon>
244        <%
245      }
246      %>
247     
248      <h3 style="margin-top: 1em;">News and announcements
249      <%
250      if (RssNewsFeed.isEnabled()) 
251      {
252        %>
253        <a href="info/news.rss" 
254          title="Subscribe to news from this BASE server"
255          ><base:icon image="rss.png" style="float: right;" /></a>
256        <%
257      }
258      %>
259      </h3>
260      <div id="news" class="news">
261      <%
262      if (broadcastTitle != null)
263      {
264        %>
265        <div class="item note sticky">
266          <div class="headline">
267            <span class="date"><%=dateFormatter.format(new Date())%></span>
268            <%=HTML.encodeTags(broadcastTitle)%><%=denyLogin ? " (login disabled)" : "" %>
269          </div>
270          <div class="text"><%=HTML.niceFormat(broadcastMessage)%></div>
271        </div>
272        <% 
273      }
274     
275      ItemQuery<News> query = News.getQuery();
276      query.order(Orders.desc(Hql.property("sticky")));
277      query.order(Orders.desc(Hql.property("newsDate")));
278      query.order(Orders.desc(Hql.property("id")));
279      query.setCacheResult(true);
280      query.setReturnTotalCount(true);
281      news = query.iterate(dc);
282      int numListed = 0;
283      while (news.hasNext())
284      {
285        News n = news.next();
286        if (numListed >= 10 && !n.isSticky()) break;
287        %>
288        <div class="item <%=n.isSticky() ? "note sticky" : ""%>">
289          <div class="headline">
290            <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
291            <%=HTML.encodeTags(n.getName())%>
292          </div>
293          <div class="text"><%=HTML.niceFormat(n.getDescription())%></div>
294        </div>
295        <%
296        numListed++;
297      }
298      if (numListed < news.getTotalCount())
299      {
300        %>
301        <base:icon image="bullet.png" /><a href="info/news.jsp" 
302          title="Show older news..."><%=news.getTotalCount()-numListed%> more</a>
303        <%
304      }
305      %>
306      </div>
307    </td>
308    </tr>
309    </table>
310
311    </form>
312  </base:body>
313  </base:page>
314  <%
315}
316finally
317{
318  if (dc != null) dc.close();
319}
320%>
321
Note: See TracBrowser for help on using the repository browser.