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


Python g.current_user方法代码示例

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


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

示例1: has_item_write_permission

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def has_item_write_permission(self, user_id, item):
        """Check if the user is allowed to modify the item.

        Implement this function for your resource.
        Default behaviour: No user has write permission.

        Args:
            user (str): The id of the user that wants to access the item
            item (dict): The item the user wants to change or delete.
                Attention! If they are any ObjectIds in here, Eve will not have
                converted them yet, so be sure to cast them to str if you want
                to compare them to e.g. g.current_user

        Returns:
            bool: True if user has permission to change the item, False if not.
        """
        return False 
开发者ID:amiv-eth,项目名称:amivapi,代码行数:19,代码来源:auth.py

示例2: test_authentication_defaults

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def test_authentication_defaults(self):
        """Make sure authenticate sets defaults for all auth values."""
        expect_none = 'current_token', 'current_user', 'current_session'
        expect_false = 'resource_admin', 'resource_admin_readonly'

        with self.app.test_request_context():
            # Nothing there before
            for item in expect_none + expect_false:
                with self.assertRaises(AttributeError):
                    getattr(g, item)

            authenticate()
            for item in expect_none:
                self.assertIsNone(getattr(g, item))

            check_if_admin('someresource')
            for item in expect_false:
                self.assertFalse(getattr(g, item)) 
开发者ID:amiv-eth,项目名称:amivapi,代码行数:20,代码来源:test_auth.py

示例3: _validate_only_self_enrollment_for_event

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def _validate_only_self_enrollment_for_event(self, enabled, field, value):
        """Validate if the user can be used to enroll for an event.

        1.  Anyone can signup with no user id
        2.  other id: Registered users can only enter their own id
        3.  Exception are resource admins: they can sign up others as well

        Args:
            enabled (bool): validates nothing if set to false
            field (string): field name
            value: field value

        The rule's arguments are validated against this schema:
        {'type': 'boolean'}
        """
        if enabled:
            if g.resource_admin or value is None:
                return
            if g.get('current_user') != str(value):
                self._error(field, "You can only enroll yourself. (%s: "
                                   "%s is yours)." % (field, g.current_user)) 
开发者ID:amiv-eth,项目名称:amivapi,代码行数:23,代码来源:authorization.py

示例4: new_post_comment

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def new_post_comment(id):
    post = Post.query.get_or_404(id)
    comment = Comment.from_json(request.json)
    comment.author = g.current_user
    comment.post = post
    db.session.add(comment)
    db.session.commit()
    return jsonify(comment.to_json()), 201, \
        {'Location': url_for('api.get_comment', id=comment.id,
                             _external=True)} 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:12,代码来源:comments.py

示例5: new_post

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def new_post():
    post = Post.from_json(request.json)
    post.author = g.current_user
    db.session.add(post)
    db.session.commit()
    return jsonify(post.to_json()), 201, \
        {'Location': url_for('api.get_post', id=post.id, _external=True)} 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:9,代码来源:posts.py

示例6: edit_post

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def edit_post(id):
    post = Post.query.get_or_404(id)
    if g.current_user != post.author and \
            not g.current_user.can(Permission.ADMINISTER):
        return forbidden('Insufficient permissions')
    post.body = request.json.get('body', post.body)
    db.session.add(post)
    return jsonify(post.to_json()) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:10,代码来源:posts.py

示例7: verify_password

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def verify_password(email_or_token, password):
    if email_or_token == '':
        g.current_user = AnonymousUser()
        return True
    if password == '':
        g.current_user = User.verify_auth_token(email_or_token)
        g.token_used = True
        return g.current_user is not None
    user = User.query.filter_by(email=email_or_token).first()
    if not user:
        return False
    g.current_user = user
    g.token_used = False
    return user.verify_password(password) 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:16,代码来源:authentication.py

示例8: before_request

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def before_request():
    if not g.current_user.is_anonymous and \
            not g.current_user.confirmed:
        return forbidden('Unconfirmed account') 
开发者ID:CircleCI-Public,项目名称:circleci-demo-python-flask,代码行数:6,代码来源:authentication.py

示例9: new_post_comment

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def new_post_comment(id):
    post = Post.query.get_or_404(id)
    comment = Comment.from_json(request.json)
    comment.author = g.current_user
    comment.post = post
    db.session.add(comment)
    db.session.commit()
    return jsonify(comment.to_json()), 201, \
        {'Location': url_for('api.get_comment', id=comment.id,_external=True)} 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:11,代码来源:comments.py

示例10: new_post

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def new_post():
    post = Post.from_json(request.json)
    post.author = g.current_user
    db.session.add(post)
    db.session.commit()
    return jsonify(post.to_json()), 201, {'Location': url_for('api.get_post',id=post.id, _external=True)}

# put请求 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:10,代码来源:posts.py

示例11: edit_post

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def edit_post(id):
    post = Post.query.get_or_404(id)
    if g.current_user != post.author and \
            not g.current_user.operation(Permission.ADMINISTER):
        return forbidden('Insufficient permissions')
    post.title = request.json.get('title', post.title)
    post.body = request.json.get('body', post.body)
    db.session.add(post)
    return jsonify(post.to_json()) 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:11,代码来源:posts.py

示例12: before_request

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def before_request():
    if not g.current_user.is_authenticated:
        return forbidden('Unconfirmed account') 
开发者ID:Blackyukun,项目名称:Simpleblog,代码行数:5,代码来源:authentication.py

示例13: verify_password

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def verify_password(username, password):
    """Check username and password with stored password hash from database."""
    user = User.query.filter_by(username=username).first()
    if user is None:
        return False
    g.current_user = user
    return user.check_password(password) 
开发者ID:AUCR,项目名称:AUCR,代码行数:9,代码来源:auth.py

示例14: verify_token

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def verify_token(token):
    """API verify auth user token."""
    g.current_user = User.check_token(token) if token else None
    return g.current_user is not None 
开发者ID:AUCR,项目名称:AUCR,代码行数:6,代码来源:auth.py

示例15: auth_required

# 需要导入模块: from flask import g [as 别名]
# 或者: from flask.g import current_user [as 别名]
def auth_required(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        token = request.headers.get('Authorization', '')
        if token:
            user = verify_token(token)
            if user:
                g.current_user = user
                return func(*args, **kwargs)
        return UNAUTHORIZED
    return wrapper 
开发者ID:projectweekend,项目名称:Flask-PostgreSQL-API-Seed,代码行数:13,代码来源:auth.py


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