Ejemplo n.º 1
0
Archivo: app.py Proyecto: 8dspaces/wiwi
def configure_extensions(app):
    # flask-MongoEngine
    db.init_app(app)
    db.register_connection(**app.config.get('ORDER_DB_CONFIG'))
    db.register_connection(**app.config.get('INVENTORY_DB_CONFIG'))
    db.register_connection(**app.config.get('CART_DB_CONFIG'))
    db.register_connection(**app.config.get('CONTENT_DB_CONFIG'))
    db.register_connection(**app.config.get('LOG_DB_CONFIG'))

    mongo_inventory.init_app(app, config_prefix='MONGO_INVENTORY')

    redis.connection_pool = ConnectionPool(**app.config.get('REDIS_CONFIG'))
    session_redis.connection_pool = ConnectionPool(
        **app.config.get('SESSION_REDIS'))

    # server side session
    app.session_interface = RedisSessionInterface(session_redis)

    # flask-mail
    mail.init_app(app)
    mail.app = app

    # flask-cache
    cache.init_app(app)

    # flask-bcrypt
    bcrypt.init_app(app)

    # flask-babel
    babel.init_app(app)

    # flask-assets
    assets.init_app(app)

    # flask_debugtoolbar
    toolbar.init_app(app)

    # flask-login (not configured will raise 401 error)
    login_manager.login_view = 'frontend.login'
    # login_manager.refresh_view = 'frontend.reauth'

    @login_manager.user_loader
    def load_user(id):
        import application.models as Models
        return Models.User.objects(id=id, is_deleted=False).first()

    login_manager.init_app(app)
    login_manager.login_message = _('Please log in to access this page.')
    login_manager.needs_refresh_message = _(
        'Please reauthenticate to access this page.')

    # flask-principal (must be configed after flask-login!!!)
    principal.init_app(app)

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        principal_on_identity_loaded(sender, identity)
Ejemplo n.º 2
0
def register_extensions(app):
    from application.extensions import db
    from application.extensions import login
    from application.extensions import migrate
    from application.extensions import mail
    from application.extensions import babel
    from application.extensions import csrf

    csrf._exempt_views.add('dash.dash.dispatch')

    db.init_app(app)
    login.init_app(app)
    login.login_view = "auth.login"
    migrate.init_app(app, db)
    mail.init_app(app)
    babel.init_app(app)
    csrf.init_app(app)
Ejemplo n.º 3
0
def register_extensions(app):
    db.init_app(app)
    migrate.init_app(app, db)
    babel.init_app(app)
    swagger.init_app(app)
    flask_wtf.CSRFProtect(app)
    # Setup Flask-Security
    from application.models.authbase import User, Role

    # from application.forms.user import ExtendedLoginForm

    user_datastore = SQLAlchemyUserDatastore(db, User, Role)
    security.init_app(
        app,
        datastore=user_datastore,
        # login_form=ExtendedLoginForm,
        # register_form=ExtendedRegisterForm
    )
Ejemplo n.º 4
0
def configure_extensions(app):
    """Configures the extensions."""
    # Flask-BabelEx
    babel.init_app(app)

    # Captcha Solver
    captcha_solver.init_app(app)

    # Flask-Mail
    mail.init_app(app)

    # Flask-Admin
    admin.init_app(app)

    # Flask-Mongo Engine
    db.init_app(app)

    ma.init_app(app)
    # Flask-Cache
    cache.init_app(app,
                   config={
                       'CACHE_TYPE': 'redis',
                       'CACHE_KEY_PREFIX': 'UHE',
                       'CACHE_REDIS_URL': app.config['REDIS_URL']
                   })

    print(app.testing)
    # Flask-And-Redis
    # jwt.secret_key = app.config['SECRET_KEY']
    redis_store.init_app(app)

    # Flask-Limiter
    limiter.init_app(app)

    # Flask-Allows
    allows.init_app(app)
    allows.identity_loader(lambda: current_user)
    login_manager.init_app(app)
    # Flask-Plugins
    app.school_time = Time()

    oauth.init_app(app)

    dashboard.bind(app)
Ejemplo n.º 5
0
from application.extensions import db, login_manager, babel, admin, principal
from configs.config import BaseConfig
from application.services.permission import principal_on_identity_loaded
from flask_principal import identity_loaded

app = Flask(__name__)

#admin
app.register_blueprint(manage_items)

#website
app.register_blueprint(auth)
app.register_blueprint(address)

db.init_app(app)
babel.init_app(app)

app.config.from_object(BaseConfig())
db.register_connection(**app.config.get('USER_DB_CONFIG'))
db.register_connection(**app.config.get('DATA_DB_CONFIG'))
db.register_connection(**app.config.get('INVENTORY_DB_CONFIG'))

login_manager.init_app(app)
login_manager.login_view = 'frontend.login'


@login_manager.user_loader
def load_user(id):
    import application.models as Models
    return Models.User.objects(id=id, is_deleted=False).first()