我是django的新手。我正在尝试根据LDAP服务器验证我的django。我看到了关于设置的django-ldap文档,并相应地配置了我的设置:
AUTH_LDAP_SERVER_URI = "ldap.forumsys.com"
AUTH_LDAP_BIND_DN = "cn=read-only-admin,dc=example,dc=com"
AUTH_LDAP_BIND_PASSWORD = "password"
AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=users,dc=example,dc=com",
ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
我的怀疑是1) 我的观点是什么。2) 我应该重新将我的url重定向到我的视图吗?3) 我该怎么办?
谢谢
我希望您已经在您的settings.py和其他相关配置中的AUTHENTICATION_BACKENDS中包含了'django_auth_ldap.backend.LDAPBackend'。您只需要使用
user=authenticate(username=user_name,password=password)对用户进行身份验证,在您的视图中,user_name和password是用于登录页面的表单
尝试:
nbsp nbsp;user=authenticate(username=username,password=password)
nbsp nbsp;如果用户不是"无":
nbsp nbsp nbsp nbsp nbsp nbsp;if user.is_active:
nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp auth.login(请求,用户)
nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp return HttpResponseRedirect('')
nbsp nbsp nbsp nbsp nbsp 其他:
nbsp nbsp nbsp nbsp nbsp nbsp nbsp 通过
,LDAError除外,如e:
nbsp nbsp nbsp nbsp nbsp;通过