Skip to content

Commit

Permalink
Merge pull request #737 from 18F/logout
Browse files Browse the repository at this point in the history
Add logout view and menu item
  • Loading branch information
rogeruiz authored Mar 7, 2018
2 parents 737a934 + f2fbc63 commit 76d3854
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tock/tock/templates/_navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<span>Users</span>
</a>
</li>
<li>
<a href="{% url 'logout' %}" class="usa-nav-link">
<span>Log out</span>
</a>
</li>
{% if request.user.is_superuser %}
<li>
<button class="
Expand Down
8 changes: 8 additions & 0 deletions tock/tock/templates/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{% extends "base.html" %}

{% block content %}

<h2>Logged out</h2>
<p>You are now logged out of Tock.</p>

{% endblock %}
2 changes: 2 additions & 0 deletions tock/tock/tests/test_url_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class URLAuthTests(TestCase):
'/auth/fake/oauth/token',
# Logging out of admin is always public, so ignore it.
'/admin/logout/',
# And logging out of the site is always public too.
'/logout',
]

def assertURLIsProtectedByAuth(self, url):
Expand Down
12 changes: 12 additions & 0 deletions tock/tock/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.test import TestCase
from django.contrib.auth.models import User


class ViewsTests(TestCase):
def test_logout_logs_user_out(self):
user = User.objects.create_user(username='foo')
self.client.force_login(user)

response = self.client.get('/logout')
self.assertEqual(response.status_code, 200)
self.assertFalse(response.context['user'].is_authenticated())
3 changes: 3 additions & 0 deletions tock/tock/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def check_if_staff(user):
import hours.views
import api.urls
import projects.urls
import tock.views

urlpatterns = [
url(r'^$',
Expand Down Expand Up @@ -50,6 +51,8 @@ def check_if_staff(user):
url(r'^admin/', include(admin.site.urls)),

url(r'^auth/', include('uaa_client.urls')),

url(r'^logout$', tock.views.logout, name='logout'),
]


Expand Down
6 changes: 6 additions & 0 deletions tock/tock/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from django.shortcuts import render
import django.contrib.auth

logger = logging.getLogger(__name__)

Expand All @@ -14,3 +15,8 @@ def csrf_failure(request, reason=""):
)
)
return render(request, '403.html')


def logout(request):
django.contrib.auth.logout(request)
return render(request, 'logout.html')

0 comments on commit 76d3854

Please sign in to comment.