Moved from 'website' to 'web'

This commit is contained in:
Éloi Rivard 2020-08-17 11:56:03 +02:00
parent 6ee415566c
commit 3a1284880a
43 changed files with 22 additions and 20 deletions

11
app.py
View file

@ -1,11 +1,4 @@
from website.app import create_app
from web.app import create_app
app = create_app(
{
"SECRET_KEY": "secret",
"OAUTH2_REFRESH_TOKEN_GENERATOR": True,
"SQLALCHEMY_TRACK_MODIFICATIONS": False,
"SQLALCHEMY_DATABASE_URI": "sqlite:///db.sqlite",
}
)
app = create_app()

View file

@ -3,7 +3,7 @@ NAME = MyDomain
# LOGO = "https://path/to/your/organization/logo.png"
# If unset, language is detected
LANGUAGE = 'en'
LANGUAGE = "en"
[LDAP]
URI = "ldaps://ldap.mydomain.tld"

View file

@ -1,5 +1,5 @@
authlib
flask
flask-babel
python-ldap
flask - babel
python - ldap
toml

View file

@ -12,8 +12,10 @@ from .routes import bp
def create_app(config=None):
app = Flask(__name__)
config = toml.load(os.environ.get("CONFIG", "config.toml"))
app.config.from_mapping(config)
app.config.from_mapping(
{"OAUTH2_REFRESH_TOKEN_GENERATOR": True,}
)
app.config.from_mapping(toml.load(os.environ.get("CONFIG", "config.toml")))
app.url_map.strict_slashes = False
@ -25,7 +27,9 @@ def setup_app(app):
@app.before_request
def before_request():
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
def after_request(response):
@ -47,17 +51,17 @@ def setup_app(app):
@babel.localeselector
def get_locale():
user = getattr(g, 'user', None)
user = getattr(g, "user", None)
if user is not None:
return user.locale
if 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
def get_timezone():
user = getattr(g, 'user', None)
user = getattr(g, "user", None)
if user is not None:
return user.timezone

View file

@ -125,10 +125,15 @@ class LDAPObjectHelper:
]
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)
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, [None])[0]

View file

Before

Width:  |  Height:  |  Size: 496 KiB

After

Width:  |  Height:  |  Size: 496 KiB

View file

Before

Width:  |  Height:  |  Size: 382 KiB

After

Width:  |  Height:  |  Size: 382 KiB

View file

Before

Width:  |  Height:  |  Size: 105 KiB

After

Width:  |  Height:  |  Size: 105 KiB

View file

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB