Python wtforms.validators.Email() Examples

The following are 30 code examples of wtforms.validators.Email(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wtforms.validators , or try the search function .
Example #1
Source File: forms.py    From comport with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
def validate(self):
        initial_validation = super(RegisterForm, self).validate()
        if not initial_validation:
            return False
        user = User.query.filter_by(username=self.username.data).first()
        if user:
            self.username.errors.append("Username already registered")
            return False
        user = User.query.filter_by(email=self.email.data).first()
        if user:
            self.email.errors.append("Email already registered")
            return False
        found_invite_code = Invite_Code.query.filter_by(code=self.invite_code.data).first()
        if not found_invite_code:
            self.invite_code.errors.append("Invite Code not recognized.")
            return False
        if found_invite_code.used:
            self.invite_code.errors.append("Invite Code has already been used.")
            return False
        return True 
Example #2
Source File: models.py    From GeoHealthCheck with MIT License 6 votes vote down vote up
def _validate_email(value):
    if not value:
        raise ValidationError("Email cannot be empty value")
    try:
        if not value.strip():
            raise ValidationError("Email cannot be empty value")
    except AttributeError:
        raise ValidationError("Email cannot be empty value")

    v = Email()

    class dummy_value(object):
        data = value

        @staticmethod
        def gettext(*args, **kwargs):
            return _(*args, **kwargs)

    dummy_form = None
    v(dummy_form, dummy_value()) 
Example #3
Source File: forms.py    From MegaQC with GNU General Public License v3.0 6 votes vote down vote up
def validate(self):
        """
        Validate the form.
        """
        initial_validation = super(AdminForm, self).validate()
        if not initial_validation:
            return False
        user = User.query.filter_by(username=self.username.data).first()
        if user and user.user_id != self.user_id.data:
            self.username.errors.append("Username already registered")
            return False
        user = User.query.filter_by(email=self.email.data).first()
        if user and user.user_id != self.user_id.data:
            self.email.errors.append("Email already registered")
            return False
        return True 
Example #4
Source File: forms.py    From MegaQC with GNU General Public License v3.0 6 votes vote down vote up
def validate(self):
        """
        Validate the form.
        """
        initial_validation = super(RegisterForm, self).validate()
        if not initial_validation:
            return False
        user = User.query.filter_by(username=self.username.data).first()
        if user:
            self.username.errors.append("Username already registered")
            return False
        user = User.query.filter_by(email=self.email.data).first()
        if user:
            self.email.errors.append("Email already registered")
            return False
        return True 
Example #5
Source File: utils.py    From flask-security with MIT License 6 votes vote down vote up
def uia_email_mapper(identity):
    """ Used to match identity as an email.

    See :py:data:`SECURITY_USER_IDENTITY_ATTRIBUTES`.

    .. versionadded:: 3.4.0
    """

    # Fake up enough to invoke the WTforms email validator.
    class FakeField:
        pass

    email_validator = validators.Email(message="nothing")
    field = FakeField()
    field.data = identity
    try:
        email_validator(None, field)
    except ValidationError:
        return None
    return identity 
Example #6
Source File: forms.py    From Flask-User with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)
        user_manager =  current_app.user_manager
        if user_manager.USER_ENABLE_USERNAME and user_manager.USER_ENABLE_EMAIL:
            # Renamed 'Username' label to 'Username or Email'
            self.username.label.text = _('Username or Email') 
Example #7
Source File: forms.py    From gitmark with GNU General Public License v2.0 5 votes vote down vote up
def validate_email(self, field):
        users = models.User.objects.filter(email=field.data)
        if users.count() > 0 and users[0].id != current_user.id:
            raise ValidationError('Email already in registered') 
Example #8
Source File: forms.py    From braindump with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #9
Source File: forms.py    From penn-club-ratings with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #10
Source File: forms.py    From penn-club-ratings with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #11
Source File: forms.py    From penn-club-ratings with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered. (Did you mean to '
                                  '<a href="{}">log in</a> instead?)'.format(
                                      url_for('account.login'))) 
Example #12
Source File: forms.py    From penn-club-ratings with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #13
Source File: forms.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if field.data != self.user.email and \
                User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #14
Source File: forms.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #15
Source File: forms.py    From flasky-first-edition with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #16
Source File: forms.py    From Flask-User with MIT License 5 votes vote down vote up
def unique_email_validator(form, field):
    """ Username must be unique. This validator may NOT be customized."""
    user_manager =  current_app.user_manager
    if not user_manager.email_is_available(field.data):
        raise ValidationError(_('This Email is already in use. Please try another one.'))


# ***********
# ** Forms **
# *********** 
Example #17
Source File: forms.py    From BhagavadGita with GNU General Public License v3.0 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #18
Source File: forms.py    From Flask-User with MIT License 5 votes vote down vote up
def validate_email(form, field):
        user_manager =  current_app.user_manager
        if user_manager.USER_SHOW_EMAIL_DOES_NOT_EXIST:
            user, user_email = user_manager.db_manager.get_user_and_user_email_by_email(field.data)
            if not user:
                raise ValidationError(_('%(username_or_email)s does not exist', username_or_email=_('Email'))) 
Example #19
Source File: user_admin.py    From flask-react-spa with MIT License 5 votes vote down vote up
def get_create_form(self):
        CreateForm = super().get_create_form()

        CreateForm.email = html5.EmailField(
            'Email',
            validators=[
                validators.DataRequired(),
                validators.Email(),
                unique_user_email,
            ],
        )
        CreateForm.password = fields.PasswordField(
            'Password',
            validators=[
                validators.DataRequired(),
                password_length,
            ],
        )
        CreateForm.confirm_password = fields.PasswordField(
            'Confirm Password',
            validators=[
                validators.DataRequired(),
                EqualTo('password', message='RETYPE_PASSWORD_MISMATCH'),
            ],
        )

        CreateForm.field_order = (
            'username', 'email', 'first_name', 'last_name',
            'password', 'confirm_password', 'roles', 'active')

        return CreateForm 
Example #20
Source File: forms.py    From flask-base with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered. (Did you mean to '
                                  '<a href="{}">log in</a> instead?)'.format(
                                    url_for('account.login'))) 
Example #21
Source File: forms.py    From flask-base with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #22
Source File: forms.py    From docassemble with MIT License 5 votes vote down vote up
def da_unique_email_validator(form, field):
    if daconfig['ldap login'].get('enable', False) and daconfig['ldap login'].get('base dn', None) is not None and daconfig['ldap login'].get('bind email', None) is not None and daconfig['ldap login'].get('bind password', None) is not None:
        ldap_server = daconfig['ldap login'].get('server', 'localhost').strip()
        base_dn = daconfig['ldap login']['base dn'].strip()
        search_filter = daconfig['ldap login'].get('search pattern', "mail=%s") % (form.email.data,)
        connect = ldap.initialize('ldap://' + ldap_server)
        try:
            connect.simple_bind_s(daconfig['ldap login']['bind email'], daconfig['ldap login']['bind password'])
            if len(connect.search_s(base_dn, ldap.SCOPE_SUBTREE, search_filter)) > 0:
                raise ValidationError(word("This Email is already in use. Please try another one."))
        except ldap.LDAPError:
            pass
    if daconfig.get('confirm registration', False):
        return True
    return unique_email_validator(form, field) 
Example #23
Source File: forms.py    From flasky-with-celery with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if field.data != self.user.email and \
                User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #24
Source File: forms.py    From flasky-with-celery with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #25
Source File: forms.py    From flasky-with-celery with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #26
Source File: forms.py    From flask-registration with MIT License 5 votes vote down vote up
def validate(self):
        initial_validation = super(RegisterForm, self).validate()
        if not initial_validation:
            return False
        user = User.query.filter_by(email=self.email.data).first()
        if user:
            self.email.errors.append("Email already registered")
            return False
        return True 
Example #27
Source File: form_class.py    From cve-portal with GNU Affero General Public License v3.0 5 votes vote down vote up
def validate_email(self, field):
        if models.User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #28
Source File: forms.py    From thewarden with MIT License 5 votes vote down vote up
def validate_email(self, email):
        if email.data != current_user.email:
            user = User.query.filter_by(email=email.data).first()
            if user:
                raise ValidationError("\
                Email already exists. Use a different one.") 
Example #29
Source File: forms.py    From circleci-demo-python-flask with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if field.data != self.user.email and \
                User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.') 
Example #30
Source File: forms.py    From circleci-demo-python-flask with MIT License 5 votes vote down vote up
def validate_email(self, field):
        if User.query.filter_by(email=field.data).first():
            raise ValidationError('Email already registered.')