Add logout page.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 25 Jul 2012 20:16:54 +0000 (22:16 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 26 Jul 2012 05:28:49 +0000 (07:28 +0200)
src/main/java/net/pterodactylus/demoscenemusic/page/LogoutPage.java [new file with mode: 0644]
src/main/resources/templates/logout [new file with mode: 0644]
src/main/webapp/WEB-INF/web.xml.template

diff --git a/src/main/java/net/pterodactylus/demoscenemusic/page/LogoutPage.java b/src/main/java/net/pterodactylus/demoscenemusic/page/LogoutPage.java
new file mode 100644 (file)
index 0000000..95ab3ea
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * DemosceneMusic - LogoutPage.java - Copyright © 2012 David Roden
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.demoscenemusic.page;
+
+import net.pterodactylus.demoscenemusic.core.Core;
+import net.pterodactylus.util.template.Template;
+import net.pterodactylus.util.template.TemplateContext;
+import net.pterodactylus.util.template.TemplateContextFactory;
+import net.pterodactylus.util.web.RedirectException;
+
+/**
+ * Page that logs out the current user.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class LogoutPage extends BasePage {
+
+       /**
+        * Creates a new logout page.
+        *
+        * @param core
+        *            The core
+        * @param templateContextFactory
+        *            The template context factory
+        * @param template
+        *            The template to render
+        */
+       public LogoutPage(Core core, TemplateContextFactory templateContextFactory, Template template) {
+               super(core, templateContextFactory, template, "logout");
+       }
+
+       //
+       // BASEPAGE METHODS
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       protected void processTemplate(TemplateContext templateContext, ServletRequest request) throws RedirectException {
+               super.processTemplate(templateContext, request);
+               request.getServletRequest().getSession().removeAttribute("currentUser");
+               throw new RedirectException(".");
+       }
+
+}
diff --git a/src/main/resources/templates/logout b/src/main/resources/templates/logout
new file mode 100644 (file)
index 0000000..e69de29
index aa22191..98e0d4d 100644 (file)
                        <param-value>net.pterodactylus.demoscenemusic.page.LoginPage</param-value>
                </init-param>
                <init-param>
+                       <param-name>logout</param-name>
+                       <param-value>net.pterodactylus.demoscenemusic.page.LogoutPage</param-value>
+               </init-param>
+               <init-param>
                        <param-name>openid</param-name>
                        <param-value>net.pterodactylus.demoscenemusic.page.OpenIdPage</param-value>
                </init-param>