當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。