source: trunk/www/main.jsp @ 7114

Last change on this file since 7114 was 7114, checked in by Nicklas Nordborg, 6 years ago

References #1995: Add extension point for selecting start page

The login handling should now support this feature. It is available from the main login page and from the "Switch user" dialog when the "Remain on this page" is not checked. The login page that is shown after an automatic logout due to a timeout does not support this feature since it may interfere with what the user doing.

A concern is that the new start page doean't exists or has an error of some sort. In this case it may result in a lockout of the user. To prevent this a special page for handling "404 Not found" errors have been created. This page should display the regular BASE menu and allow the user to continue and modify the start page setting.

If this doesn't work it is also possible to hold down CTRL or ALT or SHIFT while clicking on the "Login" button. This will disable the extension start page and always display the regular home page instead.

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