コード例 #1
0
ファイル: api.js プロジェクト: johncrossman/collabosphere
    provider.valid_request(req, function(err, isValid) {
      if (err) {
        if (err.message === 'Invalid Signature') {
          return callback({'code': 401, 'msg': 'Invalid Signature'});
        }

        log.error({'err': err}, 'An LTI launch resulted in an error');
        return callback({'code': 400, 'msg': err.message});
      } else if (!isValid) {
        log.warn('An LTI launch was invalid');
        return callback({'code': 400, 'msg': 'Failed validation'});
      }

      // Create the course on the fly
      var courseInfo = {
        'name': req.body.context_title
      };
      if (toolId === 'assetlibrary') {
        courseInfo.assetlibrary_url = req.headers.referer;
      } else if (toolId === 'dashboard') {
        courseInfo.dashboard_url = req.headers.referer;
      } else if (toolId === 'engagementindex') {
        courseInfo.engagementindex_url = req.headers.referer;
      } else if (toolId === 'whiteboards') {
        courseInfo.whiteboards_url = req.headers.referer;
      }
      CourseAPI.getOrCreateCourse(canvas_course_id, canvas, courseInfo, function(err, course) {
        if (err) {
          return callback(err);
        }

        // If the LTI launch did not provide a recognized Canvas enrollment state, mark the user inactive to
        // keep them from surfacing as a course site member.
        if (!_.includes(_.values(CollabosphereConstants.ENROLLMENT_STATE), canvas_enrollment_state)) {
          canvas_enrollment_state = 'inactive';
        }

        // Site admins are likewise considered inactive.
        if (_.includes(CollabosphereConstants.ADMIN_ROLES, canvas_course_role)) {
          canvas_enrollment_state = 'inactive';
        }

        // Create the user on the fly
        var defaults = {
          'canvas_course_role': canvas_course_role,
          'canvas_full_name': canvas_full_name,
          'canvas_image': canvas_image,
          'canvas_email': canvas_email,
          'canvas_enrollment_state': canvas_enrollment_state
        };
        UsersAPI.getOrCreateUser(canvas_user_id, course, defaults, function(err, user) {
          if (err) {
            return callback(err);
          }

          // Store or update the user's analytics properties
          AnalyticsAPI.identifyUser(user);

          // Keep track of the URL that is performing the LTI launch
          provider.body.tool_url = req.headers.referer;

          // Keep track of whether this Canvas instance supports custom cross-window messaging
          provider.body.supports_custom_messaging = canvas.supports_custom_messaging;

          return callback(null, provider.body, user);
        });
      });
    });
コード例 #2
0
ファイル: api.js プロジェクト: paulkerschen/collabosphere
    provider.valid_request(req, function(err, isValid) {
      if (err) {
        if (err.message === 'Invalid Signature') {
          return callback({'code': 401, 'msg': 'Invalid Signature'});
        }

        log.error({'err': err}, 'An LTI launch resulted in an error');
        return callback({'code': 400, 'msg': err.message});
      } else if (!isValid) {
        log.warn('An LTI launch was invalid');
        return callback({'code': 400, 'msg': 'Failed validation'});
      }

      // Create the course on the fly
      var courseInfo = {
        'name': req.body.context_title
      };
      if (toolId === 'assetlibrary') {
        courseInfo.assetlibrary_url = req.headers.referer;
      } else if (toolId === 'dashboard') {
        courseInfo.dashboard_url = req.headers.referer;
      } else if (toolId === 'engagementindex') {
        courseInfo.engagementindex_url = req.headers.referer;
      } else if (toolId === 'whiteboards') {
        courseInfo.whiteboards_url = req.headers.referer;
      }
      CourseAPI.getOrCreateCourse(canvas_course_id, canvas, courseInfo, function(err, course) {
        if (err) {
          return callback(err);
        }

        // By default, everyone who launches in an LTI tool is considered to be active
        var canvas_enrollment_state = 'active';

        // However, when a site admin launches the tool, we set their enrollment_state to
        // `inactive` as they shouldn't really appear in the engagement index
        if (_.includes(CollabosphereConstants.ADMIN_ROLES, canvas_course_role)) {
          canvas_enrollment_state = 'inactive';
        }

        // Create the user on the fly
        var defaults = {
          'canvas_course_role': canvas_course_role,
          'canvas_full_name': canvas_full_name,
          'canvas_image': canvas_image,
          'canvas_email': canvas_email,
          'canvas_enrollment_state': canvas_enrollment_state
        };
        UsersAPI.getOrCreateUser(canvas_user_id, course, defaults, function(err, user) {
          if (err) {
            return callback(err);
          }

          // Store or update the user's analytics properties
          AnalyticsAPI.identify(user);

          // Keep track of the URL that is performing the LTI launch
          provider.body.tool_url = req.headers.referer;

          // Keep track of whether this Canvas instance supports custom cross-window messaging
          provider.body.supports_custom_messaging = canvas.supports_custom_messaging;

          return callback(null, provider.body, user);
        });
      });
    });