diff --git a/studyguides/apps/auth/urls.py b/studyguides/apps/auth/urls.py index 103f9c0..644da73 100644 --- a/studyguides/apps/auth/urls.py +++ b/studyguides/apps/auth/urls.py @@ -7,5 +7,6 @@ app_name = "auth" urlpatterns = [ path("", views.index, name="index"), path("login/", views.login, name="login"), + path("logout/", views.logout_view, name="logout"), ] diff --git a/studyguides/apps/auth/views.py b/studyguides/apps/auth/views.py index 44d23ff..b6b36e2 100644 --- a/studyguides/apps/auth/views.py +++ b/studyguides/apps/auth/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth import logout from django.shortcuts import redirect, render def index(request): @@ -8,3 +9,7 @@ def index(request): def login(request): return render(request, "login.html") + +def logout_view(request): + logout(request) + return redirect("auth:login") diff --git a/studyguides/settings/__init__.py b/studyguides/settings/__init__.py index c7255ec..d375452 100644 --- a/studyguides/settings/__init__.py +++ b/studyguides/settings/__init__.py @@ -145,6 +145,7 @@ USE_TZ = True LOGIN_URL = "auth:login" LOGIN_REDIRECT_URL = "auth:index" +LOGOUT_REDIRECT_URL = "auth:login" SESSION_SAVE_EVERY_REQUEST = True diff --git a/studyguides/templates/base.html b/studyguides/templates/base.html index e97fc07..d1befde 100644 --- a/studyguides/templates/base.html +++ b/studyguides/templates/base.html @@ -45,14 +45,20 @@ {% block content %}{% endblock %} -
- {% if user.is_teacher %} - Report a Study Guide - {% elif user.is_superuser or user.is_staff %} - Report a Study Guide - Access Admin Console - {% endif %} - Add Study Guide -
+ {% if user.is_authenticated %} +
+ {% if user.is_teacher %} + Report a Study Guide + {% elif user.is_superuser or user.is_staff %} + Report a Study Guide + Access Admin Console + {% endif %} + Add Study Guide +
+
+
+ Logout +
+ {% endif %}