本文整理汇总了Python中flask_principal.identity_loaded.connect_via方法的典型用法代码示例。如果您正苦于以下问题:Python identity_loaded.connect_via方法的具体用法?Python identity_loaded.connect_via怎么用?Python identity_loaded.connect_via使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_principal.identity_loaded
的用法示例。
在下文中一共展示了identity_loaded.connect_via方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_app
# 需要导入模块: from flask_principal import identity_loaded [as 别名]
# 或者: from flask_principal.identity_loaded import connect_via [as 别名]
def init_app(self, app: FlaskUnchained):
# NOTE: the order of these `self.get_*` calls is important!
self.confirm_serializer = self._get_serializer(app, 'confirm')
self.hashing_context = self._get_hashing_context(app)
self.login_manager = self._get_login_manager(
app, app.config.SECURITY_ANONYMOUS_USER)
self.login_serializer = self._get_serializer(app, 'login')
self.principal = self._get_principal(app)
self.pwd_context = self._get_pwd_context(app)
self.remember_token_serializer = self._get_serializer(app, 'remember')
self.reset_serializer = self._get_serializer(app, 'reset')
self.context_processor(lambda: dict(security=_SecurityConfigProperties()))
# FIXME: should this be easier to customize for end users, perhaps by making
# FIXME: the function come from a config setting?
identity_loaded.connect_via(app)(self._on_identity_loaded)
app.extensions['security'] = self
示例2: init_app
# 需要导入模块: from flask_principal import identity_loaded [as 别名]
# 或者: from flask_principal.identity_loaded import connect_via [as 别名]
def init_app(self, app):
self._state = super().init_app(app, self.datastore, **self._kwargs)
# override the unauthorized action to use abort(401) instead of returning HTML
self._state.unauthorized_handler(unauthorized_handler)
# register a celery task to send emails asynchronously
self._state.send_mail_task(send_mail_async)
# load user's role hierarchy
identity_loaded.connect_via(app)(on_identity_loaded)
# only activate users after they've been confirmed
if self.confirmable:
user_confirmed.connect_via(app)(_on_user_confirmed)
if not self._kwargs['register_blueprint']:
app.context_processor(_context_processor)
app.extensions['security'] = self
示例3: app
# 需要导入模块: from flask_principal import identity_loaded [as 别名]
# 或者: from flask_principal.identity_loaded import connect_via [as 别名]
def app(appconfig, initialized_db):
"""
Used by pytest-flask plugin to inject a custom app instance for testing.
"""
app = Flask(__name__)
login_manager = LoginManager(app)
@app.errorhandler(model.DataModelException)
def handle_dme(ex):
response = jsonify({"message": str(ex)})
response.status_code = 400
return response
@login_manager.user_loader
def load_user(user_uuid):
return LoginWrappedDBUser(user_uuid)
@identity_loaded.connect_via(app)
def on_identity_loaded_for_test(sender, identity):
on_identity_loaded(sender, identity)
Principal(app, use_sessions=False)
app.url_map.converters["regex"] = RegexConverter
app.url_map.converters["apirepopath"] = APIRepositoryPathConverter
app.url_map.converters["repopath"] = RepositoryPathConverter
app.register_blueprint(api_bp, url_prefix="/api")
app.register_blueprint(appr_bp, url_prefix="/cnr")
app.register_blueprint(web, url_prefix="/")
app.register_blueprint(verbs_bp, url_prefix="/c1")
app.register_blueprint(v1_bp, url_prefix="/v1")
app.register_blueprint(v2_bp, url_prefix="/v2")
app.register_blueprint(webhooks, url_prefix="/webhooks")
app.config.update(appconfig)
Userfiles(app)
Mail(app)
return app
示例4: init_app
# 需要导入模块: from flask_principal import identity_loaded [as 别名]
# 或者: from flask_principal.identity_loaded import connect_via [as 别名]
def init_app(app):
@identity_loaded.connect_via(app)
def on_identity_loaded(sender, identity):
'''基础权限'''
identity.user = current_user
if hasattr(current_user, 'id'):
identity.provides.add(UserNeed(current_user.id))
if hasattr(current_user, 'is_superuser'):
if current_user.is_superuser:
identity.provides.add(RoleNeed('super'))
if hasattr(current_user, 'is_confirmed'):
if current_user.is_confirmed:
identity.provides.add(RoleNeed('confirmed'))
if hasattr(current_user, 'is_authenticated'):
if current_user.is_authenticated:
identity.provides.add(RoleNeed('auth'))
else:
identity.provides.add(RoleNeed('guest'))
if hasattr(current_user, 'topics'):
for topic in current_user.topics:
identity.provides.add(TopicNeed(topic.id))
if hasattr(current_user, 'replies'):
for reply in current_user.replies:
identity.provides.add(ReplyNeed(reply.id))
if hasattr(current_user, 'collects'):
for collect in current_user.collects:
identity.provides.add(CollectNeed(collect.id))
示例5: create_app
# 需要导入模块: from flask_principal import identity_loaded [as 别名]
# 或者: from flask_principal.identity_loaded import connect_via [as 别名]
def create_app(config_name):
"""
application initialization
:param config_name:
:return:
"""
app = Flask(__name__)
app.config.from_object(config[config_name])
mail.init_app(app)
db.init_app(app)
login_manager.init_app(app)
ldap.init_app(app)
# flask_principal
principals.init_app(app)
@identity_loaded.connect_via(app)
def on_identity_loaded(sender, identity):
identity.user = current_user
if hasattr(current_user, 'id'):
identity.provides.add(UserNeed(current_user.id))
if hasattr(current_user, 'role'):
identity.provides.add(RoleNeed(current_user.role))
# celery
celery.init_app(app)
# register blue_print
from .auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint, url_prefix='/auth')
from .main import main as main_blueprint
app.register_blueprint(main_blueprint)
from .admin import admin as admin_blueprint
app.register_blueprint(admin_blueprint)
from .audit import audit as audit_blueprint
app.register_blueprint(audit_blueprint)
from .dev import dev as dev_blueprint
app.register_blueprint(dev_blueprint)
return app