Ejemplo n.º 1
0
def validate_email(value):
    from osf.models import BlacklistedEmailDomain
    with reraise_django_validation_errors():
        django_validate_email(value)
    domain = value.split('@')[1].lower()
    if BlacklistedEmailDomain.objects.filter(domain=domain).exists():
        raise BlacklistedEmailError('Invalid Email')
Ejemplo n.º 2
0
def validate_email(value):
    from osf.models import BlacklistedEmailDomain
    with reraise_django_validation_errors():
        django_validate_email(value)
    domain = value.split('@')[1].lower()
    if BlacklistedEmailDomain.objects.filter(domain=domain).exists():
        raise BlacklistedEmailError('Invalid Email')
Ejemplo n.º 3
0
def validate_email(email):
    """
    Validate email, the strict or the quick way depending on `FEATURES['EMAIL_STRICT_VERIFICATION']`.
    """
    is_strict = settings.FEATURES.get('EMAIL_STRICT_VERIFICATION', True)
    log.info(u'Validating user email=%(email)s, strict_verification=%(is_strict)s', {
        'email': email,
        'is_strict': is_strict,
    })

    if is_strict:
        is_valid = strict_validate_email(
            email=email,
            check_mx=True,
            debug=True,
        )
    else:
        try:
            django_validate_email(email)
            is_valid = True
        except DjangoValidationError:
            is_valid = False

    log.info(u'Validating user email=%(email)s, strict_verification=%(is_strict)s, is_valid=%(is_valid)s', {
        'email': email,
        'is_strict': is_strict,
        'is_valid': is_valid,
    })

    return is_valid
Ejemplo n.º 4
0
def validate_email_address(email):
    django_validate_email(email)

    if email.endswith('.'):
        raise ValidationError(
            'Email cannot end with \'.\' (dot), please check again')
    else:
        return True
Ejemplo n.º 5
0
def validate_email_address(email):
    django_validate_email(email)

    if email.endswith('.'):
        raise ValidationError(
            "email doesn't end by (.) dot, please input valid email")
    else:
        return True
Ejemplo n.º 6
0
def validate_email(value):
    """Validate a single email."""
    if not value:
        return False
    # Check the regex, using the validate_email from django.
    try:
        django_validate_email(value)
    except ValidationError:
        return False
Ejemplo n.º 7
0
def validate_email_address(email):
    try:
        django_validate_email(email)
    except ValidationError:
        raise ValidationError(f'{email} is not a valid email', code='invalid')

    if email.endswith('.'):
        raise ValidationError('Email cannot end with \'.\' (dot), please check again')
    else:
        return True
Ejemplo n.º 8
0
def validate_email(value):
    """Validate a single email."""
    if not value:
        return False
    # Check the regex, using the validate_email from django.
    try:
        django_validate_email(value)
    except ValidationError:
        return False
    else:
        # Check with the disposable list.
        return True
Ejemplo n.º 9
0
def validate_email(value):
    from osf.models import NotableEmailDomain
    with reraise_django_validation_errors():
        django_validate_email(value)
    domain = value.split('@')[1].lower()

    is_email_domain_blocked = NotableEmailDomain.objects.filter(
        domain=domain,
        note=NotableEmailDomain.Note.EXCLUDE_FROM_ACCOUNT_CREATION,
    ).exists()

    if is_email_domain_blocked:
        raise BlockedEmailError('Invalid Email')
Ejemplo n.º 10
0
def validate_email(value):
    """Validate a single email."""
    if not value:
        return False
    # Check the regex, using the validate_email from django.
    try:
        django_validate_email(value)
    except ValidationError:
        return False
    else:
        # Check with the disposable list.
        try:
            validate_disposable_email(value)
        except ValidationError:
            return False
        else:
            return True
Ejemplo n.º 11
0
def validate_email_address(emailaddress):
    """
    Checks if an email address is syntactically correct. Makes use
    of the django email-validator for consistency.

    Args:
        emailaddress (str): Email address to validate.

    Returns:
        bool: If this is a valid email or not.

    """
    try:
        django_validate_email(str(emailaddress))
    except DjangoValidationError:
        return False
    except Exception:
        # logger.log_trace()
        return False
    else:
        return True
Ejemplo n.º 12
0
def validate_voter(mobile, email, throw=True):
    if not mobile:
        django_validate_email(email)
        return

    if mobile:
        mobile = mobile.replace(' ', '')
        mobile = mobile.replace('-', '')
        if len(mobile) < 4 or not mobile[1:].isdigit or \
            (mobile[0] != '+' and not mobile[0].isdigit()):
                m = "Malformed mobile phone number: %s" % mobile
                if throw:
                    raise ValidationError(m)
                else:
                    return False
    try:
        django_validate_email(email)
    except ValidationError, e:
        if throw:
            raise e
        else:
            return False
Ejemplo n.º 13
0
def validate_email(email, validate_uniqueness=False, validate_existance=False):
    from django.core.validators import validate_email as django_validate_email
    from django.core.exceptions import ValidationError
    from rest_framework import serializers
    from talos.models import Principal

    email = email.lower()

    if not email_regex.match(email):
        raise serializers.ValidationError('E-mail address is ill-formed.',
                                          code=constants.EMAIL_INVALID_CODE)

    # Validate Uniqueness
    if validate_uniqueness:
        try:
            Principal.objects.get(email=email)
            raise serializers.ValidationError(
                'Principal with provided e-mail is already registered.',
                code=constants.EMAIL_USED_CODE)
        except Principal.DoesNotExist:
            pass

    # Validate non existance (User with this email should exists)
    if validate_existance:
        try:
            Principal.objects.get(email=email)
        except Principal.DoesNotExist:
            raise serializers.ValidationError(
                'Principal with provided email not exists',
                code=constants.EMAIL_INVALID_CODE)

    try:
        django_validate_email(email)
    except ValidationError:
        raise serializers.ValidationError('Email is invalid',
                                          code=constants.EMAIL_INVALID_CODE)

    return email
Ejemplo n.º 14
0
def validate_email(value):
    with reraise_django_validation_errors():
        django_validate_email(value)
    if value.split('@')[1].lower() in settings.BLACKLISTED_DOMAINS:
        raise ValidationError('Invalid Email')
def validate_email(email):
    return django_validate_email(email)
Ejemplo n.º 16
0
def validate_email(value):
    with reraise_django_validation_errors():
        django_validate_email(value)
    if value.split('@')[1].lower() in settings.BLACKLISTED_DOMAINS:
        raise BlacklistedEmailError('Invalid Email')