public function test_create_hub_token() { $this->resetAfterTest(true); $hub = new local_hub(); $url = 'http://example.com'; // These capabilities and the arguments to create_hub_token() are modeled // on the call in register_site() in lib.php. $capabilities = array('local/hub:updateinfo', 'local/hub:registercourse', 'local/hub:view', 'local/hub:unregistercourse', 'local/hub:viewsmallinfo'); $tokenusedbysite = $hub->create_hub_token('Registered Hub User', 'Registered site', $url . '_registered_site_user', $capabilities); // If it already exists, the existing token should be found. $foundtoken = $hub->create_hub_token('Registered Hub User', 'Registered site', $url . '_registered_site_user', $capabilities); $this->assertEquals($foundtoken->id, $tokenusedbysite->id); }
/** * 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(); }
} } /////// FORM REGISTRATION ACTION ////// // retrieve the privacy setting $privacy = get_config('local_hub', 'privacy'); $fromform = $hubregistrationform->get_data(); if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked //we are using the form input as the redirection parameters //(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) {