Luke Plant avatar Luke Plant committed ebfd103

Implemented log out

Comments (0)

Files changed (5)

cciw/bookings/templatetags/bookings.py

     else:
         out.append("Bookings: %s" % escape(request.booking_account.email))
         out.append(' | <a href="%s">Account overview</a>' % escape(reverse('cciw.bookings.views.account_overview')))
-        out.append(' | <a href="%s">Log out</a>' % 'TODO')
+        out.append(' | <a href="%s">Log out</a>' % escape(reverse('cciw.bookings.views.logout')))
     out.append("</div>")
 
     out.append("<ul>")

cciw/bookings/tests.py

 
         # Basket/Shelf
         self.assertContains(resp, 'items in your basket')
+
+
+class TestLogOut(LogInMixin, TestCase):
+
+    fixtures = ['basic']
+
+    url = reverse('cciw.bookings.views.logout')
+
+    def test_get(self):
+        self.login()
+        resp = self.client.get(self.url)
+        self.assertEqual(resp.status_code, 200)
+
+    def test_logout(self):
+        self.login()
+        resp = self.client.post(self.url, {'logout': '1'})
+        self.assertEqual(resp.status_code, 302)
+
+        # Try accessing a page which is restricted
+        resp2 = self.client.get(reverse('cciw.bookings.views.account_overview'))
+        self.assertEqual(resp2.status_code, 302)
+

cciw/bookings/urls.py

              (r'^pay/done/$', 'pay_done'),
              (r'^pay/cancelled/$', 'pay_cancelled'),
              (r'^overview/$', 'account_overview'),
+             (r'^logout/$', 'logout'),
              )

cciw/bookings/views.py

                                max_age=settings.BOOKING_SESSION_TIMEOUT_SECONDS)
 
 
+def unset_booking_account_cookie(response):
+    response.delete_cookie('bookingaccount')
+
+
 def get_booking_account_from_cookie(request):
     cookie = request.get_signed_cookie('bookingaccount',
                                        salt=BOOKING_COOKIE_SALT,
         return c
 
 
+class BookingLogOut(DefaultMetaData, TemplateView):
+    metadata_title = "Booking - log out"
+    template_name = 'cciw/bookings/logout.html'
+    extra_context = {'stage': ''}
+
+    def post(self, request, *args, **kwargs):
+        if 'logout' in request.POST:
+            response = HttpResponseRedirect(reverse('cciw.bookings.views.index'))
+            unset_booking_account_cookie(response)
+            return response
+        else:
+            return self.get(request, *args, **kwargs)
+
+
 index = BookingIndex.as_view()
 start = BookingStart.as_view()
 email_sent = BookingEmailSent.as_view()
 pay_done = csrf_exempt(BookingPayDone.as_view())
 pay_cancelled = csrf_exempt(BookingPayCancelled.as_view())
 account_overview = booking_account_required(BookingAccountOverview.as_view())
-
+logout = booking_account_required(BookingLogOut.as_view())

templates/cciw/bookings/logout.html

+{% extends 'cciw/bookings/standard.html' %}
+{% block content %}
+<h2>Confirm log out</h2>
+
+
+<p><strong>In order to log back in again, you will need to verify your email address as
+  you did the first time.</strong></p>
+
+<p>By logging out, other users of this computer will not be able to access your
+  account details, which is important if you are using a public computer (for
+  example in an internet cafe).
+
+<p>Press this button in order to go ahead and log out:</p>
+
+<form action="" method="POST">
+{% csrf_token %}
+<p style="text-align: center">
+<input type="submit" name="logout" value="Log out">
+</p>
+</form>
+
+<p>Otherwise your session will expire two weeks after you last logged in.</p>
+
+{% endblock %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.