本文整理汇总了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'
示例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
示例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
示例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()
示例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
示例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