mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-03 15:41:06 -04:00
Valid email domains added and tests passing.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user