Skip to content

Commit

Permalink
Redirect unauthenticated users to contrib.auth's login URL if trying …
Browse files Browse the repository at this point in the history
…to access a page behind the beta wall.

Updates also include adjustment to applicable test scenario, plus URL and template support for basic contrib.auth in testing app.
  • Loading branch information
mypetyak committed Mar 11, 2014
1 parent a996a02 commit 19a2258
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion hunger/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def process_view(self, request, view_func, view_args, view_kwargs):
return

if not request.user.is_authenticated():
return redirect(self.redirect)
# Ask anonymous user to log in if trying to access in-beta view
return redirect(setting('LOGIN_URL'))

if request.user.is_staff:
return
Expand Down
Empty file.
3 changes: 2 additions & 1 deletion tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ def test_always_allow_module(self):
self.assertEqual(response.status_code, 200)

def test_garden_when_not_invited(self):
"""Confirm that an unauthenticated user is redirected to login"""
response = self.client.get(reverse('invited_only'))
self.assertRedirects(response, reverse(self.redirect))
self.assertRedirects(response, setting('LOGIN_URL'))

def test_using_invite(self):
cary = User.objects.create_user('cary', '[email protected]', 'secret')
Expand Down
1 change: 1 addition & 0 deletions tests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
name='always_allow_module'),
url(r'^not-allowed/$', 'tests.views.rejection', name='rejection'),
url(r'^hunger/', include('hunger.urls')),
url(r'^accounts/', include('django.contrib.auth.urls'))
)

0 comments on commit 19a2258

Please sign in to comment.