Files
edx-platform/common/djangoapps/third_party_auth/utils.py
2019-07-19 10:02:38 -04:00

32 lines
785 B
Python

"""
Utility functions for third_party_auth
"""
from __future__ import absolute_import
from django.contrib.auth.models import User
def user_exists(details):
"""
Return True if user with given details exist in the system.
Arguments:
details (dict): dictionary containing user infor like email, username etc.
Returns:
(bool): True if user with given details exists, `False` otherwise.
"""
user_queryset_filter = {}
email = details.get('email')
username = details.get('username')
if email:
user_queryset_filter['email'] = email
elif username:
user_queryset_filter['username__iexact'] = username
if user_queryset_filter:
return User.objects.filter(**user_queryset_filter).exists()
return False