我一个项目,LDAP认证在现有的Django应用程序集成工作。使用这个网站和其他网站,我终于可以使用django_auth_ldap后端正确配置所有内容。包括:的Python,Django的LDAP:检测认证失败的推理
AUTH_LDAP_REQUIRE_GROUP = "CN=myGroup,CN=groups [...] "
组因此,只有用户“为myGroup”可以登录
一切都正确,现在在settings.py和USER_LOGIN视图内配置有刚:
...
user = authenticate(username=username, password=password)
if user:
if user.is_active:
login(request, user)
return redirect('index')
else:
message = "Your account is disabled."
else:
message = "Invalid username or password supplied."
...
现在,最后一步必须是向用户发送通知,告诉他为什么他的登录失败。现在失败消息将始终为:“提供的用户名或密码无效。” 这应该是:
- 错误的用户名/密码
- 不正确的组
喜欢的东西在:
if user:
...
else:
if (LDAP auth failed reason == user does not satisfy AUTH_LDAP_REQUIRE_GROUP):
message = "You are not in the right user group."
else:
message = "Invalid username or password supplied."
...
我怎么能知道,在我的USER_LOGIN查看LDAP的原因验证失败?
P.S:在django_auth_ldap登录我看到“DEBUG验证失败名:用户不满足AUTH_LDAP_REQUIRE_GROUP”
但如何在USER_LOGIN视图知道这一点?