diff --git a/admin/registration/lib.php b/admin/registration/lib.php index 8fc5dd261f8..4179d7908c6 100644 --- a/admin/registration/lib.php +++ b/admin/registration/lib.php @@ -84,6 +84,33 @@ class registration_manager { } } + /** + * Return the site secret for a given hub + * site identifier is assigned to Mooch + * each hub has a unique and personal site secret. + * @param string $huburl + * @return string site secret + */ + public function get_site_secret_for_hub($huburl) { + global $DB; + + $existingregistration = $DB->get_record('registration_hubs', + array('huburl' => $huburl)); + + if (!empty($existingregistration)) { + return $existingregistration->secret; + } + + if ($huburl == HUB_MOODLEORGHUBURL) { + $siteidentifier = get_site_identifier(); + } else { + $siteidentifier = random_string(32) . $_SERVER['HTTP_HOST']; + } + + return $siteidentifier; + + } + /** * When the site register on a hub, he must call this function * @param object $hub where the site is registered on diff --git a/admin/registration/register.php b/admin/registration/register.php index 0454bc36317..eac6400cb53 100644 --- a/admin/registration/register.php +++ b/admin/registration/register.php @@ -49,21 +49,6 @@ if (!confirm_sesskey()) { throw new moodle_exception('missingparameter'); } -/* TO DO - if DB config plugin table is not good for dealing with token reference and token confirmation - => create other DB table - ----------------------------------------------------------------------------- - Local Type | Token | Local WS | Remote Type | Remote URL | Confirmed - ----------------------------------------------------------------------------- - HUB 4er4e server HUB-DIRECTORY http...moodle.org Yes - HUB 73j53 client HUB-DIRECTORY http...moodle.org Yes - SITE dfsd7 server HUB http...hub Yes - SITE fd8fd client HUB http...hub Yes - HUB ds78s server SITE http...site.com Yes - HUB-DIR. d7d8s server HUB http...hub Yes - ----------------------------------------------------------------------------- - */ - $registrationmanager = new registration_manager(); $registeredhub = $registrationmanager->get_registeredhub($huburl); @@ -132,7 +117,8 @@ if (!empty($fromform) and empty($update) and confirm_sesskey()) { if (empty($unconfirmedhub)) { //we save the token into the communication table in order to have a reference $unconfirmedhub = new stdClass(); - $unconfirmedhub->token = get_site_identifier(); + $unconfirmedhub->token = $registrationmanager->get_site_secret_for_hub($huburl); + $unconfirmedhub->secret = $unconfirmedhub->token; $unconfirmedhub->huburl = $huburl; $unconfirmedhub->hubname = $hubname; $unconfirmedhub->confirmed = 0; diff --git a/admin/registration/renewregistration.php b/admin/registration/renewregistration.php new file mode 100644 index 00000000000..ec9fce278c3 --- /dev/null +++ b/admin/registration/renewregistration.php @@ -0,0 +1,76 @@ +. // +// // +/////////////////////////////////////////////////////////////////////////// + +/* + * @package moodle + * @subpackage registration + * @author Jerome Mouneyrac + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL + * @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com + * + * The administrator is redirect to this page from the hub to renew a registration + * process because + */ + +require('../../config.php'); +require_once($CFG->libdir . '/adminlib.php'); +require_once($CFG->dirroot . '/' . $CFG->admin . '/registration/lib.php'); + +$url = optional_param('url', '', PARAM_URL); +$hubname = optional_param('hubname', '', PARAM_TEXT); +$token = optional_param('token', '', PARAM_TEXT); + +admin_externalpage_setup('registrationindex'); + +//check that we are waiting a confirmation from this hub, and check that the token is correct +$registrationmanager = new registration_manager(); +$registeredhub = $registrationmanager->get_unconfirmedhub($url); +if (!empty($registeredhub) and $registeredhub->token == $token) { + + echo $OUTPUT->header(); + echo $OUTPUT->heading(get_string('renewregistration', 'hub'), 3, 'main'); + $hublink = html_writer::tag('a', $hubname, array('href' => $url)); + + $registrationmanager->delete_registeredhub($url); + + //Mooch case, need to recreate the siteidentifier + if ($url == HUB_MOODLEORGHUBURL) { + $CFG->siteidentifier = null; + get_site_identifier(); + } + + $deletedregmsg = get_string('previousregistrationdeleted', 'hub', $hublink); + + $button = new single_button(new moodle_url('/admin/registration/index.php'), + get_string('restartregistration', 'hub')); + $button->class = 'restartregbutton'; + + echo html_writer::tag('div', $deletedregmsg . $OUTPUT->render($button), + array('class' => 'mdl-align')); + + echo $OUTPUT->footer(); +} else { + throw new moodle_exception('wrongtoken', 'hub', + $CFG->wwwroot . '/' . $CFG->admin . '/registration/index.php'); +} + + diff --git a/lang/en/hub.php b/lang/en/hub.php index 016a815826a..42abfad2616 100644 --- a/lang/en/hub.php +++ b/lang/en/hub.php @@ -142,6 +142,7 @@ $string['participantnumberaverage'] = 'Average number of participants ({$a})'; $string['postaladdress'] = 'Postal address'; $string['postaladdress_help'] = 'Postal address of this site, or of the entity represented by this site.'; $string['postsnumber'] = 'Number of posts ({$a})'; +$string['previousregistrationdeleted'] = 'The previous registration has been deleted from {$a}. You can restart the registration process. Thank you.'; $string['prioritise'] = 'Prioritise'; $string['privacy'] = 'Privacy'; $string['privacy_help'] = 'The hub may want to display a list of registered sites. If it does then you can choose whether or not you want to appear on that list.'; @@ -174,7 +175,9 @@ $string['registrationconfirmedon'] = 'You are now registered on the hub {$a}. Yo $string['registrationupdated'] = 'Registration has been updated.'; $string['registrationupdatedfailed'] = 'Registration update failed.'; $string['removefromhub'] = 'Remove from hub'; +$string['renewregistration'] = 'Renew registration'; $string['resourcesnumber'] = 'Number of resources ({$a})'; +$string['restartregistration'] = 'Restart registration'; $string['roleassignmentsnumber'] = 'Number of role assignments ({$a})'; $string['screenshots'] = 'Screenshots'; $string['screenshots_help'] = 'Any screenshots of the course will be displayed in search results.'; @@ -206,7 +209,7 @@ $string['sitedesc_help'] = 'This description of your site may be shown in the si $string['sitegeolocation'] = 'Geolocation'; $string['sitegeolocation_help'] = 'In future we may provide location-based searching in the hubs. If you want to specify the location for your site use a latitude/longitude value here (eg: -31.947884,115.871285). One way to find this is to use Google Maps.'; $string['siteemail'] = 'Email address'; -$string['siteemail_help'] = 'You need to provide an email address so the admin can contact you if necessary. This will not be used for any other purpose.'; +$string['siteemail_help'] = 'You need to provide an email address so the hub administrator can contact you if necessary. This will not be used for any other purpose. It is recommended to enter a email address related to a position (example: sitemanager@example.com) and not directly to a person.'; $string['sitelang'] = 'Language'; $string['sitelang_help'] = 'Your site language will be displayed on the site listing.'; $string['sitename'] = 'Name'; diff --git a/lib/db/install.xml b/lib/db/install.xml index e7676bb3384..27b3c1e5b19 100644 --- a/lib/db/install.xml +++ b/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -2624,10 +2624,11 @@ - + - + + diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 3bd79d8cae5..4fe7651c05c 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -6028,6 +6028,21 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); upgrade_main_savepoint(true, 2011020900.07); } + if ($oldversion < 2011020900.08) { + // Define field secret to be added to registration_hubs + $table = new xmldb_table('registration_hubs'); + $field = new xmldb_field('secret', XMLDB_TYPE_CHAR, '255', null, null, null, + $CFG->siteidentifier, 'confirmed'); + + // Conditionally launch add field secret + if (!$dbman->field_exists($table, $field)) { + $dbman->add_field($table, $field); + } + + // Main savepoint reached + upgrade_main_savepoint(true, 2011020900.08); + } + return true; } diff --git a/version.php b/version.php index ab374d995c7..508da1bf7b9 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2011020900.07; // YYYYMMDD = date of the last version bump +$version = 2011020900.08; // YYYYMMDD = date of the last version bump // XX = daily increments $release = '2.0.1+ (Build: 20110209)'; // Human-friendly version name