// Before we do anything check that the context is valid. $context = context::instance_by_id($tool->contextid); // Set the user data. $user = new stdClass(); $user->username = \enrol_lti\helper::create_username($ltirequest->info['oauth_consumer_key'], $ltirequest->info['user_id']); if (!empty($ltirequest->info['lis_person_name_given'])) { $user->firstname = $ltirequest->info['lis_person_name_given']; } else { $user->firstname = $ltirequest->info['user_id']; } if (!empty($ltirequest->info['lis_person_name_family'])) { $user->lastname = $ltirequest->info['lis_person_name_family']; } else { $user->lastname = $ltirequest->info['context_id']; } $user->email = \core_user::clean_field($ltirequest->getUserEmail(), 'email'); // Get the user data from the LTI consumer. $user = \enrol_lti\helper::assign_user_tool_data($tool, $user); // Check if the user exists. if (!($dbuser = $DB->get_record('user', array('username' => $user->username, 'deleted' => 0)))) { // If the email was stripped/not set then fill it with a default one. This // stops the user from being redirected to edit their profile page. if (empty($user->email)) { $user->email = $user->username . "@example.com"; } $user->auth = 'lti'; $user->id = user_create_user($user); // Get the updated user record. $user = $DB->get_record('user', array('id' => $user->id)); } else { if (\enrol_lti\helper::user_match($user, $dbuser)) {
* @ingroup Extensions * @version 0.1 * @author Charles Severance based on for from Antoni Bertran and Jose Diago */ $going2MW = false; // BLTI integration require_once 'IMSBasicLTI/ims-blti/blti.php'; if (!is_basic_lti_request()) { return; } //Let's get the user's data $context = new BLTI("secret", false, false); if ($context->valid) { $agentCourse = $context->getCourseName(); $agentUserName = $context->getUserShortName(); $agentEmail = $context->getUserEmail(); $agentFullName = $context->getUserName(); $going2MW = true; session_start(); $_SESSION['BLTIclassroom'] = $agentCourse; } else { echo 'Error validating: ' . $context->message; } $context = null; if ($going2MW) { $myURI = $_SERVER['REQUEST_URI']; $newURI = str_replace("extensions/Redirect2CourseBLTI.php", "index.php", $myURI); $newParameters = "title=Category:{$agentCourse}&BLTIusername={$agentUserName}&BLTIemail={$agentEmail}&BLTIfullname={$agentFullName}&BLTI=yes"; $newURI = $newURI . "?" . $newParameters; header("Location: {$newURI}"); }