add simple email validator to form to prevent spam
This commit is contained in:
parent
c54c37b10e
commit
b34cf05497
|
@ -1,4 +1,6 @@
|
|||
from re import match as re_match
|
||||
from re import fullmatch as re_fullmatch
|
||||
from re import compile as re_compile
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import StringField, BooleanField
|
||||
from wtforms.validators import DataRequired, ValidationError
|
||||
|
@ -11,6 +13,12 @@ class Register(FlaskForm):
|
|||
terms_reviewed = BooleanField('Terms Reviewed:', validators=[DataRequired()], render_kw={"class": "form-control-span"})
|
||||
privacy_reviewed = BooleanField('Privacy Policy Reviewed:', validators=[DataRequired()], render_kw={"class": "form-control-span"})
|
||||
|
||||
def validate_email(self, email):
|
||||
regex = re_compile(r'([A-Za-z0-9]+[.-_])*[A-Za-z0-9]+@[A-Za-z0-9-]+(\.[A-Z|a-z]{2,})+')
|
||||
if not re_fullmatch(regex, self.email.data):
|
||||
raise ValidationError('This appears to be an invalid email. Contact admins if you feel this is incorrect.')
|
||||
|
||||
|
||||
class Login(FlaskForm):
|
||||
email = StringField('Email Address:', validators=[DataRequired()], render_kw={"placeholder": "Email", "class": "form-control", "type": "email"})
|
||||
password = StringField('Password:', validators=[DataRequired()], render_kw={"placeholder": "Password", "class": "form-control", "type": "password"})
|
||||
|
|
Loading…
Reference in New Issue