|
|
- import ldap as l
- from flask import Flask
- from flask_sqlalchemy import SQLAlchemy
- from flask_login import LoginManager, login_manager
- from flask_bootstrap import Bootstrap
- from flask_cachebuster import CacheBuster
-
- import os
-
-
- app = Flask(__name__)
- Bootstrap(app)
- app.secret_key = 'asdf'
- app.debug = True
-
- app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///../users.db'
- app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
- app.config['WTF_CSRF_SECRET_KEY'] = 'asdf'
-
- # Base
- app.config['LDAP_REALM_NAME'] = 'OpenLDAP Authentication'
- app.config['LDAP_HOST'] = os.environ.get('LDAP_HOST')
- app.config['LDAP_BASE_DN'] = os.environ.get('LDAP_BASE_DN')
- app.config['LDAP_USERNAME'] = os.environ.get('LDAP_USERNAME')
- app.config['LDAP_PASSWORD'] = os.environ.get('LDAP_PASSWORD')
-
- # OpenLDAP
- app.config['LDAP_OBJECTS_DN'] = 'dn'
- app.config['LDAP_OPENLDAP'] = True
- app.config['LDAP_USER_OBJECT_FILTER'] = '(&(objectclass=posixAccount)(uid=%s))'
-
- # Login cookies
- app.config['SESSION_COOKIE_DOMAIN'] = os.environ.get('COOKIE_DOMAIN')
- app.config['REMEMBER_COOKIE_DOMAIN'] = os.environ.get('COOKIE_DOMAIN')
-
- db = SQLAlchemy(app)
-
- login_manager = LoginManager(app)
- login_manager.init_app(app)
- login_manager.login_view = 'auth.login'
-
- config = {"extensions": [".js", ".css", ".csv"], "hash_size": 5}
-
- cache_buster = CacheBuster(config=config)
- cache_buster.init_app(app)
-
- from accounts.auth.views import auth
- app.register_blueprint(auth)
-
- db.create_all()
|