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


Python User.from_session_token方法代码示例

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


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

示例1: get_auth_from_request

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_session_token [as 别名]
def get_auth_from_request(request):
    """Authenticate from a cookie or an API key in basic auth.
    """
    user = None
    if request.line.uri.startswith('/assets/'):
        pass
    elif 'Authorization' in request.headers:
        header = request.headers['authorization']
        if header.startswith('Basic '):
            creds = header[len('Basic '):].decode('base64')
            token, ignored = creds.split(':')
            user = User.from_api_key(token)

            # We don't require CSRF if they basically authenticated.
            csrf_token = csrf._get_new_csrf_key()
            request.headers.cookie['csrf_token'] = csrf_token
            request.headers['X-CSRF-TOKEN'] = csrf_token
            if 'Referer' not in request.headers:
                request.headers['Referer'] = \
                                        'https://%s/' % csrf._get_host(request)
    elif SESSION in request.headers.cookie:
        token = request.headers.cookie[SESSION].value
        user = User.from_session_token(token)

    request.context['user'] = user or User()
开发者ID:beerm,项目名称:gratipay.com,代码行数:27,代码来源:authentication.py

示例2: test_user_can_be_loaded_from_session_token

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_session_token [as 别名]
 def test_user_can_be_loaded_from_session_token(self):
     self.make_participant('alice')
     user = User.from_username('alice')
     user.sign_in(SimpleCookie())
     token = user.participant.session_token
     actual = User.from_session_token(token).participant.username
     assert actual == 'alice'
开发者ID:SirCmpwn,项目名称:gratipay.com,代码行数:9,代码来源:test_user.py

示例3: test_user_from_expired_session_is_anonymous

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_session_token [as 别名]
 def test_user_from_expired_session_is_anonymous(self):
     self.make_participant('alice')
     user = User.from_username('alice')
     user.sign_in(SimpleCookie())
     token = user.participant.session_token
     user.participant.set_session_expires(utcnow())
     user = User.from_session_token(token)
     assert user.ANON
开发者ID:SirCmpwn,项目名称:gratipay.com,代码行数:10,代码来源:test_user.py

示例4: authenticate_user_if_possible

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_session_token [as 别名]
def authenticate_user_if_possible(request, user):
    """This signs the user in.
    """
    if request.line.uri.startswith('/assets/'):
        pass
    elif 'Authorization' in request.headers:
        header = request.headers['authorization']
        if header.startswith('Basic '):
            user = _get_user_via_basic_auth(header)
            if not user.ANON:
                _turn_off_csrf(request)
    elif SESSION in request.headers.cookie:
        token = request.headers.cookie[SESSION].value
        user = User.from_session_token(token)
    return {'user': user}
开发者ID:HolaChica,项目名称:gratipay.com,代码行数:17,代码来源:authentication.py

示例5: set_request_context_user

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_session_token [as 别名]
def set_request_context_user(request):
    """Set request.context['user']. This signs the user in.
    """

    request.context['user'] = user = ANON  # Make sure we always have a user object, even if
                                           # there's an exception in the rest of this function.

    if request.line.uri.startswith('/assets/'):
        pass
    elif 'Authorization' in request.headers:
        header = request.headers['authorization']
        if header.startswith('Basic '):
            user = _get_user_via_basic_auth(header)
            if not user.ANON:
                _turn_off_csrf(request)
    elif SESSION in request.headers.cookie:
        token = request.headers.cookie[SESSION].value
        user = User.from_session_token(token)

    request.context['user'] = user
开发者ID:rohitpaulk,项目名称:gratipay.com,代码行数:22,代码来源:authentication.py

示例6: test_user_from_None_session_token_is_anonymous

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_session_token [as 别名]
 def test_user_from_None_session_token_is_anonymous(self):
     self.make_participant('alice')
     self.make_participant('bob')
     user = User.from_session_token(None)
     assert user.ANON
开发者ID:SirCmpwn,项目名称:gratipay.com,代码行数:7,代码来源:test_user.py

示例7: test_user_from_bad_session_token_is_anonymous

# 需要导入模块: from gratipay.security.user import User [as 别名]
# 或者: from gratipay.security.user.User import from_session_token [as 别名]
 def test_user_from_bad_session_token_is_anonymous(self):
     user = User.from_session_token('deadbeef')
     assert user.ANON
开发者ID:SirCmpwn,项目名称:gratipay.com,代码行数:5,代码来源:test_user.py


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