Created
November 8, 2017 10:27
-
-
Save etianen/b7535ca5c6f45efa3b540bb92ae8b518 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django_python3_ldap import ldap | |
from django.contrib.auth.decorators import login_required | |
@login_required | |
def ldap_seach(request): | |
# Because of login_required, this view is protected by the Django login screen. | |
# request.user will be the logged-in user. | |
if request.method == "POST": | |
# The user has submitted the search form of the user to look up. | |
username_to_look_up = request.post["username"] | |
# We are using an anonymous LDAP connection to search for the user. | |
# If your LDAP server requires authentication to look up users, then | |
# you need to hardcode a username and password here, like: | |
# with ldap.connection(username="foo", password="bar"). | |
with ldap.connection() as connection: | |
# Look up the user by username. | |
user = connectino.get_user(username=username_to_look_up) | |
print(user) | |
return render(request, "ldap_search.html") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment