本文整理汇总了Python中flask_login.current_user.roles方法的典型用法代码示例。如果您正苦于以下问题:Python current_user.roles方法的具体用法?Python current_user.roles怎么用?Python current_user.roles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask_login.current_user
的用法示例。
在下文中一共展示了current_user.roles方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requires_roles
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import roles [as 别名]
def requires_roles(required_roles):
'''
Takes in a list of roles and checks whether the user
has access to those role
'''
def check_roles(view_function):
@wraps(view_function)
def decorated_function(*args, **kwargs):
def names(role):
return role.name
if not all(r in map(names, current_user.roles) for r in required_roles):
flash('You do not have sufficient permissions to do that', 'alert alert-danger')
return redirect(request.args.get('next') or '/')
return view_function(*args, **kwargs)
return decorated_function
return check_roles
示例2: on_identity_loaded
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import roles [as 别名]
def on_identity_loaded(sender, identity):
# Set the identity user object
identity.user = current_user
# Add the UserNeed to the identity
if hasattr(current_user, 'username'):
identity.provides.add(UserNeed(current_user.username))
# Assuming the User model has a list of roles, update the
# identity with the roles that the user provides
if hasattr(current_user, 'role'):
# for role in current_user.roles:
identity.provides.add(RoleNeed(current_user.role))
# if current_user.is_superuser:
if hasattr(current_user, 'is_superuser') and current_user.is_superuser:
identity.provides.add(su_need)
# return current_user.role
identity.allow_su = su_permission.allows(identity)
identity.allow_admin = admin_permission.allows(identity)
identity.allow_edit = editor_permission.allows(identity)
identity.allow_general = general_permission.allows(identity)
示例3: make_cache_key
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import roles [as 别名]
def make_cache_key(*args, **kwargs):
path = request.path
args = str(hash(frozenset(request.args.items())))
messages = str(hash(frozenset(get_flashed_messages())))
if current_user.is_authenticated:
roles = str(current_user.roles)
else:
roles = ""
return (path + args + roles + session.get('locale', '') + messages).encode('utf-8')
开发者ID:PacktPublishing,项目名称:Mastering-Flask-Web-Development-Second-Edition,代码行数:11,代码来源:controllers.py
示例4: index
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import roles [as 别名]
def index(map_identifier, topic_identifier):
topic_store = get_topic_store()
if "admin" not in current_user.roles:
abort(403)
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
attributes = []
entity_attributes = topic_store.get_attributes(map_identifier, topic_identifier)
for entity_attribute in entity_attributes:
attributes.append(
{
"identifier": entity_attribute.identifier,
"name": entity_attribute.name,
"value": entity_attribute.value,
"type": str(entity_attribute.data_type).lower(),
"scope": entity_attribute.scope,
}
)
creation_date_attribute = topic.get_attribute_by_name("creation-timestamp")
creation_date = maya.parse(creation_date_attribute.value) if creation_date_attribute else "Undefined"
entity_type = "topic"
return_url = "topic.view"
return render_template(
"attribute/index.html",
topic_map=topic_map,
topic=topic,
entity_type=entity_type,
return_url=return_url,
attributes=attributes,
creation_date=creation_date,
)
示例5: delete
# 需要导入模块: from flask_login import current_user [as 别名]
# 或者: from flask_login.current_user import roles [as 别名]
def delete(map_identifier, topic_identifier, attribute_identifier):
topic_store = get_topic_store()
if "admin" not in current_user.roles:
abort(403)
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
# If the map doesn't belong to the user and they don't have the right
# collaboration mode on the map, then abort
if not topic_map.owner and topic_map.collaboration_mode is not CollaborationMode.EDIT:
abort(403)
topic = topic_store.get_topic(
map_identifier, topic_identifier, resolve_attributes=RetrievalMode.RESOLVE_ATTRIBUTES,
)
if topic is None:
abort(404)
attribute = topic_store.get_attribute(map_identifier, attribute_identifier)
if attribute is None:
abort(404)
form_attribute_name = attribute.name
form_attribute_value = attribute.value
form_attribute_type = str(attribute.data_type).capitalize()
form_attribute_scope = attribute.scope
if request.method == "POST":
# Delete attribute from topic store
topic_store.delete_attribute(map_identifier, attribute.identifier)
flash("Attribute successfully deleted.", "warning")
return redirect(
url_for("attribute.index", map_identifier=topic_map.identifier, topic_identifier=topic.identifier,)
)
entity_type = "topic"
post_url = "attribute.delete"
cancel_url = "attribute.index"
return render_template(
"attribute/delete.html",
topic_map=topic_map,
topic=topic,
attribute=attribute,
entity_type=entity_type,
post_url=post_url,
cancel_url=cancel_url,
attribute_name=form_attribute_name,
attribute_value=form_attribute_value,
attribute_type=form_attribute_type,
attribute_scope=form_attribute_scope,
)