Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions django_python3_ldap/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
from django_python3_ldap.conf import settings
from django_python3_ldap.utils import import_func, format_search_filter


logger = logging.getLogger(__name__)


class Connection(object):

"""
A connection to an LDAP server.
"""
Expand Down Expand Up @@ -46,11 +44,9 @@ def _get_or_create_user(self, user_data):

# Create the user data.
user_fields = {
field_name: (
attributes[attribute_name][0]
if isinstance(attributes[attribute_name], (list, tuple)) else
attributes[attribute_name]
)
field_name: attributes[attribute_name][0]
if len(attributes[attribute_name]) == 1
else attributes[attribute_name]
for field_name, attribute_name
in settings.LDAP_AUTH_USER_FIELDS.items()
if attribute_name in attributes
Expand Down Expand Up @@ -219,7 +215,7 @@ def connection(**kwargs):
)
settings_password = settings.LDAP_AUTH_CONNECTION_PASSWORD
if (settings_username or settings_password) and (
settings_username != username or settings_password != password
settings_username != username or settings_password != password
):
c.rebind(
user=settings_username,
Expand Down
4 changes: 4 additions & 0 deletions django_python3_ldap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def clean_user_data(model_fields):
Transforms the user data loaded from
LDAP into a form suitable for creating a user.
"""
for field in model_fields:
if isinstance(model_fields[field], (list, tuple)):
model_fields[field] = model_fields[field][0]

return model_fields


Expand Down