12490866baa3e55e9e264c4a726dd76b7330f287
[Sone.git] / src / main / java / net / pterodactylus / sone / web / pages / LogoutPage.java
1 /*
2  * Sone - LogoutPage.java - Copyright © 2010–2016 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.web.pages;
19
20 import net.pterodactylus.sone.web.WebInterface;
21 import net.pterodactylus.sone.web.page.FreenetRequest;
22 import net.pterodactylus.util.template.Template;
23 import net.pterodactylus.util.template.TemplateContext;
24 import freenet.clients.http.ToadletContext;
25
26 /**
27  * Logs a user out.
28  *
29  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30  */
31 public class LogoutPage extends SoneTemplatePage {
32
33         /**
34          * @param template
35          *            The template to render
36          * @param webInterface
37          *            The Sone web interface
38          */
39         public LogoutPage(Template template, WebInterface webInterface) {
40                 super("logout.html", template, "Page.Logout.Title", webInterface, true);
41         }
42
43         //
44         // TEMPLATEPAGE METHODS
45         //
46
47         /**
48          * {@inheritDoc}
49          */
50         @Override
51         protected void handleRequest(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
52                 setCurrentSone(request.getToadletContext(), null);
53                 throw new RedirectException("index.html");
54         }
55
56         /**
57          * {@inheritDoc}
58          */
59         @Override
60         public boolean isEnabled(ToadletContext toadletContext) {
61                 if (webInterface.getCore().getPreferences().isRequireFullAccess() && !toadletContext.isAllowedFullAccess()) {
62                         return false;
63                 }
64                 return (getCurrentSoneWithoutCreatingSession(toadletContext) != null) && (webInterface.getCore().getLocalSones().size() != 1);
65         }
66
67 }