Advertisement
Guest User

Untitled

a guest
Aug 12th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. from flask import Flask, g, request, session, redirect, url_for, abort, g, render_template
  2. from flask_simpleldap import LDAP
  3. from flask_httpauth import HTTPTokenAuth
  4. from flask_scss import Scss
  5.  
  6. app = Flask(__name__)
  7. app.secret_key = 'dev key'
  8. app.debug = True
  9.  
  10. app.config['LDAP_USE_SSL'] = False
  11. app.config['LDAP_HOST'] = 'XXXX'
  12. app.config['LDAP_BASE_DN'] = 'CN=XX,DC=XX,DC=XXX,DC=XXX'
  13. app.config['LDAP_USERNAME'] = 'CN=XX,CN=XX,DC=XX,DC=XX,DC=XX'
  14. app.config['LDAP_PASSWORD'] = 'XXXX'
  15.  
  16.  
  17. app.config['LDAP_OBJECTS_DN'] = 'dn'
  18. app.config['LDAP_OPENLDAP'] = True
  19. app.config['LDAP_USER_OBJECT_FILTER'] = '(&(objectclass=Person)(sAMAccountName=%s))'
  20.  
  21. app.config['LDAP_GROUP_MEMBER_FILTER'] = '(|(&(objectClass=Group)(member=%s)))'
  22. app.config['LDAP_GROUP_MEMBER_FILTER_FIELD'] = 'sAMAccountName'
  23.  
  24. ldap = LDAP(app)
  25.  
  26.  
  27. @app.before_request
  28. def before_request():
  29. g.user = None
  30. if 'user_id' in session:
  31. # This is where you'd query your database to get the user info.
  32. g.user = {}
  33. # Create a global with the LDAP groups the user is a member of.
  34. g.ldap_groups = ldap.get_user_groups(user=session['user_id'])
  35. print(g.ldap_groups)
  36.  
  37.  
  38. @app.route('/')
  39. @ldap.login_required
  40. def index():
  41. return "xd"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement