Encapsulate required app config on Devicehub
This commit is contained in:
parent
338afcc556
commit
c226844a43
|
@ -35,6 +35,7 @@ class DevicehubConfig(Config):
|
|||
import_resource(metric_def),
|
||||
),)
|
||||
PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str]
|
||||
SECRET_KEY = config('SECRET_KEY')
|
||||
DB_USER = config('DB_USER', 'dhub')
|
||||
DB_PASSWORD = config('DB_PASSWORD', 'ereuse')
|
||||
DB_HOST = config('DB_HOST', 'localhost')
|
||||
|
|
|
@ -22,6 +22,11 @@ from ereuse_devicehub.resources.inventory import Inventory, InventoryDef
|
|||
from ereuse_devicehub.templating import Environment
|
||||
|
||||
|
||||
from flask_login import LoginManager
|
||||
from flask_wtf.csrf import CSRFProtect
|
||||
from ereuse_devicehub.resources.user.models import User
|
||||
|
||||
|
||||
class Devicehub(Teal):
|
||||
test_client_class = Client
|
||||
Dummy = Dummy
|
||||
|
@ -61,6 +66,20 @@ class Devicehub(Teal):
|
|||
inv.command('search')(self.regenerate_search)
|
||||
self.before_request(self._prepare_request)
|
||||
|
||||
self.configure_extensions()
|
||||
|
||||
def configure_extensions(self):
|
||||
# configure & enable CSRF of Flask-WTF
|
||||
CSRFProtect(self)
|
||||
|
||||
# configure Flask-Login
|
||||
login_manager = LoginManager()
|
||||
login_manager.init_app(self)
|
||||
|
||||
@login_manager.user_loader
|
||||
def load_user(user_id):
|
||||
return User.query.get(user_id)
|
||||
|
||||
# noinspection PyMethodOverriding
|
||||
@click.option('--name', '-n',
|
||||
default='Test 1',
|
||||
|
|
Reference in New Issue