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


Python User.from_session_token方法代码示例

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


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

示例1: test_user_can_be_loaded_from_session_token

# 需要导入模块: from gittip.security.user import User [as 别名]
# 或者: from gittip.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()
     token = user.participant.session_token
     actual = User.from_session_token(token).participant.username
     assert actual == 'alice'
开发者ID:Aaron1011,项目名称:www.gittip.com,代码行数:9,代码来源:test_user.py

示例2: inbound

# 需要导入模块: from gittip.security.user import User [as 别名]
# 或者: from gittip.security.user.User import from_session_token [as 别名]
def inbound(request):
    """Authenticate from a cookie or an API key in basic auth.
    """
    user = None
    if '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)

    if user is None:
        user = User()
    request.context['user'] = user
开发者ID:abnor,项目名称:www.gittip.com,代码行数:27,代码来源:authentication.py

示例3: test_user_from_expired_session_is_anonymous

# 需要导入模块: from gittip.security.user import User [as 别名]
# 或者: from gittip.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:Alive-AttemptTheLifeGangHouse,项目名称:www.gittip.com,代码行数:10,代码来源:test_user.py

示例4: inbound

# 需要导入模块: from gittip.security.user import User [as 别名]
# 或者: from gittip.security.user.User import from_session_token [as 别名]
def inbound(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:venmo,项目名称:www.gittip.com,代码行数:26,代码来源:authentication.py

示例5: test_user_from_None_session_token_is_anonymous

# 需要导入模块: from gittip.security.user import User [as 别名]
# 或者: from gittip.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:Aaron1011,项目名称:www.gittip.com,代码行数:7,代码来源:test_user.py

示例6: test_user_from_bad_session_token_is_anonymous

# 需要导入模块: from gittip.security.user import User [as 别名]
# 或者: from gittip.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:Aaron1011,项目名称:www.gittip.com,代码行数:5,代码来源:test_user.py


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