Skip to content

Commit

Permalink
Added logout view
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnny Mijnhout committed Jan 11, 2019
1 parent c67657c commit acd00ad
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
8 changes: 7 additions & 1 deletion arctic/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import extra_views
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import authenticate, login
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.forms import AuthenticationForm
from django.core.exceptions import (
FieldDoesNotExist,
Expand Down Expand Up @@ -933,3 +933,9 @@ def post(self, request, *args, **kwargs):
return render(
request, self.template_name, self.get_context_data(**kwargs)
)


class LogoutView(View):
def dispatch(self, request, *args, **kwargs):
logout(request)
return redirect(settings.LOGIN_URL)
3 changes: 2 additions & 1 deletion arctic/project_template/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@

STATIC_URL = "/static/"

LOGIN_URL = LOGOUT_URL = "login"
LOGIN_URL = "login"
LOGOUT_URL = "logout"

# Arctic configuration
ARCTIC_SITE_NAME = "{{ project_name }}'s Arctic website"
Expand Down
3 changes: 2 additions & 1 deletion example/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@
MEDIA_ROOT = location("media")
MEDIA_URL = "/media/"

LOGIN_URL = LOGOUT_URL = "login"
LOGIN_URL = "login"
LOGOUT_URL = "logout"


try:
Expand Down
3 changes: 2 additions & 1 deletion example/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.conf.urls import include, url
from django.conf.urls.static import static

from arctic.generics import LoginView
from arctic.generics import LoginView, LogoutView
from arctic.views import handler400, handler403, handler404, handler500 # noqa

from countries.views import CountryAPIView, CountryListView
Expand All @@ -14,6 +14,7 @@
urlpatterns = [
url(r"^$", DashboardView.as_view(), name="index"),
url(r"^login/$", LoginView.as_view(), name="login"),
url(r"^logout/$", LogoutView.as_view(), name="logout"),
url(r"^articles/", include("articles.urls", "articles")),
url(r"^users/", include("arctic.users.urls", namespace="users")),
url(r"^countries/$", CountryListView.as_view(), name="countries-list"),
Expand Down

0 comments on commit acd00ad

Please sign in to comment.