Commit c73f1963 authored by jeromemoodle's avatar jeromemoodle Committed by Petr Skoda
Browse files

MDL-26179 implement the new 5 registration use cases

parent fb473042
...@@ -84,6 +84,33 @@ class registration_manager { ...@@ -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 * When the site register on a hub, he must call this function
* @param object $hub where the site is registered on * @param object $hub where the site is registered on
......
...@@ -49,21 +49,6 @@ if (!confirm_sesskey()) { ...@@ -49,21 +49,6 @@ if (!confirm_sesskey()) {
throw new moodle_exception('missingparameter'); 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(); $registrationmanager = new registration_manager();
$registeredhub = $registrationmanager->get_registeredhub($huburl); $registeredhub = $registrationmanager->get_registeredhub($huburl);
...@@ -132,7 +117,8 @@ if (!empty($fromform) and empty($update) and confirm_sesskey()) { ...@@ -132,7 +117,8 @@ if (!empty($fromform) and empty($update) and confirm_sesskey()) {
if (empty($unconfirmedhub)) { if (empty($unconfirmedhub)) {
//we save the token into the communication table in order to have a reference //we save the token into the communication table in order to have a reference
$unconfirmedhub = new stdClass(); $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->huburl = $huburl;
$unconfirmedhub->hubname = $hubname; $unconfirmedhub->hubname = $hubname;
$unconfirmedhub->confirmed = 0; $unconfirmedhub->confirmed = 0;
......
<?php
///////////////////////////////////////////////////////////////////////////
// //
// This file is part of Moodle - http://moodle.org/ //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// //
// Moodle is free software: you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation, either version 3 of the License, or //
// (at your option) any later version. //
// //
// Moodle is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. //
// //
///////////////////////////////////////////////////////////////////////////
/*
* @package moodle
* @subpackage registration
* @author Jerome Mouneyrac <jerome@mouneyrac.com>
* @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');
}
...@@ -142,6 +142,7 @@ $string['participantnumberaverage'] = 'Average number of participants ({$a})'; ...@@ -142,6 +142,7 @@ $string['participantnumberaverage'] = 'Average number of participants ({$a})';
$string['postaladdress'] = 'Postal address'; $string['postaladdress'] = 'Postal address';
$string['postaladdress_help'] = 'Postal address of this site, or of the entity represented by this site.'; $string['postaladdress_help'] = 'Postal address of this site, or of the entity represented by this site.';
$string['postsnumber'] = 'Number of posts ({$a})'; $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['prioritise'] = 'Prioritise';
$string['privacy'] = 'Privacy'; $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.'; $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 ...@@ -174,7 +175,9 @@ $string['registrationconfirmedon'] = 'You are now registered on the hub {$a}. Yo
$string['registrationupdated'] = 'Registration has been updated.'; $string['registrationupdated'] = 'Registration has been updated.';
$string['registrationupdatedfailed'] = 'Registration update failed.'; $string['registrationupdatedfailed'] = 'Registration update failed.';
$string['removefromhub'] = 'Remove from hub'; $string['removefromhub'] = 'Remove from hub';
$string['renewregistration'] = 'Renew registration';
$string['resourcesnumber'] = 'Number of resources ({$a})'; $string['resourcesnumber'] = 'Number of resources ({$a})';
$string['restartregistration'] = 'Restart registration';
$string['roleassignmentsnumber'] = 'Number of role assignments ({$a})'; $string['roleassignmentsnumber'] = 'Number of role assignments ({$a})';
$string['screenshots'] = 'Screenshots'; $string['screenshots'] = 'Screenshots';
$string['screenshots_help'] = 'Any screenshots of the course will be displayed in search results.'; $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 ...@@ -206,7 +209,7 @@ $string['sitedesc_help'] = 'This description of your site may be shown in the si
$string['sitegeolocation'] = 'Geolocation'; $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['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'] = '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'] = 'Language';
$string['sitelang_help'] = 'Your site language will be displayed on the site listing.'; $string['sitelang_help'] = 'Your site language will be displayed on the site listing.';
$string['sitename'] = 'Name'; $string['sitename'] = 'Name';
......
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="lib/db" VERSION="20110206" COMMENT="XMLDB file for core Moodle tables" <XMLDB PATH="lib/db" VERSION="20110209" COMMENT="XMLDB file for core Moodle tables"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd" xsi:noNamespaceSchemaLocation="../../lib/xmldb/xmldb.xsd"
> >
...@@ -2624,10 +2624,11 @@ ...@@ -2624,10 +2624,11 @@
<TABLE NAME="registration_hubs" COMMENT="hub where the site is registered on with their associated token" PREVIOUS="license" NEXT="backup_controllers"> <TABLE NAME="registration_hubs" COMMENT="hub where the site is registered on with their associated token" PREVIOUS="license" NEXT="backup_controllers">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="token"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="token"/>
<FIELD NAME="token" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="hubname"/> <FIELD NAME="token" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="the token to communicate with the hub by web service" PREVIOUS="id" NEXT="hubname"/>
<FIELD NAME="hubname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="token" NEXT="huburl"/> <FIELD NAME="hubname" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="token" NEXT="huburl"/>
<FIELD NAME="huburl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="hubname" NEXT="confirmed"/> <FIELD NAME="huburl" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" PREVIOUS="hubname" NEXT="confirmed"/>
<FIELD NAME="confirmed" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="huburl"/> <FIELD NAME="confirmed" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="huburl" NEXT="secret"/>
<FIELD NAME="secret" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="the unique site identifier for this hub" PREVIOUS="confirmed"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/> <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
......
...@@ -6028,6 +6028,21 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL"); ...@@ -6028,6 +6028,21 @@ WHERE gradeitemid IS NOT NULL AND grademax IS NOT NULL");
upgrade_main_savepoint(true, 2011020900.07); 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; return true;
} }
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die(); 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 // XX = daily increments
$release = '2.0.1+ (Build: 20110209)'; // Human-friendly version name $release = '2.0.1+ (Build: 20110209)'; // Human-friendly version name
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment