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

Adds VALIDATE_USER setting config, if False then don't check email in User model #370

Closed
wants to merge 2 commits into from
Closed
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
13 changes: 13 additions & 0 deletions newsletter/settings.py
Original file line number Diff line number Diff line change
@@ -66,6 +66,7 @@ class NewsletterSettings(Settings):
settings_prefix = 'NEWSLETTER'

DEFAULT_CONFIRM_EMAIL = True
DEFAULT_VALIDATE_USER = True

@property
def DEFAULT_CONFIRM_EMAIL_SUBSCRIBE(self):
@@ -137,4 +138,16 @@ def THUMBNAIL(self):
"'%s' is not a supported thumbnail application." % THUMBNAIL
)

@property
def VALIDATE_USER(self):
validate_user = getattr(
django_settings, "NEWSLETTER_VALIDATE_USER", ""
)

if validate_user:
return validate_user
else:
return self.DEFAULT_VALIDATE_USER


newsletter_settings = NewsletterSettings()
19 changes: 11 additions & 8 deletions newsletter/validators.py
Original file line number Diff line number Diff line change
@@ -2,17 +2,20 @@
from django.forms.utils import ValidationError
from django.utils.translation import gettext_lazy as _

from newsletter.settings import newsletter_settings


def validate_email_nouser(email):
"""
Check if the email address does not belong to an existing user.
"""
# Check whether we should be subscribed to as a user
User = get_user_model()
if newsletter_settings.VALIDATE_USER:
# Check whether we should be subscribed to as a user
User = get_user_model()

if User.objects.filter(email__exact=email).exists():
raise ValidationError(_(
"The e-mail address '%(email)s' belongs to a user with an "
"account on this site. Please log in as that user "
"and try again."
) % {'email': email})
if User.objects.filter(email__exact=email).exists():

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be email__iexact? Because "[email protected]" and "[email protected]' would be the same user.

raise ValidationError(_(
"The e-mail address '%(email)s' belongs to a user with an "
"account on this site. Please log in as that user "
"and try again."
) % {'email': email})