Files
edx-platform/common/djangoapps/third_party_auth/utils.py
Brittney Exline 550d2616b5 ENT-1500 Update third_party_auth pipeline to override get_username
We are doing this for two reasons:
1. We suspect that the get_username function in social_core is performing a case-sensitive
username check which is breaking when we try to create the user with a duplicate username.
This version ensures we perform a case insensitive check.

2. If it's not that, we want more logging information in order to debug the issue.
2019-03-19 17:01:29 -04:00

30 lines
745 B
Python

"""
Utility functions for third_party_auth
"""
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