Skip to content

Commit

Permalink
Add docs, fix bug where LOGIN_REDIRECT_URL always used (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshblum authored Oct 4, 2017
1 parent 9881217 commit bfd0460
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ your project, and specifying one additional setting:
Optional. If this is `True`, your users will automatically log in when they
click on the activation link in their email. Defaults to `False`.

``ACCOUNT_AUTHENTICATED_REGISTRATION_REDIRECTS``
Optional. If this is `True`, your users will automatically be
redirected to ``LOGIN_REDIRECT_URL`` when trying to access the
``RegistrationView``. Defaults to `True`.

For example, you might have something like the following in your
Django settings file::

Expand Down
10 changes: 6 additions & 4 deletions registration/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
REGISTRATION_FORM_PATH = getattr(settings, 'REGISTRATION_FORM',
'registration.forms.RegistrationForm')
REGISTRATION_FORM = import_string(REGISTRATION_FORM_PATH)
ACCOUNT_AUTHENTICATED_REGISTRATION_REDIRECTS = getattr(settings, 'ACCOUNT_AUTHENTICATED_REGISTRATION_REDIRECTS', True)
ACCOUNT_AUTHENTICATED_REGISTRATION_REDIRECTS = getattr(
settings, 'ACCOUNT_AUTHENTICATED_REGISTRATION_REDIRECTS', True)


class RegistrationView(FormView):
Expand All @@ -42,10 +43,11 @@ def dispatch(self, request, *args, **kwargs):
if settings.LOGIN_REDIRECT_URL is not None:
return redirect(settings.LOGIN_REDIRECT_URL)
else:
raise Exception("You must set a URL with LOGIN_REDIRECT_URL in settings.py or set ACCOUNT_AUTHENTICATED_REGISTRATION_REDIRECTS=False")
raise Exception((
'You must set a URL with LOGIN_REDIRECT_URL in '
'settings.py or set '
'ACCOUNT_AUTHENTICATED_REGISTRATION_REDIRECTS=False'))

if self.request.user.is_authenticated():
return redirect(settings.LOGIN_REDIRECT_URL)
if not self.registration_allowed():
return redirect(self.disallowed_url)
return super(RegistrationView, self).dispatch(request, *args, **kwargs)
Expand Down

0 comments on commit bfd0460

Please sign in to comment.