diff --git a/plinth/modules/sso/views.py b/plinth/modules/sso/views.py index d84984a96..6415f545a 100644 --- a/plinth/modules/sso/views.py +++ b/plinth/modules/sso/views.py @@ -9,9 +9,13 @@ import urllib import axes.utils from axes.decorators import axes_form_invalid +from django import shortcuts +from django.contrib import messages from django.contrib.auth import REDIRECT_FIELD_NAME -from django.contrib.auth.views import LoginView, LogoutView +from django.contrib.auth import logout as auth_logout +from django.contrib.auth.views import LoginView from django.http import HttpResponseRedirect +from django.utils.translation import gettext as _ from plinth import actions, translation, utils, web_framework @@ -89,15 +93,13 @@ class CaptchaLoginView(LoginView): return set_ticket_cookie(request.user, response) -class SSOLogoutView(LogoutView): - """View to log out of FreedomBox and remove the auth_pubtkt cookie.""" - template_name = 'index.html' - - def dispatch(self, request, *args, **kwargs): - response = super(SSOLogoutView, self).dispatch(request, *args, - **kwargs) - response.delete_cookie(SSO_COOKIE_NAME) - return response +def logout(request): + """Logout an authenticated user, remove SSO cookie and redirect to home.""" + auth_logout(request) + response = shortcuts.redirect('index') + response.delete_cookie(SSO_COOKIE_NAME) + messages.success(request, _('Logged out successfully.')) + return response def refresh(request): diff --git a/plinth/modules/users/urls.py b/plinth/modules/users/urls.py index b95391f75..7bce71b59 100644 --- a/plinth/modules/users/urls.py +++ b/plinth/modules/users/urls.py @@ -4,11 +4,10 @@ URLs for the Users module """ from axes.decorators import axes_dispatch -from django.urls import re_path, reverse_lazy +from django.urls import re_path from stronghold.decorators import public -from plinth.modules.sso.views import (CaptchaLoginView, SSOLoginView, - SSOLogoutView) +from plinth.modules.sso.views import CaptchaLoginView, SSOLoginView, logout from plinth.utils import non_admin_view from . import views @@ -30,8 +29,7 @@ urlpatterns = [ # axes_dispatch after axes 5.x becomes available in Debian stable. re_path(r'^accounts/login/$', public(axes_dispatch(SSOLoginView.as_view())), name='login'), - re_path(r'^accounts/logout/$', non_admin_view(SSOLogoutView.as_view()), - {'next_page': reverse_lazy('index')}, name='logout'), + re_path(r'^accounts/logout/$', public(logout), name='logout'), re_path(r'^users/firstboot/$', public(views.FirstBootView.as_view()), name='firstboot'), re_path(r'accounts/login/locked/$', public(CaptchaLoginView.as_view()),