Skip to content

Commit

Permalink
Merge c6b70f1 into c4ac9b2
Browse files Browse the repository at this point in the history
  • Loading branch information
windy1 committed Jan 16, 2017
2 parents c4ac9b2 + c6b70f1 commit 8ffeaa5
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 4 deletions.
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
5 changes: 3 additions & 2 deletions 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,13 +17,13 @@ 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):
try:
return getattr(
resolve(url).func, 'allow_without_verified_email', False)
resolve(url).func, 'allow_without_verified_email', False) or not settings.REQUIRE_EMAIL_CONFIRM
except django.urls.exceptions.Resolver404:
return False

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
2 changes: 2 additions & 0 deletions spongeauth/spongeauth/settings/prod.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

SECRET_KEY = os.environ['SECRET_KEY']

REQUIRE_EMAIL_CONFIRM = True

DEFAULT_FROM_EMAIL = 'admin@spongepowered.org'
SERVER_EMAIL = 'admin@spongepowered.org'

Expand Down

0 comments on commit 8ffeaa5

Please sign in to comment.