当前位置: 首页>>代码示例>>Python>>正文


Python flask_principal.Principal方法代码示例

本文整理汇总了Python中flask_principal.Principal方法的典型用法代码示例。如果您正苦于以下问题:Python flask_principal.Principal方法的具体用法?Python flask_principal.Principal怎么用?Python flask_principal.Principal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask_principal的用法示例。


在下文中一共展示了flask_principal.Principal方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_principal

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Principal [as 别名]
def _get_principal(app):
    p = Principal(app, use_sessions=False)
    p.identity_loader(_identity_loader)
    return p 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:6,代码来源:core.py

示例2: on_identity_loaded

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Principal [as 别名]
def on_identity_loaded(sender, identity):
    """Method for Flask Principal identity load listener
    """
    # set the identity user object
    identity.user = current_user

    if current_user.is_authenticated:
        # add UserNeed to identity
        identity.provides.add(UserNeed(current_user.id)) 
开发者ID:muicss,项目名称:flaskapp,代码行数:11,代码来源:__init__.py

示例3: init_app

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Principal [as 别名]
def init_app(self, app, storage=None, cache=None, file_upload=None):
        """
        Initialize the engine.

        :param app: The app to use
        :type app: Object
        :param storage: The blog storage instance that implements the
        :type storage: Object
        :param cache: (Optional) A Flask-Cache object to enable caching
        :type cache: Object
         ``Storage`` class interface.
        """

        self.app = app
        self.config = self.app.config
        self.storage = storage or self.storage
        self.file_upload = file_upload or self.file_upload
        self.cache = cache or self.cache
        self._register_plugins(self.app, self.config)

        from .views import create_blueprint
        blog_app = create_blueprint(__name__, self)
        # external urls
        blueprint_created.send(self.app, engine=self, blueprint=blog_app)
        self.app.register_blueprint(
            blog_app, url_prefix=self.config.get("BLOGGING_URL_PREFIX"))

        self.app.extensions["FLASK_BLOGGING_ENGINE"] = self  # duplicate
        self.app.extensions["blogging"] = self
        self.principal = Principal(self.app)
        engine_initialised.send(self.app, engine=self)

        if self.config.get("BLOGGING_ALLOW_FILEUPLOAD", True):
            self.ffu = self.file_upload or FlaskFileUpload(app) 
开发者ID:gouthambs,项目名称:Flask-Blogging,代码行数:36,代码来源:engine.py

示例4: _get_principal

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Principal [as 别名]
def _get_principal(self, app: FlaskUnchained) -> Principal:
        """
        Get an initialized instance of Flask Principal's.
        :class:~flask_principal.Principal`.
        """
        principal = Principal(app, use_sessions=False)
        principal.identity_loader(self._identity_loader)
        return principal 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:10,代码来源:security.py

示例5: _identity_loader

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Principal [as 别名]
def _identity_loader(self) -> Union[Identity, None]:
        """
        Identity loading function to be passed to be assigned to the Principal
        instance returned by :meth:`_get_principal`.
        """
        if not isinstance(current_user._get_current_object(), AnonymousUser):
            return Identity(current_user.id) 
开发者ID:briancappello,项目名称:flask-unchained,代码行数:9,代码来源:security.py

示例6: app_with_principal

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Principal [as 别名]
def app_with_principal():
    app = flask.Flask(__name__)
    app.config.from_object(testconfig.TestConfig())
    principal = Principal(app)
    return app, principal 
开发者ID:quay,项目名称:quay,代码行数:7,代码来源:test_v2_tuf.py

示例7: create_app

# 需要导入模块: import flask_principal [as 别名]
# 或者: from flask_principal import Principal [as 别名]
def create_app(extra_config=None):
    """Create Flask app for Flaskapp
    """
    app = Flask('flaskapp',
                template_folder='templates',
                static_folder='static')

    app.config.from_object('config')
    app.config.update(**(extra_config or {}))
    app.before_request(before_request)

    # import static file manifest
    js = pkg_resources.resource_string('flaskapp', '/static/rev-manifest.json')
    app.config['static_manifest'] = json.loads(js.decode('utf-8'))

    # configure jinja2
    app.jinja_env.globals.update({'h': template_helpers})

    # add Flask-WTForms CSRF Protection
    CSRFProtect(app)

    # init Flask-SQLAlchemy
    db.init_app(app)

    # init Flask-Principal
    Principal(app)
    identity_loaded.connect(on_identity_loaded, app)

    # init Flask-Login
    lm.init_app(app)
    lm.login_view = 'auth.login'
    lm.user_loader(load_user)

    # init Flask-Mail
    mail.init_app(app)

    # register blueprints
    app.register_blueprint(content.bp)
    app.register_blueprint(auth.bp, url_prefix='/auth')

    return app


# ===============================
# Helper methods
# =============================== 
开发者ID:muicss,项目名称:flaskapp,代码行数:48,代码来源:__init__.py


注:本文中的flask_principal.Principal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。