Moved from 'website' to 'web'
11
app.py
|
@ -1,11 +1,4 @@
|
||||||
from website.app import create_app
|
from web.app import create_app
|
||||||
|
|
||||||
|
|
||||||
app = create_app(
|
app = create_app()
|
||||||
{
|
|
||||||
"SECRET_KEY": "secret",
|
|
||||||
"OAUTH2_REFRESH_TOKEN_GENERATOR": True,
|
|
||||||
"SQLALCHEMY_TRACK_MODIFICATIONS": False,
|
|
||||||
"SQLALCHEMY_DATABASE_URI": "sqlite:///db.sqlite",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ NAME = MyDomain
|
||||||
# LOGO = "https://path/to/your/organization/logo.png"
|
# LOGO = "https://path/to/your/organization/logo.png"
|
||||||
|
|
||||||
# If unset, language is detected
|
# If unset, language is detected
|
||||||
LANGUAGE = 'en'
|
LANGUAGE = "en"
|
||||||
|
|
||||||
[LDAP]
|
[LDAP]
|
||||||
URI = "ldaps://ldap.mydomain.tld"
|
URI = "ldaps://ldap.mydomain.tld"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
authlib
|
authlib
|
||||||
flask
|
flask
|
||||||
flask-babel
|
flask - babel
|
||||||
python-ldap
|
python - ldap
|
||||||
toml
|
toml
|
||||||
|
|
|
@ -12,8 +12,10 @@ from .routes import bp
|
||||||
def create_app(config=None):
|
def create_app(config=None):
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
config = toml.load(os.environ.get("CONFIG", "config.toml"))
|
app.config.from_mapping(
|
||||||
app.config.from_mapping(config)
|
{"OAUTH2_REFRESH_TOKEN_GENERATOR": True,}
|
||||||
|
)
|
||||||
|
app.config.from_mapping(toml.load(os.environ.get("CONFIG", "config.toml")))
|
||||||
|
|
||||||
app.url_map.strict_slashes = False
|
app.url_map.strict_slashes = False
|
||||||
|
|
||||||
|
@ -25,7 +27,9 @@ def setup_app(app):
|
||||||
@app.before_request
|
@app.before_request
|
||||||
def before_request():
|
def before_request():
|
||||||
g.ldap = ldap.initialize(app.config["LDAP"]["URI"])
|
g.ldap = ldap.initialize(app.config["LDAP"]["URI"])
|
||||||
g.ldap.simple_bind_s(app.config["LDAP"]["BIND_USER"], app.config["LDAP"]["BIND_PW"])
|
g.ldap.simple_bind_s(
|
||||||
|
app.config["LDAP"]["BIND_USER"], app.config["LDAP"]["BIND_PW"]
|
||||||
|
)
|
||||||
|
|
||||||
@app.after_request
|
@app.after_request
|
||||||
def after_request(response):
|
def after_request(response):
|
||||||
|
@ -47,17 +51,17 @@ def setup_app(app):
|
||||||
|
|
||||||
@babel.localeselector
|
@babel.localeselector
|
||||||
def get_locale():
|
def get_locale():
|
||||||
user = getattr(g, 'user', None)
|
user = getattr(g, "user", None)
|
||||||
if user is not None:
|
if user is not None:
|
||||||
return user.locale
|
return user.locale
|
||||||
|
|
||||||
if app.config.get("LANGUAGE"):
|
if app.config.get("LANGUAGE"):
|
||||||
return app.config.get("LANGUAGE")
|
return app.config.get("LANGUAGE")
|
||||||
|
|
||||||
return request.accept_languages.best_match(['fr', 'en'])
|
return request.accept_languages.best_match(["fr", "en"])
|
||||||
|
|
||||||
@babel.timezoneselector
|
@babel.timezoneselector
|
||||||
def get_timezone():
|
def get_timezone():
|
||||||
user = getattr(g, 'user', None)
|
user = getattr(g, "user", None)
|
||||||
if user is not None:
|
if user is not None:
|
||||||
return user.timezone
|
return user.timezone
|
|
@ -125,10 +125,15 @@ class LDAPObjectHelper:
|
||||||
]
|
]
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if (not self.may or name not in self.may) and (not self.must or name not in self.must):
|
if (not self.may or name not in self.may) and (
|
||||||
|
not self.must or name not in self.must
|
||||||
|
):
|
||||||
return super().__getattribute__(name)
|
return super().__getattribute__(name)
|
||||||
|
|
||||||
if not self.attr_type_by_name() or not self.attr_type_by_name()[name].single_value:
|
if (
|
||||||
|
not self.attr_type_by_name()
|
||||||
|
or not self.attr_type_by_name()[name].single_value
|
||||||
|
):
|
||||||
return self.attrs.get(name, [])
|
return self.attrs.get(name, [])
|
||||||
|
|
||||||
return self.attrs.get(name, [None])[0]
|
return self.attrs.get(name, [None])[0]
|
Before Width: | Height: | Size: 496 KiB After Width: | Height: | Size: 496 KiB |
Before Width: | Height: | Size: 382 KiB After Width: | Height: | Size: 382 KiB |
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |