Valid email domains added and tests passing.

This commit is contained in:
Nicholas Staples
2016-03-18 12:05:50 +00:00
parent 11db35f9bd
commit 8a203c0155
11 changed files with 77 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
import re
from wtforms import ValidationError
from datetime import datetime
from app.main.encryption import check_hash
@@ -22,3 +23,18 @@ class CsvFileValidator(object):
def __call__(self, form, field):
if not form.file.data.mimetype == 'text/csv':
raise ValidationError(self.message)
class ValidEmailDomainRegex(object):
def __call__(self, form, field):
from flask import (current_app, url_for)
message = (
'Enter a central government email address.'
' If you think you should have access'
' <a href="{}">contact us</a>').format(
"https://docs.google.com/forms/d/1AL8U-xJX_HAFEiQiJszGQw0PcEaEUnYATSntEghNDGo/viewform")
valid_domains = current_app.config.get('EMAIL_DOMAIN_REGEXES', [])
email_regex = "(^[^@^\\s]+@[^@^\\.^\\s]+(\\.[^@^\\.^\\s]*)*.({}))".format("|".join(valid_domains))
if not re.match(email_regex, field.data):
raise ValidationError(message)