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


Python XsrfTokenManager.create_xsrf_token方法代码示例

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


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

示例1: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
 def get(self):
     """Provides empty initial content for asset upload editor."""
     # TODO(jorr): Pass base URI through as request param when generalized.
     json_payload = {'file': '', 'base': ALLOWED_ASSET_UPLOAD_BASE}
     transforms.send_json_response(
         self, 200, 'Success.', payload_dict=json_payload,
         xsrf_token=XsrfTokenManager.create_xsrf_token('asset-upload'))
开发者ID:CSavvy,项目名称:coursebuilder,代码行数:9,代码来源:filer.py

示例2: render

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def render(self, node, context):
        """Renders the submit button."""

        xsrf_token = XsrfTokenManager.create_xsrf_token(
            QUESTIONNAIRE_XSRF_TOKEN_NAME)
        form_id = node.attrib.get('form-id')
        button_label = node.attrib.get('button-label')
        disabled = (node.attrib.get('disabled') == 'true')
        post_message = node.text

        user = context.handler.get_user()
        registered = False
        if user and models.Student.get_enrolled_student_by_user(user):
            registered = True

        template_vals = {
            'xsrf_token': xsrf_token,
            'form_id': form_id,
            'button_label': button_label,
            'disabled': disabled,
            'registered': registered,
            'post_message': post_message,
        }
        template = jinja_utils.get_template(
            'questionnaire.html', [TEMPLATES_DIR])
        button = template.render(template_vals)
        return tags.html_string_to_element_tree(button)
开发者ID:JuanCarlosllh,项目名称:GCB-Modding-Introduction,代码行数:29,代码来源:questionnaire.py

示例3: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Provides empty initial content for asset upload editor."""
        # TODO(jorr): Pass base URI through as request param when generalized.
        key = self.request.get('key')
        base = asset_paths.AllowedBases.match_allowed_bases(key)
        if not base:
            transforms.send_json_response(
                self, 400, 'Malformed request.', {'key': key})
            return

        json_payload = {
            'key': key,
            'base': base,
        }
        fs = self.app_context.fs.impl
        if fs.isfile(fs.physical_to_logical(key)):
            json_payload['asset_url'] = key
            # TODO(davyrisso): Remove when cached assets issues are solved.
            # We add a random seed to the URL to force a reload, we also append
            # the URL because oeditor expects it to end with the filename.
            suffix = ('?seed=%s&url=%s' % (
                str(random.randint(0, 100000)), json_payload['asset_url']))
            json_payload['asset_url'] += suffix
        else:
            json_payload['asset_url'] = asset_paths.relative_base(base)
        transforms.send_json_response(
            self, 200, 'Success.', payload_dict=json_payload,
            xsrf_token=XsrfTokenManager.create_xsrf_token(self.XSRF_TOKEN_NAME))
开发者ID:google,项目名称:coursebuilder-core,代码行数:30,代码来源:filer.py

示例4: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Get the data to populate the question editor form."""
        key = self.request.get('key')

        if not CourseOutlineRights.can_view(self):
            transforms.send_json_response(
                self, 401, 'Access denied.', {'key': key})
            return

        if key:
            question = QuestionDAO.load(key)
            payload_dict = question.dict
        else:
            payload_dict = {
                'version': self.SCHEMA_VERSION,
                'question': '',
                'description': '',
                'graders': [
                    {
                        'score': '1.0',
                        'matcher': 'case_insensitive',
                        'response': '',
                        'feedback': ''}]}

        transforms.send_json_response(
            self, 200, 'Success',
            payload_dict=payload_dict,
            xsrf_token=XsrfTokenManager.create_xsrf_token(self.XSRF_TOKEN))
开发者ID:AppScale,项目名称:coursebuilder,代码行数:30,代码来源:question_editor.py

示例5: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles REST GET verb and returns an object as JSON payload."""
        assert self.app_context.is_editable_fs()

        key = self.request.get('key')

        if not CourseSettingsRights.can_view(self):
            transforms.send_json_response(
                self, 401, 'Access denied.', {'key': key})
            return

        # Load data if possible.
        fs = self.app_context.fs.impl
        filename = fs.physical_to_logical('/course.yaml')
        try:
            stream = fs.get(filename)
        except:  # pylint: disable=bare-except
            stream = None
        if not stream:
            transforms.send_json_response(
                self, 404, 'Object not found.', {'key': key})
            return

        # Prepare data.
        json_payload = self.process_get()
        transforms.send_json_response(
            self, 200, 'Success.',
            payload_dict=json_payload,
            xsrf_token=XsrfTokenManager.create_xsrf_token(self.XSRF_ACTION))
开发者ID:CSCI1200Course,项目名称:csci1200OnlineCourse,代码行数:31,代码来源:course_settings.py

示例6: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles REST GET verb and returns an object as JSON payload."""

        if not CourseOutlineRights.can_view(self):
            transforms.send_json_response(self, 401, "Access denied.", {})
            return

        course = courses.Course(self)
        outline_data = []
        for unit in course.get_units():
            lesson_data = []
            for lesson in course.get_lessons(unit.unit_id):
                lesson_data.append({"title": lesson.title, "id": lesson.lesson_id})
            unit_title = unit.title
            if verify.UNIT_TYPE_UNIT == unit.type:
                unit_title = "Unit %s - %s" % (unit.index, unit.title)
            outline_data.append({"title": unit_title, "id": unit.unit_id, "lessons": lesson_data})

        transforms.send_json_response(
            self,
            200,
            "Success.",
            payload_dict={"outline": outline_data},
            xsrf_token=XsrfTokenManager.create_xsrf_token("unit-lesson-reorder"),
        )
开发者ID:henrymp,项目名称:coursebuilder,代码行数:27,代码来源:unit_lesson_editor.py

示例7: test_attempt_activity_event

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def test_attempt_activity_event(self):
        """Test activity attempt generates event."""

        email = '[email protected]'
        name = 'Test Attempt Activity Event'

        actions.login(email)
        actions.register(self, name)

        # Enable event recording.
        config.Registry.db_overrides[
            lessons.CAN_PERSIST_ACTIVITY_EVENTS.name] = True

        # Prepare event.
        request = {}
        request['source'] = 'test-source'
        request['payload'] = json.dumps({'Alice': 'Bob'})

        # Check XSRF token is required.
        response = self.post('rest/events?%s' % urllib.urlencode(
            {'request': json.dumps(request)}), {})
        assert_equals(response.status_int, 200)
        assert_contains('"status": 403', response.body)

        # Check PUT works.
        request['xsrf_token'] = XsrfTokenManager.create_xsrf_token(
            'event-post')
        response = self.post('rest/events?%s' % urllib.urlencode(
            {'request': json.dumps(request)}), {})
        assert_equals(response.status_int, 200)
        assert not response.body

        # Clean up.
        config.Registry.db_overrides = {}
开发者ID:ksh,项目名称:gpitraining,代码行数:36,代码来源:tests.py

示例8: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles REST GET verb and returns an object as JSON payload."""
        assert is_editable_fs(self.app_context)

        key = self.request.get("key")
        if not FilesRights.can_view(self):
            transforms.send_json_response(self, 401, "Access denied.", {"key": key})
            return

        # Load data if possible.
        fs = self.app_context.fs.impl
        filename = fs.physical_to_logical(key)
        try:
            stream = fs.get(filename)
        except:  # pylint: disable=bare-except
            stream = None
        if not stream:
            transforms.send_json_response(self, 404, "Object not found.", {"key": key})
            return

        # Prepare data.
        entity = {"key": key}
        if self.is_text_file(key):
            entity["encoding"] = self.FILE_ENCODING_TEXT
            entity["content"] = vfs.stream_to_string(stream)
        else:
            entity["encoding"] = self.FILE_ENCODING_BINARY
            entity["content"] = base64.b64encode(stream.read())

        # Render JSON response.
        json_payload = transforms.dict_to_json(entity, FilesItemRESTHandler.SCHEMA_DICT)
        transforms.send_json_response(
            self, 200, "Success.", payload_dict=json_payload, xsrf_token=XsrfTokenManager.create_xsrf_token("file-put")
        )
开发者ID:henrymp,项目名称:coursebuilder,代码行数:36,代码来源:filer.py

示例9: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles REST GET verb and returns an object as JSON payload."""
        key = self.request.get('key')

        try:
            entity = AnnouncementEntity.get(key)
        except db.BadKeyError:
            entity = None

        if not entity:
            transforms.send_json_response(
                self, 404, 'Object not found.', {'key': key})
            return

        viewable = AnnouncementsRights.apply_rights(self, [entity])
        if not viewable:
            transforms.send_json_response(
                self, 401, 'Access denied.', {'key': key})
            return
        entity = viewable[0]

        json_payload = transforms.dict_to_json(transforms.entity_to_dict(
            entity), AnnouncementsItemRESTHandler.SCHEMA_DICT)
        transforms.send_json_response(
            self, 200, 'Success.',
            payload_dict=json_payload,
            xsrf_token=XsrfTokenManager.create_xsrf_token(
                'announcement-put'))
开发者ID:cglmoocs,项目名称:cgl-mooc-builder,代码行数:30,代码来源:announcements.py

示例10: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles REST GET verb and returns an object as JSON payload."""

        if not CourseOutlineRights.can_view(self):
            transforms.send_json_response(self, 401, 'Access denied.', {})
            return

        course = courses.Course(self)
        outline_data = []
        for unit in course.get_units():
            lesson_data = []
            for lesson in course.get_lessons(unit.unit_id):
                lesson_data.append({
                    'title': lesson.title,
                    'id': lesson.lesson_id})
            unit_title = unit.title
            if verify.UNIT_TYPE_UNIT == unit.type:
                unit_title = 'Unit %s - %s' % (unit.index, unit.title)
            outline_data.append({
                'title': unit_title,
                'id': unit.unit_id,
                'lessons': lesson_data})

        transforms.send_json_response(
            self, 200, None,
            payload_dict={'outline': outline_data},
            xsrf_token=XsrfTokenManager.create_xsrf_token(
                'unit-lesson-reorder'))
开发者ID:graemian,项目名称:ami-mooc-pilot,代码行数:30,代码来源:unit_lesson_editor.py

示例11: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles REST GET verb and returns an object as JSON payload."""
        key = self.request.get('key')
        if not ConfigPropertyRights.can_view():
            transforms.send_json_response(
                self, 401, 'Access denied.', {'key': key})
            return

        item = None
        if key and key in config.Registry.registered.keys():
            item = config.Registry.registered[key]
        if not item:
            self.redirect('/admin?action=settings')

        try:
            entity = config.ConfigPropertyEntity.get_by_key_name(key)
        except db.BadKeyError:
            entity = None

        if not entity:
            transforms.send_json_response(
                self, 404, 'Object not found.', {'key': key})
        else:
            entity_dict = {'name': key, 'is_draft': entity.is_draft}
            entity_dict['value'] = transforms.string_to_value(
                entity.value, item.value_type)
            json_payload = transforms.dict_to_json(
                entity_dict,
                transforms.loads(
                    ConfigPropertyEditor.get_schema_json(item)))
            transforms.send_json_response(
                self, 200, 'Success.',
                payload_dict=json_payload,
                xsrf_token=XsrfTokenManager.create_xsrf_token(
                    'config-property-put'))
开发者ID:CSCI1200Course,项目名称:csci1200OnlineCourse,代码行数:37,代码来源:config.py

示例12: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Respond to the REST GET verb with the contents of the group."""
        key = self.request.get('key')

        if not CourseOutlineRights.can_view(self):
            transforms.send_json_response(
                self, 401, 'Access denied.', {'key': key})
            return

        if key:
            question_group = QuestionGroupDAO.load(key)
            version = question_group.dict.get('version')
            if self.SCHEMA_VERSION != version:
                transforms.send_json_response(
                    self, 403, 'Cannot edit a Version %s group.' % version,
                    {'key': key})
                return
            payload_dict = question_group.dict
        else:
            payload_dict = {
                'version': self.SCHEMA_VERSION,
                'items': [{'weight': ''}, {'weight': ''}, {'weight': ''}]}

        transforms.send_json_response(
            self, 200, 'Success',
            payload_dict=payload_dict,
            xsrf_token=XsrfTokenManager.create_xsrf_token(self.XSRF_TOKEN))
开发者ID:Domofera,项目名称:Domofera_MOOC,代码行数:29,代码来源:question_group_editor.py

示例13: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def get(self):
        """Handles GET requests."""
        if not course_explorer.GCB_ENABLE_COURSE_EXPLORER_PAGE.value:
            self.error(404)
            return

        user = self.initialize_page_and_get_user()
        if not user:
            self.redirect('/explorer')
            return

        courses = self.get_public_courses()
        self.template_values['student'] = (
            StudentProfileDAO.get_profile_by_user_id(user.user_id()))
        self.template_values['navbar'] = {'profile': True}
        self.template_values['courses'] = self.get_enrolled_courses(courses)
        self.template_values['student_edit_xsrf_token'] = (
            XsrfTokenManager.create_xsrf_token(
                STUDENT_RENAME_GLOBAL_XSRF_TOKEN_ID))
        self.template_values['html_hooks'] = NullHtmlHooks()
        self.template_values['student_preferences'] = {}

        template = jinja_utils.get_template(
            '/modules/course_explorer/views/profile.html', DIR)
        self.response.write(template.render(self.template_values))
开发者ID:CSCI1200Course,项目名称:csci1200OnlineCourse,代码行数:27,代码来源:student.py

示例14: get

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
 def get(self):
     if not users.is_current_user_admin():
         self.abort(403)
     form = self.Form()
     self.template_value['form'] = form
     self.template_value['xsrf_token'] = XsrfTokenManager.create_xsrf_token('post')
     self.template_value['action_url'] = self.request.url
     self.template_value['title'] = 'Reconsider a single participant'
     self.render('badge_bulk_issue.html')
开发者ID:twiffy,项目名称:eabooc,代码行数:11,代码来源:report_handlers.py

示例15: test_non_admin_has_no_access

# 需要导入模块: from controllers.utils import XsrfTokenManager [as 别名]
# 或者: from controllers.utils.XsrfTokenManager import create_xsrf_token [as 别名]
    def test_non_admin_has_no_access(self):
        """Test non admin has no access to pages or REST endpoints."""

        email = '[email protected]'
        actions.login(email)

        # Add datastore override.
        prop = config.ConfigPropertyEntity(
            key_name='gcb_config_update_interval_sec')
        prop.value = '5'
        prop.is_draft = False
        prop.put()

        # Check user has no access to specific pages and actions.
        response = self.testapp.get('/admin?action=settings')
        assert_equals(response.status_int, 302)

        response = self.testapp.get(
            '/admin?action=config_edit&name=gcb_admin_user_emails')
        assert_equals(response.status_int, 302)

        response = self.testapp.post(
            '/admin?action=config_reset&name=gcb_admin_user_emails')
        assert_equals(response.status_int, 302)

        # Check user has no rights to GET verb.
        response = self.testapp.get(
            '/rest/config/item?key=gcb_config_update_interval_sec')
        assert_equals(response.status_int, 200)
        json_dict = json.loads(response.body)
        assert json_dict['status'] == 401
        assert json_dict['message'] == 'Access denied.'

        # Check user has no rights to PUT verb.
        payload_dict = {}
        payload_dict['value'] = '666'
        payload_dict['is_draft'] = False
        request = {}
        request['key'] = 'gcb_config_update_interval_sec'
        request['payload'] = json.dumps(payload_dict)

        # Check XSRF token is required.
        response = self.testapp.put('/rest/config/item?%s' % urllib.urlencode(
            {'request': json.dumps(request)}), {})
        assert_equals(response.status_int, 200)
        assert_contains('"status": 403', response.body)

        # Check user still has no rights to PUT verb even if he somehow
        # obtained a valid XSRF token.
        request['xsrf_token'] = XsrfTokenManager.create_xsrf_token(
            'config-property-put')
        response = self.testapp.put('/rest/config/item?%s' % urllib.urlencode(
            {'request': json.dumps(request)}), {})
        assert_equals(response.status_int, 200)
        json_dict = json.loads(response.body)
        assert json_dict['status'] == 401
        assert json_dict['message'] == 'Access denied.'
开发者ID:ksh,项目名称:gpitraining,代码行数:59,代码来源:tests.py


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