summaryrefslogtreecommitdiff
path: root/app/lttr/validators.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2019-02-11 13:51:21 -0600
committerluxagraf <sng@luxagraf.net>2019-02-11 13:51:21 -0600
commitee2803d2f85888ce42fd6371ef606f4a9c6fd88b (patch)
treed115dcdc3e4cf5640c0cd5f216bafe880f3c5574 /app/lttr/validators.py
parente7d938a42424fd31d36d7cfdd1533d87f236b05a (diff)
added newsletter
Diffstat (limited to 'app/lttr/validators.py')
-rw-r--r--app/lttr/validators.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/lttr/validators.py b/app/lttr/validators.py
new file mode 100644
index 0000000..754df3b
--- /dev/null
+++ b/app/lttr/validators.py
@@ -0,0 +1,18 @@
+from django.contrib.auth import get_user_model
+from django.forms.utils import ValidationError
+from django.utils.translation import ugettext_lazy as _
+
+
+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 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})