I have problem with authentication users in my django app. I am using Python 3.5 and Django 1.10.
I wrote simple bind configuration to check if user is realy user from database:
username = request.POST['username']
password = request.POST['password']
server = Server(LDAP_AUTH_URL)
c = Connection(server, user=LDAP_AUTH_CONNECTION_USERNAME, password=LDAP_AUTH_CONNECTION_PASSWORD)
c.open()
c.bind()
if c.bind():
user_search_filter = '(uid={})'.format(username)
c.search(search_base=LDAP_AUTH_SEARCH_BASE,
search_filter=user_search_filter,
search_scope=SUBTREE)
username = c.response[0]['dn']
if c.rebind(user=username, password=password):
return HttpResponseRedirect(next)
but now I don't know what to do with it, in django we have of course something like this:
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
auth.login(request, user)
return HttpResponseRedirect(next)
else:
return render(request, 'login.html', {'error_message': 'Your account has been disabled'})
else:
return render(request, 'login.html', {'error_message': 'Invalid login'})
but in this situation we have to have user account in our base not from ldap authorization.
so I would like to get authorization from django when I am logging by ldap to have access to any other view with "@login_required"
Maybe something is wrong with my thinking about ldap and ldap3 for Python >3.
Anybody can help me or give me usefull links?