'Authenticate the facebook user by id OR facebook_email
We filter using an OR to allow existing members to connect with
their facebook ID using email.
This decorator works with django\'s custom user model
:param facebook_id:
Optional string representing the facebook id.
:param facebook_email:
Optional string with the facebook email.
:return: The signed in :class:`User`.'

def user_authenticate(self, facebook_id=None, facebook_email=None):

    user_model = get_user_model()
    if (facebook_id or facebook_email):
        auth_conditions = []
        if facebook_id:
            auth_conditions.append(Q(facebook_id=facebook_id))
        if facebook_email:
            auth_conditions.append(Q(email__iexact=facebook_email))
        auth_condition = reduce(operator.or_, auth_conditions)
        users = list(user_model.objects.filter(auth_condition))
        id_matches = [u for u in users if (u.facebook_id == facebook_id)]
        email_matches = [u for u in users if (u.facebook_id != facebook_id)]
        if (len(id_matches) > 1):
            raise ValueError(('found    multiple    facebook    id    matches.    this    shouldnt    be    allowed,    check    your    unique    constraints.    users    found    %s' % users))
        user = None
        if id_matches:
            user = id_matches[0]
        elif email_matches:
            user = email_matches[0]
        if (user and facebook_settings.FACEBOOK_FORCE_PROFILE_UPDATE_ON_LOGIN):
            user.fb_update_required = True
        return user
