2016-03-18 12:05:50 +00:00
|
|
|
import re
|
2015-12-01 15:51:09 +00:00
|
|
|
from wtforms import ValidationError
|
2016-01-07 12:43:10 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
from app.main.encryption import check_hash
|
2015-12-01 15:51:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Blacklist(object):
|
|
|
|
|
def __init__(self, message=None):
|
|
|
|
|
if not message:
|
|
|
|
|
message = 'Password is blacklisted.'
|
|
|
|
|
self.message = message
|
|
|
|
|
|
|
|
|
|
def __call__(self, form, field):
|
|
|
|
|
if field.data in ['password1234', 'passw0rd1234']:
|
|
|
|
|
raise ValidationError(self.message)
|
2016-01-07 12:43:10 +00:00
|
|
|
|
|
|
|
|
|
2016-01-11 15:00:51 +00:00
|
|
|
class CsvFileValidator(object):
|
|
|
|
|
|
|
|
|
|
def __init__(self, message='Not a csv file'):
|
|
|
|
|
self.message = message
|
|
|
|
|
|
|
|
|
|
def __call__(self, form, field):
|
|
|
|
|
if not form.file.data.mimetype == 'text/csv':
|
|
|
|
|
raise ValidationError(self.message)
|
2016-03-18 12:05:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|