Ejemplo n.º 1
0
def configure_admin(app):
    from application.controllers.admin.dashboard import IndexView
    admin.name = u"汽车服务管理平台"
    admin.base_template = 'admin/master2.html'
    admin.template_mode = 'bootstrap3'
    admin.init_app(app)
    admin.index_view = IndexView(name="Dashboard")
Ejemplo n.º 2
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.º 3
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.º 4
0
def register_extensions(app, user_datastore):

    db.init_app(app)
    app.db = db

    serializer(app.secret_key)

    # user_manager(app, app.db, User)
    # print(f"user manager: {dir(user_manager)}")

    admin.init_app(app)

    debug_toolbar(app)

    # security(app, user_datastore)
    security.init_app(app, user_datastore)

    # define a context processor for merging flask-admin's template context into the
    # flask-security views.
    @security.context_processor
    def security_context_processor():
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
            get_url=url_for
        )

    # Access front bluprint and add context variables for Flask-admin layout 
    @front_blueprint.context_processor
    def security_context_processor():
        return dict(
            admin_base_template=admin.base_template,
            admin_view=admin.index_view,
            h=admin_helpers,
            get_url=url_for
        )

    # from app.admin_core import configure_admin
    # configure_admin(admin)
    
    return None
Ejemplo n.º 5
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.º 6
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)