source: trunk/www/main.jsp @ 7408

Last change on this file since 7408 was 7408, checked in by Nicklas Nordborg, 5 years ago

References #2097: Implement support for device verification

The major part of device verification should now be implemented. If the web application has a stored token it is submitted with the login information (LoginRequest.setDeviceToken()). The SessionControl.login() method will check if the device is known or not.

If not, a DeviceNotVerifiedException is thrown and the user is taken to the verify_device.jsp page. The code should be sent by email but is currently only display on that page (to be fixed!). If the verification code is correct, information about the device is stored in the database so that the user can be allowed access immediately the next time.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 9.9 KB
Line 
1<%-- $Id: main.jsp 7408 2017-10-06 09:37:18Z 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  %>
105  <base:page type="default">
106  <base:head styles="login.css" scripts="exception.js,~login.js">
107    <ext:scripts context="<%=jspContext%>" />
108    <ext:stylesheets context="<%=jspContext%>" />
109  </base:head>
110  <base:body style="padding-top: 5em;">
111    <form name="login" action="login.jsp" method="post">
112    <input type="hidden" name="ID" value="<%=ID%>">
113    <input type="hidden" name="useAutoStartPage" value="1">
114    <input type="hidden" name="deviceToken" value="">
115   
116    <table style="margin: auto; width: 700px;">
117    <tr>
118    <td>
119      <%
120      if (loginAction.getHelp() != null)
121      {
122        %>
123        <div class="messagecontainer help" style="font-style: italic;" id="login-help">
124        <%=loginAction.getHelp() %>
125        </div>
126        <%
127      }
128      if (error != null) 
129      {
130        %>
131        <div class="messagecontainer error" style="margin-top: 1em;"><%=error%></div>
132        <%
133      }
134      %>
135      <table style="width: 100%; margin-top: 1em; border-collapse: separate;">
136      <tr>
137        <td class="base-logo"><img src="images/baselogo.png" alt="BASE logo"></td>
138        <td style="width: 515px;">
139          <div id="loginform">
140          <table style="width: 100%;">
141            <tr <%=valueIfNotNull("class=\"", loginField.getClazz(), "\"")%> id="login-row">
142              <th class="bg-filled-100"><%=loginField.getPrompt() %></th>
143              <td colspan="2"><input class="text" name="login" id="login"
144                type="<%=loginField.hasHiddenCharacters() ? "password" : "text"%>"
145                value="<%=loginAction.rememberLastLogin() ? HTML.encodeTags(login) : ""%>" 
146                <%=denyLogin ? "disabled" : ""%>
147                <%=valueIfNotNull("style=\"", loginField.getStyle(), "\"") %>
148                <%=valueIfNotNull("title=\"", loginField.getTooltip(), "\"") %>
149                <%=valueIfNotNull("placeholder=\"", loginField.getPlaceHolder(), "\"") %>
150                <%=loginAction.rememberLastLogin() ? "" : "autocomplete=\"off\" data-use-last-login=\"0\""%>
151                maxlength="100" 
152                tabindex="0">
153              </td>
154            </tr>
155            <tr <%=valueIfNotNull("class=\"", passwordField.getClazz(), "\"")%> id="password-row">
156              <th class="bg-filled-100"><%=passwordField.getPrompt() %></th>
157              <td><input class="text" name="password" id="password"
158                type="<%=passwordField.hasHiddenCharacters() ? "password" : "text"%>"
159                <%=denyLogin ? "disabled" : ""%>
160                <%=valueIfNotNull("style=\"", passwordField.getStyle(), "\"") %>
161                <%=valueIfNotNull("title=\"", passwordField.getTooltip(), "\"") %>
162                <%=valueIfNotNull("placeholder=\"", passwordField.getPlaceHolder(), "\"") %>
163                maxlength="80"
164                tabindex="0">
165              </td>
166              <td><base:button 
167                id="btnLogin"
168                subclass="<%=denyLogin ? "disabled" : ""%>"
169                image="login.png" title="Login" 
170                tooltip="<%=HTML.encodeTags(broadcastTitle)%>" /></td>
171            </tr>
172            <tr>
173              <th class="bg-filled-100 subprompt"></th>
174              <td colspan="2">
175              <%
176              String forgotPassword = sc.getClientDefaultSetting("server.forgotten.password");
177              String getAccount = sc.getClientDefaultSetting("server.get.account");
178              if (forgotPassword != null)
179              {
180                %>
181                <base:icon id="forgotPassword" image="bullet.png" 
182                  tooltip="Click here if you have forgotten your password">Forgot your password?</base:icon>
183                <%
184              }
185              if (getAccount != null)
186              {
187                %>
188                <base:icon id="getAccount" image="bullet.png" 
189                  tooltip="Click here if you want to get an account on this server">Get an account!</base:icon>
190                <%
191              }
192              %>
193              </td>
194            </tr>
195            </table>
196          </div>
197        </td>
198      </tr>
199      </table>
200      <%
201      if (denyLogin)
202      {
203        %>
204        <div class="messagecontainer help" id="denyLogin">
205          <b><%=HTML.encodeTags(broadcastTitle) %> (login disabled)</b><br>
206          <%=HTML.niceFormat(broadcastMessage)%>
207          <base:buttongroup style="margin-top: 1em;">
208            <base:button id="btnLoginAnyway" title="Login anyway" image="login.png" tooltip="At your own risk!" />
209          </base:buttongroup>
210        </div>
211        <%
212      }
213      %>
214      <%
215      String aboutServer = sc.getClientDefaultSetting("server.about");
216      if (aboutServer != null)
217      {
218        %>
219        <h3 style="margin-top: 1em;">About this server</h3>
220        <p>
221          <%=aboutServer%>
222        </p>
223        <base:icon id="aboutServer" image="bullet.png">More about this server</base:icon>
224        <%
225      }
226      %>
227     
228      <h3 style="margin-top: 1em;">News and announcements
229      <%
230      if (RssNewsFeed.isEnabled()) 
231      {
232        %>
233        <a href="info/news.rss" 
234          title="Subscribe to news from this BASE server"
235          ><base:icon image="rss.png" style="float: right;" /></a>
236        <%
237      }
238      %>
239      </h3>
240      <div id="news" class="news">
241      <%
242      if (broadcastTitle != null)
243      {
244        %>
245        <div class="item note sticky">
246          <div class="headline">
247            <span class="date"><%=dateFormatter.format(new Date())%></span>
248            <%=HTML.encodeTags(broadcastTitle)%><%=denyLogin ? " (login disabled)" : "" %>
249          </div>
250          <div class="text"><%=HTML.niceFormat(broadcastMessage)%></div>
251        </div>
252        <% 
253      }
254     
255      ItemQuery<News> query = News.getQuery();
256      query.order(Orders.desc(Hql.property("sticky")));
257      query.order(Orders.desc(Hql.property("newsDate")));
258      query.order(Orders.desc(Hql.property("id")));
259      query.setCacheResult(true);
260      query.setReturnTotalCount(true);
261      news = query.iterate(dc);
262      int numListed = 0;
263      while (news.hasNext())
264      {
265        News n = news.next();
266        if (numListed >= 10 && !n.isSticky()) break;
267        %>
268        <div class="item <%=n.isSticky() ? "note sticky" : ""%>">
269          <div class="headline">
270            <span class="date"><%=dateFormatter.format(n.getNewsDate())%></span>
271            <%=HTML.encodeTags(n.getName())%>
272          </div>
273          <div class="text"><%=HTML.niceFormat(n.getDescription())%></div>
274        </div>
275        <%
276        numListed++;
277      }
278      if (numListed < news.getTotalCount())
279      {
280        %>
281        <base:icon image="bullet.png" /><a href="info/news.jsp" 
282          title="Show older news..."><%=news.getTotalCount()-numListed%> more</a>
283        <%
284      }
285      %>
286      </div>
287    </td>
288    </tr>
289    </table>
290
291    </form>
292  </base:body>
293  </base:page>
294  <%
295}
296finally
297{
298  if (dc != null) dc.close();
299}
300%>
301
Note: See TracBrowser for help on using the repository browser.