本文整理汇总了Python中controllers.utils.XsrfTokenManager.is_xsrf_token_valid方法的典型用法代码示例。如果您正苦于以下问题:Python XsrfTokenManager.is_xsrf_token_valid方法的具体用法?Python XsrfTokenManager.is_xsrf_token_valid怎么用?Python XsrfTokenManager.is_xsrf_token_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类controllers.utils.XsrfTokenManager
的用法示例。
在下文中一共展示了XsrfTokenManager.is_xsrf_token_valid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import is_xsrf_token_valid [as 别名]
def post(self):
if not users.is_current_user_admin():
self.abort(403)
if not XsrfTokenManager.is_xsrf_token_valid(self.request.POST.get('xsrf_token', ''), 'post'):
self.abort(403, 'XSRF token failed.')
form = self.Form(self.request.POST)
if not form.validate():
self.response.write('<br>'.join(form.errors))
return
student = Student.get_by_key_name(form.email.data)
report = PartReport.on(student, course=self.get_course(),
part=form.part.data,
force_re_run=form.re_run.data,
put=form.really_save.data)
badge_version = choose_badge_version(part_config[form.part.data]['slug'], report.completion())
if badge_version:
badge = Badge.get_by_key_name(badge_version)
if not badge:
self.response.write(' There is no badge with key_name %s (so I cannot issue a badge)' % badge_version)
if form.really_save.data and badge:
b = Badge.issue(badge, student, put=False)
b.evidence = self.request.host_url + '/badges/evidence?id=%d' % report.key().id()
b.put()
self.response.write('Issued badge %s!' % badge_version)
else:
self.response.write('Would have issued badge %s!' % badge_version)
else:
self.response.write('Not issuing because at least one of: %s' % (', '.join(report.incomplete_reasons)))
示例2: is_valid_xsrf_token
# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import is_xsrf_token_valid [as 别名]
def is_valid_xsrf_token(self, action):
"""Asserts the current request has proper XSRF token or fails."""
token = self.request.get('xsrf_token')
return token and XsrfTokenManager.is_xsrf_token_valid(token, action)