Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add REQUIRE_EMAIL_CONFIRM setting #7

Merged
merged 2 commits into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ media/
.cache/
.tox/
.coverage
.idea
*.iml
.DS_Store
3 changes: 2 additions & 1 deletion spongeauth/accounts/middleware.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.urls import resolve
from django.shortcuts import redirect
from django.conf import settings
import django.urls.exceptions


Expand All @@ -16,7 +17,7 @@ def __call__(self, request):

@staticmethod
def must_verify(user):
return user.is_authenticated() and not user.email_verified
return user.is_authenticated() and not user.email_verified and settings.REQUIRE_EMAIL_CONFIRM

@staticmethod
def may_pass(url):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def test_email_not_verified(self):
email_verified=False)
assert middleware.EnforceVerifiedEmails.must_verify(user)

@django.test.override_settings(REQUIRE_EMAIL_CONFIRM=False)
def test_setting_require_email_confirm(self):
user = accounts.tests.factories.UserFactory.build(email_verified=False)
assert not middleware.EnforceVerifiedEmails.must_verify(user)


@django.test.override_settings(ROOT_URLCONF='accounts.tests.test_middleware_enforce_verified_emails')
class TestMayPass(django.test.SimpleTestCase):
Expand Down
5 changes: 3 additions & 2 deletions spongeauth/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def register(request):
# _log_user_in must happen before sending the email, since the token
# will change after the user has been logged in.
resp = _log_user_in(request, user)
_send_verify_email(request, user)
if django_settings.REQUIRE_EMAIL_CONFIRM:
_send_verify_email(request, user)
return resp

return render(request, 'accounts/register.html', {'form': form})
Expand Down Expand Up @@ -251,7 +252,7 @@ def register_google(request):

if user:
resp = _log_user_in(request, user, skip_twofa=True)
if not user.email_verified:
if not user.email_verified and django_settings.REQUIRE_EMAIL_CONFIRM:
# This must happen /after/ _log_user_in.
_send_verify_email(request, user)
return resp
Expand Down
Empty file removed spongeauth/media/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions spongeauth/spongeauth/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
'auth.spongepowered.org',
]

REQUIRE_EMAIL_CONFIRM = True


# Application definition

Expand Down
1 change: 1 addition & 0 deletions spongeauth/spongeauth/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
DEBUG = True
ALLOWED_HOSTS += ['localhost', '127.0.0.1', '::1']
INTERNAL_IPS = ['127.0.0.1', '::1']
REQUIRE_EMAIL_CONFIRM = False

MIDDLEWARE = [
'debug_toolbar.middleware.DebugToolbarMiddleware',
Expand Down