Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ldap
- from django_auth_ldap.config import LDAPSearch
- AUTH_LDAP_SERVER_URI = "http://ldap.forumsys.com:389/"
- AUTH_LDAP_CONNECTION_OPTIONS = {
- ldap.OPT_REFERRALS: 0
- }
- AUTH_LDAP_BIND_DN = "cn=read-only-admin,dc=example,dc=com"
- AUTH_LDAP_BIND_PASSWORD = "password"
- AUTH_LDAP_USER_SEARCH = LDAPSearch(
- "cn=read-only-admin,dc=example,dc=com",
- ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
- BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- AUTHENTICATION_BACKENDS = [
- 'django_auth_ldap.backend.LDAPBackend',
- ]
- from django.contrib.auth import authenticate, login
- from django.shortcuts import render
- def login_user(request):
- email = password = ""
- state = ""
- if request.POST:
- email = request.POST.get('email')
- password = request.POST.get('password')
- print (email, password)
- user = authenticate(username=request.POST.get('email'), password=request.POST.get('password'))
- if user is not None:
- login(request, user)
- state = "Valid account"
- else:
- state = "Inactive account"
- return render(request, 'KPI/auth.html', {'state': state, 'email': email})
- <html>
- <head>
- <title>Login</title>
- </head>
- <body>
- {{state}}
- <form action="" method="post"> {% csrf_token %}
- Email address: <input type="text" name="email" value="{{ email }}" />
- Password: <input type="password" name="password" value="" />
- <input type="submit" value="Log in" />
- </form>
- </body>
- </html>
Add Comment
Please, Sign In to add comment