Skip to content

Commit

Permalink
Added redirect check for unauthenticated users.
Browse files Browse the repository at this point in the history
  • Loading branch information
williln committed Jul 12, 2015
1 parent 96af2aa commit 17d4c04
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Expand Up @@ -26,6 +26,7 @@ Direct Contributors
* Kit Sunde
* Ben Cardy
* Rag Sagar.V
* Lacey Williams Henschel

Other Contributors
==================
Expand Down
12 changes: 7 additions & 5 deletions braces/views/_access.py
Expand Up @@ -430,8 +430,10 @@ def dispatch(self, request, *args, **kwargs):
resp = super(RecentLoginRequiredMixin, self).dispatch(
request, *args, **kwargs)

delta = datetime.timedelta(seconds=self.max_last_login_delta)
if now() > (request.user.last_login + delta):
return logout_then_login(request, self.get_login_url())
else:
return resp
if resp.status_code == 200:
delta = datetime.timedelta(seconds=self.max_last_login_delta)
if now() > (request.user.last_login + delta):
return logout_then_login(request, self.get_login_url())
else:
return resp
return resp
1 change: 1 addition & 0 deletions docs/changelog.rst
Expand Up @@ -4,6 +4,7 @@
Changelog
=========

* :bug:`176` Added redirect for unauthenticated users.
* :support:`-` Changed :ref:`JsonRequestResponseMixin` docs to not use `ugettext_lazy`.
* :support:`-` Updated tests to include Python 3.2.
* :bug:`185` Removed `u` prefixes to allow Python 3.2 support.
Expand Down
6 changes: 6 additions & 0 deletions tests/test_access_mixins.py
Expand Up @@ -645,3 +645,9 @@ def test_outdated_login(self):
self.client.login(username=user.username, password='asdf1234')
resp = self.client.get(self.outdated_view_url)
assert resp.status_code == 302

def test_not_logged_in(self):
last_login = datetime.datetime.now()
user = UserFactory(last_login=last_login)
resp = self.client.get(self.recent_view_url)
assert resp.status_code != 200

0 comments on commit 17d4c04

Please sign in to comment.