This should be combined with the logic below since if only one of the `SHARE_` settings is enabled, looking up by both fields would not be conforming to the setting.

```python
if not settings.SHARE_BY_USERNAME and not settings.SHARE_BY_EMAIL:
    return False

q = Q()

if settings.SHARE_BY_USERNAME:
    if settings.SHARE_BY_USERNAME_CASE_SENSITIVE:
        q |= Q(username=username_or_email)
    else:
        q |= Q(username__iexact=username_or_email)

if settings.SHARE_BY_EMAIL:
    q |= Q(email__iexact=username_or_email)

try:
    user = User.objects.get(q)
except User.DoesNotExist:
    user = None

# continue...
```