Esempio n. 1
0
    def init_app(self, app, datastore=None, register_blueprint=True):
        """Initializes the Flask-Security extension for the specified
        application and datastore implentation.

        :param app: The application.
        :param datastore: An instance of a user datastore.
        """
        datastore = datastore or self.datastore

        for key, value in _default_config.items():
            app.config.setdefault('SECURITY_' + key, value)

        for key, value in _default_messages.items():
            app.config.setdefault('SECURITY_MSG_' + key, value)

        identity_loaded.connect_via(app)(_on_identity_loaded)

        state = _get_state(app, datastore)

        if register_blueprint:
            app.register_blueprint(create_blueprint(state, __name__))
            app.context_processor(_context_processor)

        app.extensions['security'] = state

        return state
Esempio n. 2
0
    def init_app(self, app, datastore=None, register_blueprint=True):
        """Initializes the Flask-Security extension for the specified
        application and datastore implentation.

        :param app: The application.
        :param datastore: An instance of a user datastore.
        """
        datastore = datastore or self.datastore

        for key, value in _default_config.items():
            app.config.setdefault('SECURITY_' + key, value)

        for key, value in _default_messages.items():
            app.config.setdefault('SECURITY_MSG_' + key, value)

        identity_loaded.connect_via(app)(_on_identity_loaded)

        if register_blueprint:
            name = cv('BLUEPRINT_NAME', app=app)
            url_prefix = cv('URL_PREFIX', app=app)
            bp = views.create_blueprint(app, name, __name__,
                                        url_prefix=url_prefix,
                                        template_folder='templates')
            app.register_blueprint(bp)

        state = self._get_state(app, datastore)

        app.extensions['security'] = state

        app.context_processor(lambda: dict(url_for_security=url_for_security,
                                           security=state))

        return state
Esempio n. 3
0
def initialise_app(app, configclass):
    # Load the default configuration
    app.config.from_object(configclass)

    # Load the configuration from the instance folder
    try:
        app.config.from_pyfile('config.py')
    except:
        print 'No instance config file'

    if app.config['USE_PROXY']:
        app.wsgi_app = ProxyFix(app.wsgi_app)

    toolbar = DebugToolbarExtension(app)

    db.init_app(app)
    mail.init_app(app)

    assets = Environment(app)
    assets.register(bundles)

    from .models import User, Feed, Entry, Author, Role

    user_datastore = SQLAlchemyUserDatastore(db, User, Role)
    app.security = Security(app, user_datastore)

    wtf.add_helpers(app)

    admin = Admin(app, 'Admin', index_view=SecuredAdminIndexView())
    admin.add_view(SecuredModelView(User, db.session))
    admin.add_view(SecuredModelView(Feed, db.session))
    admin.add_view(SecuredModelView(Entry, db.session))
    admin.add_view(SecuredModelView(Author, db.session))

    app.register_blueprint(frontend_blueprint)
    identity_loaded.connect_via(app)(on_identity_loaded)

    add_errorhandlers(app)

    Principal(app)

    if not app.debug:
        import logging
        from .utils.loggers import add_logger_filehandler, add_logger_external

        add_logger_filehandler(app)

        if app.config['LOG_ADDRESS']:
            add_logger_external(app)

        app.logger.setLevel(logging.INFO)
        app.logger.info(u'{0} startup'.format(app.config['PROJECT_NAME']))

    return app
Esempio n. 4
0
    def init_app(
        self,
        app,
        datastore=None,
        register_blueprint=True,
        login_form=None,
        confirm_register_form=None,
        register_form=None,
        forgot_password_form=None,
        reset_password_form=None,
        change_password_form=None,
        send_confirmation_form=None,
        passwordless_login_form=None,
    ):
        """Initializes the Flask-Security extension for the specified
        application and datastore implentation.

        :param app: The application.
        :param datastore: An instance of a user datastore.
        :param register_blueprint: to register the Security blueprint or not.
        """
        datastore = datastore or self.datastore

        for key, value in _default_config.items():
            app.config.setdefault("SECURITY_" + key, value)

        for key, value in _default_messages.items():
            app.config.setdefault("SECURITY_MSG_" + key, value)

        identity_loaded.connect_via(app)(_on_identity_loaded)

        state = _get_state(
            app,
            datastore,
            login_form=login_form,
            confirm_register_form=confirm_register_form,
            register_form=register_form,
            forgot_password_form=forgot_password_form,
            reset_password_form=reset_password_form,
            change_password_form=change_password_form,
            send_confirmation_form=send_confirmation_form,
            passwordless_login_form=passwordless_login_form,
        )

        if register_blueprint:
            app.register_blueprint(create_blueprint(state, __name__))
            app.context_processor(_context_processor)

        app.extensions["security"] = state

        return state
Esempio n. 5
0
    def init_app(self,
                 app,
                 datastore=None,
                 register_blueprint=True,
                 login_form=None,
                 confirm_register_form=None,
                 register_form=None,
                 forgot_password_form=None,
                 reset_password_form=None,
                 change_password_form=None,
                 send_confirmation_form=None,
                 passwordless_login_form=None):
        """Initializes the Flask-Security extension for the specified
        application and datastore implentation.

        :param app: The application.
        :param datastore: An instance of a user datastore.
        :param register_blueprint: to register the Security blueprint or not.
        """
        datastore = datastore or self.datastore

        for key, value in _default_config.items():
            app.config.setdefault('SECURITY_' + key, value)

        for key, value in _default_messages.items():
            app.config.setdefault('SECURITY_MSG_' + key, value)

        identity_loaded.connect_via(app)(_on_identity_loaded)

        state = _get_state(app,
                           datastore,
                           login_form=login_form,
                           confirm_register_form=confirm_register_form,
                           register_form=register_form,
                           forgot_password_form=forgot_password_form,
                           reset_password_form=reset_password_form,
                           change_password_form=change_password_form,
                           send_confirmation_form=send_confirmation_form,
                           passwordless_login_form=passwordless_login_form)

        if register_blueprint:
            app.register_blueprint(create_blueprint(state, __name__))
            app.context_processor(_context_processor)

        state.render_template = self.render_template
        app.extensions['security'] = state

        return state
Esempio n. 6
0
    def __init__(self, app):

        actions_cfg = app.config.get('RELENGAPI_ACTIONS', {})
        self.group_actions = actions_cfg.get('group-actions', {})

        # verify that each specified action exists
        for actionstr in set(itertools.chain(*self.group_actions.values())):
            try:
                actions[actionstr]
            except KeyError:
                raise RuntimeError("invalid action in settings: %r" % (actionstr,))

        self.uri = actions_cfg['uri']
        self.login_dn = actions_cfg['login_dn']
        self.login_password = actions_cfg['login_password']
        self.user_base = actions_cfg['user_base']
        self.group_base = actions_cfg['group_base']
        self.debug = actions_cfg.get('debug')

        self.logger = logging.getLogger(__name__)

        identity_loaded.connect_via(app)(self.on_identity_loaded)
Esempio n. 7
0
    def init_app(self, app, datastore=None, register_blueprint=True, **kwargs):
        """
        :param app: The application.
        :param datastore: An instance of a user datastore.
        :param register_blueprint: to register the Security blueprint or not.
        """
        datastore = datastore or self.datastore
        for key, value in _default_config.items():
            app.config.setdefault('SECURITY_' + key, value)

        for key, value in _default_messages.items():
            app.config.setdefault('SECURITY_MSG_' + key, value)

        identity_loaded.connect_via(app)(_on_identity_loaded)

        state = _get_state(app, datastore, **kwargs)

        if register_blueprint:
            app.register_blueprint(create_blueprint(state, __name__))
            app.context_processor(_context_processor)

        state.render_template = self.render_template
        app.security = state
        return state