本文整理匯總了Python中common.crypto.XsrfTokenManager.is_xsrf_token_valid方法的典型用法代碼示例。如果您正苦於以下問題:Python XsrfTokenManager.is_xsrf_token_valid方法的具體用法?Python XsrfTokenManager.is_xsrf_token_valid怎麽用?Python XsrfTokenManager.is_xsrf_token_valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類common.crypto.XsrfTokenManager
的用法示例。
在下文中一共展示了XsrfTokenManager.is_xsrf_token_valid方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: assert_xsrf_token_or_fail
# 需要導入模塊: from common.crypto import XsrfTokenManager [as 別名]
# 或者: from common.crypto.XsrfTokenManager import is_xsrf_token_valid [as 別名]
def assert_xsrf_token_or_fail(self, request, action):
"""Asserts the current request has proper XSRF token or fails."""
token = request.get('xsrf_token')
if not token or not XsrfTokenManager.is_xsrf_token_valid(token, action):
self.error(403)
return False
return True
示例2: assert_xsrf_token_or_fail
# 需要導入模塊: from common.crypto import XsrfTokenManager [as 別名]
# 或者: from common.crypto.XsrfTokenManager import is_xsrf_token_valid [as 別名]
def assert_xsrf_token_or_fail(self, token_dict, action, args_dict):
"""Asserts that current request has proper XSRF token or fails."""
token = token_dict.get("xsrf_token")
if not token or not XsrfTokenManager.is_xsrf_token_valid(token, action):
transforms.send_json_response(self, 403, "Bad XSRF token. Please reload the page and try again", args_dict)
return False
return True
示例3: post
# 需要導入模塊: from common.crypto import XsrfTokenManager [as 別名]
# 或者: from common.crypto.XsrfTokenManager import is_xsrf_token_valid [as 別名]
def post(self):
"""Handles POST."""
action = self.request.get('action')
if not action or action not in self.post_actions:
self.error(404)
return
handler = getattr(self, 'post_%s' % action)
if not handler:
self.error(404)
return
# Each POST request must have valid XSRF token.
xsrf_token = self.request.get('xsrf_token')
if not XsrfTokenManager.is_xsrf_token_valid(xsrf_token, action):
self.error(403)
return
return handler()