From 4a5b38f42e26668cee7eb4a3b4951d56933458b5 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 6 Jan 2021 17:13:40 +0100 Subject: [PATCH] Logout Application --- .../libreccm/ui/login/LoginController.java | 2 +- .../libreccm/ui/login/LogoutApplication.java | 41 ++++++++++++++ .../libreccm/ui/login/LogoutController.java | 55 +++++++++++++++++++ .../ccm-freemarker/logout/loggedout.html.ftl | 13 +++++ .../themes/ccm-freemarker/theme.json | 24 ++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 ccm-core/src/main/java/org/libreccm/ui/login/LogoutApplication.java create mode 100644 ccm-core/src/main/java/org/libreccm/ui/login/LogoutController.java create mode 100644 ccm-core/src/main/resources/themes/ccm-freemarker/logout/loggedout.html.ftl diff --git a/ccm-core/src/main/java/org/libreccm/ui/login/LoginController.java b/ccm-core/src/main/java/org/libreccm/ui/login/LoginController.java index 01df138c7..d75e0c61d 100644 --- a/ccm-core/src/main/java/org/libreccm/ui/login/LoginController.java +++ b/ccm-core/src/main/java/org/libreccm/ui/login/LoginController.java @@ -118,7 +118,7 @@ public class LoginController { models.put("loginFailed", true); return getLoginForm(uriInfo, returnUrl); } - + try { return Response.seeOther( new URI( diff --git a/ccm-core/src/main/java/org/libreccm/ui/login/LogoutApplication.java b/ccm-core/src/main/java/org/libreccm/ui/login/LogoutApplication.java new file mode 100644 index 000000000..6d942471a --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/login/LogoutApplication.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.login; + +import java.util.HashSet; +import java.util.Set; + +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +/** + * + * @author Jens Pelzetter + */ +@ApplicationPath("/@logout") +public class LogoutApplication extends Application { + + @Override + public Set> getClasses() { + final Set> classes = new HashSet<>(); + classes.add(LogoutController.class); + return classes; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/ui/login/LogoutController.java b/ccm-core/src/main/java/org/libreccm/ui/login/LogoutController.java new file mode 100644 index 000000000..48f41ccf9 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/ui/login/LogoutController.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2021 LibreCCM Foundation. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301 USA + */ +package org.libreccm.ui.login; + +import org.apache.shiro.subject.Subject; +import org.libreccm.theming.mvc.ThemesMvc; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.mvc.Controller; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.UriInfo; + +/** + * + * @author Jens Pelzetter + */ +@Controller +@Path("/") +@RequestScoped +public class LogoutController { + + @Inject + private Subject subject; + + @Inject + private ThemesMvc themesMvc; + + @GET + @Path("/") + public String logout(@Context final UriInfo uriInfo) { + subject.logout(); + + return themesMvc.getMvcTemplate(uriInfo, "logout"); + } + +} diff --git a/ccm-core/src/main/resources/themes/ccm-freemarker/logout/loggedout.html.ftl b/ccm-core/src/main/resources/themes/ccm-freemarker/logout/loggedout.html.ftl new file mode 100644 index 000000000..c126f5956 --- /dev/null +++ b/ccm-core/src/main/resources/themes/ccm-freemarker/logout/loggedout.html.ftl @@ -0,0 +1,13 @@ + + + + Category page + + + +
+

Logout successful

+

Logout successful

+
+ + diff --git a/ccm-core/src/main/resources/themes/ccm-freemarker/theme.json b/ccm-core/src/main/resources/themes/ccm-freemarker/theme.json index a71f3595d..fce2189d4 100644 --- a/ccm-core/src/main/resources/themes/ccm-freemarker/theme.json +++ b/ccm-core/src/main/resources/themes/ccm-freemarker/theme.json @@ -77,6 +77,30 @@ ] } } + }, + "logout": { + "description": { + "values": { + "value": [ + { + "lang": "en", + "value": "Logout successful" + } + ] + } + }, + "name": "loggedout", + "path": "logout/loggedout.html.ftl", + "title": { + "values": { + "value": [ + { + "lang": "en", + "value": "Logout succesful" + } + ] + } + } } } }