/** * Authenticate user from the received hub token * If no token, so we use the "public" hub community token from the system (create one if don't exist) */ protected function authenticate_user() { global $DB; //retrieve hub privacy $privacy = get_config('local_hub', 'privacy'); // hub server public access (search, rate, comment, import) if ($this->token == 'publichub' and $privacy != HUBPRIVATE) { $hub = new local_hub(); $publiccommunication = $hub->get_communication(WSSERVER, PUBLICSITE); if (empty($publiccommunication)) { $capabilities = array('local/hub:view'); $token = $hub->create_hub_token('Public Hub User', 'Public site', 'public_hub_user', $capabilities); $publiccommunication = new stdClass(); $publiccommunication->token = $token->token; $publiccommunication->type = WSSERVER; $publiccommunication->remotename = ''; $publiccommunication->remoteentity = PUBLICSITE; $publiccommunication->confirmed = 1; $publiccommunication->id = $hub->add_communication($publiccommunication); } $this->token = $publiccommunication->token; } parent::authenticate_user(); }
//(token, url and name) $params = (array) $fromform; //first time we press the registration button (and only time if no failure) if (empty($directorytohubcommunication)) { //create new token for the hub directory to call the hub $capabilities = array('local/hub:viewinfo'); $token = $hub->create_hub_token('Moodle.org Hub Directory', 'Hub directory', HUB_HUBDIRECTORYURL . '_directory_user', $capabilities); //we save the token into the communication table in order to have a reference to the hidden token $directorytohubcommunication = new stdClass(); $directorytohubcommunication->token = $token->token; $directorytohubcommunication->type = WSSERVER; $directorytohubcommunication->remotename = 'Moodle.org hub directory'; $directorytohubcommunication->remoteentity = HUBDIRECTORY; $directorytohubcommunication->remoteurl = HUB_HUBDIRECTORYURL; $directorytohubcommunication->confirmed = 0; $directorytohubcommunication->id = $hub->add_communication($directorytohubcommunication); $params['token'] = $token->token; } else { $params['token'] = $directorytohubcommunication->token; } //if the hub is private do not redirect to moodle.org if ($privacy != HUBPRIVATE) { redirect(new moodle_url(HUB_HUBDIRECTORYURL . '/local/hubdirectory/hubregistration.php', $params)); } } /////// OUTPUT SECTION ///////////// echo $OUTPUT->header(); $renderer = $PAGE->get_renderer('local_hub'); //unregister confirmation page if ($unregister && empty($confirm)) { echo $renderer->unregistration_confirmation($force);
public function test_add_communication() { global $DB; $this->resetAfterTest(true); $hub = new local_hub(); $sitetohubcommunication = new stdClass(); $sitetohubcommunication->token = '123456'; $sitetohubcommunication->type = WSSERVER; $sitetohubcommunication->remoteentity = REGISTEREDSITE; $sitetohubcommunication->remotename = 'test site'; $sitetohubcommunication->remoteurl = 'http://example.com'; $sitetohubcommunication->confirmed = 1; $sitetohubcommunication->id = $hub->add_communication($sitetohubcommunication); $this->assertTrue($sitetohubcommunication->id > 0); // Deleting a communication just toggles a deleted flage. // Adding another communication with the same details // should result in the ID of the new and old communication matching. $originalID = $sitetohubcommunication->id; $hub->delete_communication($sitetohubcommunication); $newID = $hub->add_communication($sitetohubcommunication); $this->assertTrue($originalID == $newID); }