From 5c46e19aaae3e2b7c78a3c03e02a21d3ad8943ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexis=20M=C3=A9taireau?= Date: Sun, 5 Aug 2018 15:45:33 +0200 Subject: [PATCH] Fix email validation when sending invites --- CHANGELOG.rst | 1 + ihatemoney/forms.py | 7 +++++-- requirements.txt | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 382e8897..7947b1a4 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,7 @@ Fixed - Fix the generation of the supervisord template (#309) - Fix the validation of the hashed password (#310) - Fix infinite loop that happened when accessing / (#358) +- Fix email validation when sending invites Added ===== diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 3966891c..de9004d5 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -10,6 +10,8 @@ from werkzeug.security import generate_password_hash from datetime import datetime from jinja2 import Markup +import email_validator + from ihatemoney.models import Project, Person from ihatemoney.utils import slugify @@ -184,9 +186,10 @@ class InviteForm(FlaskForm): submit = SubmitField(_("Send invites")) def validate_emails(form, field): - validator = Email() for email in [email.strip() for email in form.emails.data.split(",")]: - if not validator.regex.match(email): + try: + email_validator.validate_email(email) + except email_validator.EmailNotValidError as e: raise ValidationError(_("The email %(email)s is not valid", email=email)) diff --git a/requirements.txt b/requirements.txt index c2fe5348..964d7fc5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ raven blinker six>=1.10 itsdangerous>=0.24 +email_validator>=1.0