Guest User

Untitled

a guest
Nov 15th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import ldap
  2. from django_auth_ldap.config import LDAPSearch
  3.  
  4.  
  5. AUTH_LDAP_SERVER_URI = "http://ldap.forumsys.com:389/"
  6. AUTH_LDAP_CONNECTION_OPTIONS = {
  7. ldap.OPT_REFERRALS: 0
  8. }
  9.  
  10. AUTH_LDAP_BIND_DN = "cn=read-only-admin,dc=example,dc=com"
  11. AUTH_LDAP_BIND_PASSWORD = "password"
  12. AUTH_LDAP_USER_SEARCH = LDAPSearch(
  13. "cn=read-only-admin,dc=example,dc=com",
  14. ldap.SCOPE_SUBTREE, "(uid=%(user)s)")
  15.  
  16. BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
  17.  
  18. AUTHENTICATION_BACKENDS = [
  19. 'django_auth_ldap.backend.LDAPBackend',
  20. ]
  21.  
  22. from django.contrib.auth import authenticate, login
  23. from django.shortcuts import render
  24.  
  25. def login_user(request):
  26.  
  27. email = password = ""
  28. state = ""
  29.  
  30. if request.POST:
  31. email = request.POST.get('email')
  32. password = request.POST.get('password')
  33.  
  34. print (email, password)
  35.  
  36. user = authenticate(username=request.POST.get('email'), password=request.POST.get('password'))
  37. if user is not None:
  38. login(request, user)
  39. state = "Valid account"
  40. else:
  41. state = "Inactive account"
  42.  
  43. return render(request, 'KPI/auth.html', {'state': state, 'email': email})
  44.  
  45. <html>
  46. <head>
  47. <title>Login</title>
  48. </head>
  49. <body>
  50. {{state}}
  51. <form action="" method="post"> {% csrf_token %}
  52. Email address: <input type="text" name="email" value="{{ email }}" />
  53. Password: <input type="password" name="password" value="" />
  54. <input type="submit" value="Log in" />
  55. </form>
  56. </body>
  57. </html>
Add Comment
Please, Sign In to add comment