pip3 install django-auth-ldap python-ldap

urls.py,

from app0104 import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^loginauth/', views.loginauth),
url(r'^index/', views.index),
]

index.html,

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>fuck,{{ usergo }}</h1>
</body>
</html>

loginauth.html,

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form class="formone" action="/loginauth/" method="post">
<input type="text" name="name" />
<input type="password" name="password" />
<input type="submit" value="ss" />
</form> {{ context.errors_list }}
{{ context.user_loggedin }} </body>
</html>

views.py,

from django.shortcuts import render,HttpResponseRedirect

# Create your views here.

from django.contrib.auth import authenticate, login as auth_login, logout as auth_logout
from django.contrib.auth.models import User name = '' def loginauth(request): user_loggedin = 'Guest'
errors_list = []
if request.method == 'POST':
print('pp: ', request.POST.get('name'), request.POST.get('password'))
global name
name = request.POST.get('name')
password = request.POST.get('password')
usergo = authenticate(username=name, password=password) print('authuser', usergo)
if usergo is not None:
auth_login(request, usergo)
uu = request.user
loginusername = usergo
u = User.objects.get(username=uu)
return HttpResponseRedirect("/index/") context = {'errors_list': errors_list, 'user_loggedin': user_loggedin}
return render(request, 'loginauth.html', context) def index(request):
print('last:',name)
return render(request,'index.html',{'usergo':name})

settings.py,

import os

import ldap
#LDAP configurationimport ldap
from django_auth_ldap.config import LDAPSearch
AUTHENTICATION_BACKENDS = (
'django_auth_ldap.backend.LDAPBackend',
'django.contrib.auth.backends.ModelBackend',
)
# base_dn = 'dc=example,dc=com'
# AUTH_LDAP_SERVER_URI = 'ldap://192.168.187.55:389'
# AUTH_LDAP_BIND_DN = 'cn=admin,dc=example,dc=com'
# AUTH_LDAP_BIND_PASSWORD = "123456"
#
# # 用户的DN是uid=caojun,ou=People,dc=ldap,dc=ssotest,dc=net,所以用uid
# AUTH_LDAP_USER_SEARCH = LDAPSearch('ou=People,dc=example,dc=com', ldap.SCOPE_SUBTREE, "(uid=%(user)s)") basedn = "OU=fds,DC=ddd,DC=com"
AUTH_LDAP_SERVER_URI = 'ldap://192.112.250.140:31338'
AUTH_LDAP_BIND_DN = 'CN=Admin.BJSHOP,OU=dfd_Admin,OU=AdminAccounts,OU=Applications,DC=sf,DC=com'
AUTH_LDAP_BIND_PASSWORD = "dddw33rewq" # 用户的DN是uid=caojun,ou=People,dc=ldap,dc=ssotest,dc=net,所以用uid
AUTH_LDAP_USER_SEARCH = LDAPSearch('OU=ddd,DC=dd,DC=com', ldap.SCOPE_SUBTREE, "(sAMAccountName=%(user)s)") AUTH_LDAP_USER_ATTR_MAP = {
"first_name": "givenName",
"last_name": "sn",
"email": "mail"
}

django使用ldap认证的更多相关文章

  1. Django集成OpenLDAP认证

    本文详细介绍了django-auth-ldap的使用方法,参数含义,并提供了示例代码 版本说明 Django==2.2 django-auth-ldap==1.7.0 集成过程 Django集成LDA ...

  2. 07: Django 使用ldap登录、注销等

    目录:Django其他篇 01:Django基础篇 02:Django进阶篇 03:Django数据库操作--->Model 04: Form 验证用户数据 & 生成html 05:Mo ...

  3. django使用LDAP验证

    1.安装Python-LDAP(python_ldap-2.4.25-cp27-none-win_amd64.whl)pip install python_ldap-2.4.25-cp27-none- ...

  4. Django自定义用户认证系统之自定义用户模型

    参考文档:http://python.usyiyi.cn/django/topics/auth/customizing.html Django 自带的认证系统足够应付大多数情况,但你或许不打算使用现成 ...

  5. 将Python的Django框架与认证系统整合的方法

    将Python的Django框架与认证系统整合的方法 这篇文章主要介绍了将Python的Django框架与认证系统整合的方法,包括指定认证后台和编写认证后台等内容,需要的朋友可以参考下 将Django ...

  6. No.2 CAS之SPNEGO+LDAP认证配置

    1.概述 本文先配置了SPNEGO认证,就是如果用户操作系统如果登陆了公司的Windows域,用户浏览器访问应用服务即可免登录. 然后如果不在域里的员工,用LDAP认证方式,输账号密码登陆. 参考文档 ...

  7. Jenkins-配置LDAP认证

    Jenkins-配置LDAP认证 参考文档: LDAP添加用户详见我的博文  Linux分类 中的< LDAP2-创建OU和用户>博文. 1.LDAP配置 1.准备一个adminDN账号用 ...

  8. Django组件之认证系统

      Django自带的用户认证 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能,这还真是个麻烦的事情呢. Dja ...

  9. Django Rest Framework(认证、权限、限制访问频率)

    阅读原文Django Rest Framework(认证.权限.限制访问频率) django_rest_framework doc django_redis cache doc

随机推荐

  1. C#面向对象特征的具体实现及作用详解

    转自:http://www.jb51.net/article/42390.htm 众所周知,面向对象编程的特点为:封装.继承.多态.C#是一门完全面向对象的语言,由于比Java推出的时间还要晚,所以对 ...

  2. 常用的WEB服务

     1.股票行情数据 Web Service(支持香港.深圳.上海基金.债券和股票:支持多股票同时查询) http://www.webxml.com.cn/WebServices/StockInfoWS ...

  3. javascript 实现页面加载完再显示页面

    document.onreadystatechange = function () { if (document.readyState == "complete") { docum ...

  4. 工作需求----表单多选框checkbox交互

    关于多选框,反选及选取几个: 1.html内容 <!--begin checkbox--> <div class="c_n_manage_tablexx"> ...

  5. Node.js EventEmitter(事件队列)

    Node.js 所有的异步 I/O 操作在完成时都会发送一个事件到事件队列. Node.js里面的许多对象都会分发事件:一个net.Server对象会在每次有新连接时分发一个事件, 一个fs.read ...

  6. 打造最高效的科研环境之Emacs插件们

    0 盲人摸象 作为初学者,迫切的需求就是直接上手Emacs并打造包含自动补全命令在内的科研环境. 和网上众多的插件安装的教程相比,我认为找到一个与自己需求匹配的Emacs配置环境来得更方便. 本例中, ...

  7. nginx 配置ci ,tp

    #local ciserver {    listen       80;    server_name  ci.local;        root    E:/test/CodeIgniter/; ...

  8. VS2015快捷键

    Shift+Alt+Enter: 切换全屏编辑 Ctrl+B,T / Ctrl+K,K: 切换书签开关Ctrl+B,N / Ctrl+K,N: 移动到下一书签Ctrl+B,P: 移动到上一书签Ctrl ...

  9. eclipse打开文件或者目录位置

    1.点击Run-->External Tools-->External Tools Configurations... 右击program,点击new 2.填写名称,Location,Ar ...

  10. HDU 4951 Multiplication table(2014 Multi-University Training Contest 8)

    思路   如果进制为p    那么当x<p时 (p-1)*(p-x)=(p-(x+1))  *p +x     因为x<p  所以没有进位  所以高位上的数字为    p-(x+1). 根 ...