From 0bded3afc75839f27f34800fab1ee2932761e9ab Mon Sep 17 00:00:00 2001 From: Evert Date: Tue, 14 Nov 2017 15:32:26 +0200 Subject: [PATCH] Authentication - Add logout view and set login url in settings --- EpisodesCommunity/settings.py | 1 + LandingPage/urls.py | 1 + LandingPage/views.py | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/EpisodesCommunity/settings.py b/EpisodesCommunity/settings.py index 0774f06..63e691d 100644 --- a/EpisodesCommunity/settings.py +++ b/EpisodesCommunity/settings.py @@ -72,6 +72,7 @@ MIDDLEWARE = [ ] ROOT_URLCONF = 'EpisodesCommunity.urls' +LOGIN_URL = '/login' TEMPLATES = [ { diff --git a/LandingPage/urls.py b/LandingPage/urls.py index 8c4c86d..7b2ab2c 100644 --- a/LandingPage/urls.py +++ b/LandingPage/urls.py @@ -3,6 +3,7 @@ from django.conf.urls import url from . import views urlpatterns = [ + url(r'^logout/$', views.LogoutView), url(r'^login/redirect$', views.LoginRedirect.as_view()), url(r'^login$', views.Login.as_view()), url(r'^$', views.LandingPage.as_view()), diff --git a/LandingPage/views.py b/LandingPage/views.py index 0c277f2..b515f80 100644 --- a/LandingPage/views.py +++ b/LandingPage/views.py @@ -6,6 +6,7 @@ from django.conf import settings from django.http import HttpResponse from django.http import HttpResponseRedirect from django.db.models import Max +from django.contrib.auth.views import logout import requests import hashlib import json @@ -50,6 +51,10 @@ class Login(View): response['Location'] = url return response +def LogoutView(request): + logout(request) + return HttpResponseRedirect('/') + def generateState(request): request.session.save()