I've set up Flask-Security and I'm trying to an e-mail to be validated against lists in a database. I want to keep the current email validators and add a new one.
Below is the code that I'm adding to extend the registration form. But I'm not getting it to work at all the validator is just ignored. I've tried
- Changing DataRequired to Input Required,
- changing form to self.
- Adding a print statement in the validator but it doesn't seem to run at all. It is just being ignored
- change StringField to EmailField
class ExtendedRegisterForm(RegisterForm):
email = StringField('Email', validators=[DataRequired()])
def validate_email(form, field):
domain = field.data.split('@')[1]
regdomains = db.session.query(Company.id, Company.domain).filter(Company.domain != None).all()
for row in regdomains:
valid = (row.domain).find(domain)
if valid != -1:
validated = True
else:
continue
if validated is not True:
raise ValidationError('Email address must be from an authorised domain')
security = Security(app, user_datastore, register_form=ExtendedRegisterForm)