public function test_check_secret_validity() { global $DB; $this->resetAfterTest(true); $hub = new local_hub(); $token = 'this is my token'; $md5 = md5($token); $this->assertTrue($hub->check_secret_validity($md5)); // Mark it stolen. $stolensecret = new stdClass(); $stolensecret->secret = $md5; $stolensecret->siteurl = 'http://example.com'; $stolensecret->blockeddate = time(); $DB->insert_record('hub_stolen_site_secrets', $stolensecret); $this->assertFalse($hub->check_secret_validity($md5)); }
// Retrieve the current url of MOOCH. // We do that because we switched to moodle.net from hub.moodle.org and we need both url to be registrable. if ($_SERVER['HTTP_HOST'] == 'hub.moodle.org') { $huburl = 'http://hub.moodle.org'; } else { $huburl = $CFG->wwwroot; } define('HUBURL', $huburl); //hack to support Xlanguage MDL-30281 - Moodle regression explains in MDL-30297 if (empty($language)) { $language = optional_param('Xlanguage', '', PARAM_ALPHANUMEXT); } $sitevalues = array('name' => $name, 'url' => $url, 'token' => $token, 'description' => $description, 'contactname' => $contactname, 'contactemail' => $contactemail, 'contactphone' => $contactphone, 'imageurl' => $imageurl, 'privacy' => $privacy, 'language' => $language, 'users' => $users, 'courses' => $courses, 'street' => $street, 'regioncode' => $regioncode, 'countrycode' => $countrycode, 'geolocation' => $geolocation, 'contactable' => $contactable, 'emailalert' => $emailalert, 'enrolments' => $enrolments, 'posts' => $posts, 'questions' => $questions, 'resources' => $resources, 'participantnumberaverage' => $participantnumberaverage, 'modulenumberaverage' => $modulenumberaverage, 'moodleversion' => $moodleversion, 'moodlerelease' => $moodlerelease, 'password' => $password, 'badges' => $badges, 'issuedbadges' => $issuedbadges); $hub = new local_hub(); //check the secret is not stolen if (!$hub->check_secret_validity(md5($token))) { echo $OUTPUT->header(); $renderer = $PAGE->get_renderer('local_hub'); echo $renderer->secretisstolen($sitevalues); echo $OUTPUT->footer(); exit; } //fresh moodle install on same url / Moved Moodle install on a url where a Moodle site was previously registered //the user comes to this page from an email link with a special token valid one time. $freshmoodletoken = optional_param('freshmoodletoken', '', PARAM_ALPHANUMEXT); $freshmoodleid = optional_param('id', 0, PARAM_INT); $freshmoodletokenconf = optional_param('freshmoodletokenconf', 0, PARAM_INT); if (!empty($freshmoodletoken) and !empty($freshmoodleid)) { $freshregistration = get_config('local_hub_unregistration', $freshmoodleid); if (!empty($freshregistration)) { $freshregistration = unserialize($freshregistration);