Skip to content

Commit

Permalink
Adding InvalidView and verify_invite views to whitelist (user should …
Browse files Browse the repository at this point in the history
…be able to access these without being in beta).

Enforcing login requirements before invitee with new code can be validated.  If user is not logged in, she is redirected to auth login page.  If auth 'next' feature is used, a successful login will then redirect to VerifiedView view.

.gitignor-ing Vagrant settings used for local development

Added test scenario for invalid Invite Code
  • Loading branch information
mypetyak committed Feb 28, 2014
1 parent 8b70af0 commit b31b881
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ media/c/m.scss

media/c/m.scss

*.sqlite
*.sqlite

vagrant_bootstrap.sh
Vagrantfile
2 changes: 1 addition & 1 deletion docs/example_app.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Clone the repo and run the included example django project::
Guide
-----

The example app utlizes a basic configuration with
The example app utilizes a basic configuration with
`django-registration
<https://bitbucket.org/ubernostrum/django-registration>`_ for
verifying emails. Therefore the list of views in
Expand Down
4 changes: 3 additions & 1 deletion hunger/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ def process_view(self, request, view_func, view_args, view_kwargs):
'django.contrib.staticfiles.views']

# All hunger views, except NotBetaView, are off limits until in beta
whitelisted_views = ['hunger.views.NotBetaView']
whitelisted_views = ['hunger.views.NotBetaView',
'hunger.views.verify_invite',
'hunger.views.InvalidView']

short_name = view_func.__class__.__name__
if short_name == 'function':
Expand Down
1 change: 1 addition & 0 deletions hunger/templates/hunger/invalid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
You have an invalid Invite Code.
5 changes: 5 additions & 0 deletions hunger/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from hunger.utils import setting, now
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormView
from django.contrib.auth.decorators import login_required


class InviteView(FormView):
Expand Down Expand Up @@ -55,7 +56,11 @@ class InviteSentView(TemplateView):
template_name = 'hunger/invite_sent.html'


@login_required

This comment has been minimized.

Copy link
@palm86

palm86 Aug 7, 2014

Contributor

Why is login required for this view? What if a completely non-existing user is invited by email? He would immediately be redirected to the login view. It would be best to display a welcome page to him and tell him to register...

def verify_invite(request, code):
"""
Verify new invitee by storing invite code in cookie for middleware to validate.
"""
response = redirect(setting('HUNGER_VERIFIED_REDIRECT'))
response.set_cookie('hunger_code', code)
return response
6 changes: 6 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,9 @@ def test_invite_existing_user_without_email(self):
response = self.client.get(reverse('invited_only'))
# Alice should be denied, since she has no connection with email account
self.assertEqual(response.status_code, 302)

def test_invalid_code(self):
invalid_code = 'XXXXinvalidcodeXXXX'
self.client.login(username='alice', password='secret')
response = self.client.get(reverse('hunger-verify', args=[invalid_code]), follow=True)
self.assertRedirects(response, reverse('hunger-invalid', args=[invalid_code]))

0 comments on commit b31b881

Please sign in to comment.