本文整理汇总了Python中flask_security.current_user.is_authenticated方法的典型用法代码示例。如果您正苦于以下问题:Python current_user.is_authenticated方法的具体用法?Python current_user.is_authenticated怎么用?Python current_user.is_authenticated使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_security.current_user
的用法示例。
在下文中一共展示了current_user.is_authenticated方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inject_user_tags
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def inject_user_tags():
if not current_user.is_authenticated:
return {
"user_tags": None
}
else:
user_tags = Tag.query.filter(Tag.user == current_user.id,
Tag.count > 0).all()
user_tags.sort(key=lambda k: k.text.lower())
user_tags = [{'text': tag.text.encode('utf-8'),
'value': tag.text.encode('utf-8'),
'count': tag.count} for tag in user_tags if
tag.text != '']
return {
"user_tags": user_tags
}
示例2: is_accessible
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def is_accessible(self):
if not current_user.is_active or not current_user.is_authenticated:
return False
if current_user.has_role('admin'):
return True
return False
示例3: _handle_view
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def _handle_view(self, name, **kwargs):
"""
Override builtin _handle_view in order to redirect users when a
view is not accessible.
"""
if not self.is_accessible():
if current_user.is_authenticated:
# permission denied
abort(403)
else:
# login
return redirect(url_for('security.login', next=request.url))
示例4: is_accessible
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def is_accessible(self):
return current_user.is_authenticated and current_user.has_role("admin")
示例5: index
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def index(self):
if not current_user.is_authenticated:
return redirect(url_for("security.login"))
if not any(map(current_user.has_role, ("developer", "package_admin", "admin"))):
abort(403)
return super(IndexView, self).index()
示例6: inject_bmark_count
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def inject_bmark_count():
if current_user.is_authenticated:
bookmark_count = Bookmark.query.filter_by(user=current_user.id, deleted=False).count()
return dict(bookmark_count=bookmark_count)
return dict(bookmark_count=0)
示例7: view
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def view(map_identifier):
topic_store = get_topic_store()
collaboration_mode = None
if current_user.is_authenticated: # User is logged in
is_map_owner = topic_store.is_topic_map_owner(map_identifier, current_user.id)
if is_map_owner:
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
else:
topic_map = topic_store.get_topic_map(map_identifier)
if topic_map is None:
abort(404)
collaboration_mode = topic_store.get_collaboration_mode(map_identifier, current_user.id)
# The map is private and doesn't belong to the user who is trying to
# access it
if not topic_map.published and not is_map_owner:
if not collaboration_mode: # The user is not collaborating on the map
abort(403)
else: # User is not logged in
topic_map = topic_store.get_topic_map(map_identifier)
if topic_map is None:
abort(404)
if not topic_map.published: # User is not logged in and the map is not published
abort(403)
return render_template("map/view.html", topic_map=topic_map)
示例8: is_accessible
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def is_accessible(self):
if not current_user.is_active or not current_user.is_authenticated:
return False
if current_user.has_role('superuser'):
return True
return False
示例9: _handle_view
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def _handle_view(self, name, **kwargs):
if current_user.is_authenticated:
pass
else:
return redirect(url_for('security.login', next=request.url))
示例10: index
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def index(self):
if not current_user.is_authenticated:
return redirect(url_for('security.login'))
return super(ProxyPoolAdminIndexView, self).index()
示例11: write_activity_on_follow
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def write_activity_on_follow(follow, **kwargs):
if current_user.is_authenticated:
if isinstance(follow.following, Dataset):
UserFollowedDataset.emit(follow.following)
elif isinstance(follow.following, Reuse):
UserFollowedReuse.emit(follow.following)
elif isinstance(follow.following, Organization):
UserFollowedOrganization.emit(follow.following)
elif isinstance(follow.following, User):
UserFollowedUser.emit(follow.following)
示例12: write_activity_on_discuss
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def write_activity_on_discuss(discussion, **kwargs):
if current_user.is_authenticated:
if isinstance(discussion.subject, Dataset):
UserDiscussedDataset.emit(discussion.subject)
elif isinstance(discussion.subject, Reuse):
UserDiscussedReuse.emit(discussion.subject)
示例13: on_user_created_reuse
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def on_user_created_reuse(reuse):
if not reuse.private and current_user and current_user.is_authenticated:
UserCreatedReuse.emit(reuse, reuse.organization)
示例14: on_user_updated_reuse
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def on_user_updated_reuse(reuse):
if not reuse.private and current_user and current_user.is_authenticated:
UserUpdatedReuse.emit(reuse, reuse.organization)
示例15: on_user_deleted_reuse
# 需要导入模块: from flask_security import current_user [as 别名]
# 或者: from flask_security.current_user import is_authenticated [as 别名]
def on_user_deleted_reuse(reuse):
if not reuse.private and current_user and current_user.is_authenticated:
UserDeletedReuse.emit(reuse, reuse.organization)