Пример #1
0
    def dispatch(self, request, *args, **kwargs):
        lti = LTI(self.request_type, self.role_type)

        # validate the user via oauth
        user = authenticate(request=request, lti=lti)
        if user is None:
            lti.clear_session(request)
            return render(request, 'lti_auth/fail_auth.html', {})

        # login
        login(request, user)

        # check if course is configured
        try:
            ctx = LTICourseContext.objects.get(
                lms_course_context=lti.course_context())
        except (KeyError, ValueError, LTICourseContext.DoesNotExist):
            return render(
                request, 'lti_auth/fail_course_configuration.html', {
                    'is_instructor': lti.is_instructor(),
                    'is_administrator': lti.is_administrator(),
                    'user': user,
                    'lms_course': lti.course_context(),
                    'lms_course_title': lti.course_title(),
                    'sis_course_id': lti.sis_course_id(),
                    'domain': lti.canvas_domain()
                })

        # add user to the course
        self.join_groups(lti, ctx, user)
        self.lti = lti
        return super(LTIAuthMixin, self).dispatch(request, *args, **kwargs)
Пример #2
0
    def dispatch(self, request, *args, **kwargs):
        lti = LTI(self.request_type, self.role_type)

        # validate the user via oauth
        user = authenticate(request=request, lti=lti)
        if user is None:
            lti.clear_session(request)
            return render(request, 'lti_auth/fail_auth.html', {})

        # login
        login(request, user)

        # check if course is configured
        try:
            ctx = LTICourseContext.objects.get(
                lms_course_context=lti.course_context())
        except (KeyError, ValueError, LTICourseContext.DoesNotExist):
            return render(
                request,
                'lti_auth/fail_course_configuration.html',
                {
                    'is_instructor': lti.is_instructor(),
                    'is_administrator': lti.is_administrator(),
                    'user': user,
                    'lms_course': lti.course_context(),
                    'lms_course_title': lti.course_title(),
                    'sis_course_id': lti.sis_course_id(),
                    'domain': lti.canvas_domain()
                })

        # add user to the course
        self.join_groups(lti, ctx, user)
        self.lti = lti
        return super(LTIAuthMixin, self).dispatch(request, *args, **kwargs)
Пример #3
0
    def test_user_roles(self):
        lti = LTI('initial', 'any')
        self.assertEquals(lti.user_roles(), [])

        lti.lti_params = BASE_LTI_PARAMS
        self.assertEquals(lti.user_roles(), [
            u'urn:lti:instrole:ims/lis/instructor',
            u'urn:lti:instrole:ims/lis/staff'])

        self.assertTrue(lti.is_instructor())
        self.assertFalse(lti.is_administrator())
Пример #4
0
    def test_user_roles(self):
        lti = LTI('initial', 'any')
        self.assertEquals(lti.user_roles(), [])

        lti.lti_params = BASE_LTI_PARAMS
        self.assertEquals(lti.user_roles(), [
            u'urn:lti:instrole:ims/lis/instructor',
            u'urn:lti:instrole:ims/lis/staff'
        ])

        self.assertTrue(lti.is_instructor())
        self.assertFalse(lti.is_administrator())