# Path: django_core/utils/validators.py
# def is_valid_email(value):
#     """Checks to see if the value is a valid email. Returns True if the email
#     is valid. Otherwise, False.
#     """
#     try:
#         validate_email(value)
#         return True
#     except ValidationError:
#         return False


from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
from django_core.utils.validators import is_valid_email
from __future__ import unicode_literals



class EmailOrUsernameBackend(ModelBackend):
    """Authentication backend to allow a user to login via email address or
    username.
    """

    def authenticate(self, username, password):
        """
        :param username: this is the email or username to check
        """
        # If username is an email address, then try to pull it up
        user = self.get_by_username_or_email(username)

        if not user:
            return None

        if user.check_password(password):
            return user

        return None

    def get_by_username_or_email(self, username_or_email):
        username_or_email = username_or_email.strip().lower()


# Path: django_core/utils/validators.py
# def is_valid_email(value):
#     """Checks to see if the value is a valid email. Returns True if the email
#     is valid. Otherwise, False.
#     """
#     try:
#         validate_email(value)
#         return True
#     except ValidationError:
#         return False


# Path: django_core/contrib/auth/backends.py
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import ModelBackend
from django_core.utils.validators import is_valid_email

from __future__ import unicode_literals



class EmailOrUsernameBackend(ModelBackend):
    """Authentication backend to allow a user to login via email address or
    username.
    """

    def authenticate(self, username, password):
        """
        :param username: this is the email or username to check
        """
        # If username is an email address, then try to pull it up
        user = self.get_by_username_or_email(username)

        if not user:
            return None

        if user.check_password(password):
            return user

        return None

    def get_by_username_or_email(self, username_or_email):
        username_or_email = username_or_email.strip().lower()


        if is_valid_email(username_or_email):