Ejemplo n.º 1
0
def register_extensions(app):
    if app.config.get('ELASTICSEARCH_SUPPORT', False):
        es.init_app(app)
    mail.init_app(app)
    redis.init_app(app)

    login_manager.session_protection = 'strong'
    login_manager.login_view = '/admin/login'
    login_manager.init_app(app)
    """init redis connection"""
    redisco.connection_setup(host=app.config['REDIS_CONFIG']['HOST'],
                             port=app.config['REDIS_CONFIG']['PORT'],
                             db=app.config['REDIS_CONFIG']['DB'])

    def filter_func(kv):
        print(kv)

    app.jinja_env.add_extension('pyjade.ext.jinja.PyJadeExtension')
    from application.services.theme import RedisLoader
    app.jinja_env.loader = RedisLoader()

    from pyjade import Compiler
    Compiler.register_autoclosecode('load')

    @login_manager.user_loader
    def load_user(user_id):
        return User.objects.get_by_id(user_id)

    if not app.config['DEBUG'] and not app.config['TESTING']:
        sentry.init_app(
            app,
            dsn=
            'https://*****:*****@app.getsentry.com/93431'
        )
Ejemplo n.º 2
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.º 3
0
def registe_extensions(app):
    """config extensions"""
    db.init_app(app)
    migrate.init_app(app, db)
    login_manager.init_app(app)

    @login_manager.user_loader
    def load_user(user_id):
        return User.query.filter_by(id=user_id).first()
Ejemplo n.º 4
0
def create_app(config_class=Config):
    app.config.from_object(config_class)

    from application import auth, controllers

    mysql.init_app(app)
    login_manager.init_app(app)
    login_manager.login_view = 'login'
    login_manager.login_message = None
    return app
Ejemplo n.º 5
0
def register_extensions(app):
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db)
    asset_locator.init_app(app)
    basic_auth.init_app(app)
    return None
Ejemplo n.º 6
0
def register_extensions(app):
    db.init_app(app)
    login_manager.init_app(app)
    login_manager.login_view = 'auth.login'

    @login_manager.user_loader
    def load_user(user_id):
        return User.objects(id=user_id).first()

    admin.init_app(app)
    admin.add_view(ModelView(Role))
Ejemplo n.º 7
0
def create_app(config_class=Config):
    app.config.from_object(config_class)
    from application import controllers
    from application.models import db, User
    from application.admin import init_admin
    db.init_app(app)
    migrate.init_app(app, db)
    csrf.init_app(app)
    login_manager.init_app(app)
    init_admin(app)
    authentication(User)
    return app
Ejemplo n.º 8
0
def extensions(app):
    """
    Register 0 or more extensions (mutates the app passed in).

    :param app: Flask application instance
    :return: None
    """

    db.init_app(app)
    login_manager.init_app(app)
    migrate.init_app(app, db)

    return None
Ejemplo n.º 9
0
def configure_extensions(app):
    """
    注册扩展
    :param app: 
    :return: 
    """
    # --- DB --- #
    db.init_app(app)

    # 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-cache
    cache.init_app(app)

    # flask-bcrypt
    bcrypt.init_app(app)

    # flask-assets
    assets.init_app(app)

    # flask_debugtoolbar
    toolbar.init_app(app)

    # weixin 注册

    # 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):
        user = Models.SystemUser.query.filter_by(id=id,
                                                 is_deleted=False).first()
        return user

    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.º 10
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.º 11
0
def register_extensions(app):
    """Register models."""
    db.init_app(app)
    login_manager.init_app(app)

    # flask-admin configs
    admin.init_app(app)
    admin.add_view(ModelView(User))
    admin.add_view(ModelView(Role))

    login_manager.login_view = 'auth.login'

    @login_manager.user_loader
    def load_user(user_id):
        return User.objects(id=user_id).first()

    # jwt config
    def jwt_authenticate(username, password):
        logging.info("username:{}\npassword:{}\n".format(username, password))
        user = User.objects(name=username, password=password).first()
        return user

    def jwt_identity(payload):
        logging.info("payload:{}".format(payload))
        user_id = payload['identity']
        return User.objects(id=user_id).first()

    def make_payload(identity):
        iat = datetime.utcnow()
        exp = iat + current_app.config.get('JWT_EXPIRATION_DELTA')
        nbf = iat + current_app.config.get('JWT_NOT_BEFORE_DELTA')
        identity = str(identity.id)
        return {'exp': exp, 'iat': iat, 'nbf': nbf, 'identity': identity}

    jwt.authentication_handler(jwt_authenticate)
    jwt.identity_handler(jwt_identity)
    jwt.jwt_payload_handler(make_payload)

    jwt.init_app(app)
Ejemplo n.º 12
0
def register_extensions(app):
    """Register models."""
    db.init_app(app)
    login_manager.init_app(app)

    # flask-admin configs
    admin.init_app(app)
    admin.add_view(ModelView(User))
    admin.add_view(ModelView(Role))

    login_manager.login_view = 'auth.login'

    @login_manager.user_loader
    def load_user(user_id):
        return User.objects(id=user_id).first()

    # jwt config
    def jwt_authenticate(username, password):
        logging.info("username:{}\npassword:{}\n".format(username, password))
        user = User.objects(name=username, password=password).first()
        return user

    def jwt_identity(payload):
        logging.info("payload:{}".format(payload))
        user_id = payload['identity']
        return User.objects(id=user_id).first()

    def make_payload(identity):
        iat = datetime.utcnow()
        exp = iat + current_app.config.get('JWT_EXPIRATION_DELTA')
        nbf = iat + current_app.config.get('JWT_NOT_BEFORE_DELTA')
        identity = str(identity.id)
        return {'exp': exp, 'iat': iat, 'nbf': nbf, 'identity': identity}

    jwt.authentication_handler(jwt_authenticate)
    jwt.identity_handler(jwt_identity)
    jwt.jwt_payload_handler(make_payload)

    jwt.init_app(app)
Ejemplo n.º 13
0
def register_extensions(app):
    """ 注册models """
    mysql.init_app(app)
    mongo.init_app(app)

    # 注册用户认证
    login_manager.init_app(app)

    @login_manager.user_loader
    def load_user(user_id):
        return User.objects(id=user_id).first()

    # jwt config
    def jwt_authenticate(username, password):
        logging.info("username:{}\npassword:{}\n".format(username, password))
        hash_password = hash_encrypt(password)
        user = User.query.filter_by(email=username, password=hash_password).first()
        return user

    def jwt_identity(payload):
        logging.info("payload:{}".format(payload))
        user_id = payload['identity']
        user = UserAuth(user_id=user_id)
        return user

    def make_payload(identity):
        iat = datetime.utcnow()
        exp = iat + current_app.config.get('JWT_EXPIRATION_DELTA')
        nbf = iat + current_app.config.get('JWT_NOT_BEFORE_DELTA')
        identity = str(identity.id)
        return {'exp': exp, 'iat': iat, 'nbf': nbf, 'identity': identity}

    jwt.authentication_handler(jwt_authenticate)
    jwt.identity_handler(jwt_identity)
    jwt.jwt_payload_handler(make_payload)

    jwt.init_app(app)
Ejemplo n.º 14
0
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()


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