registration MDL-19313 implement password for private hub

This commit is contained in:
jerome mouneyrac 2010-05-06 06:41:25 +00:00
parent b2aea6c674
commit 4b1acb3ae8
5 changed files with 29 additions and 13 deletions

View file

@ -46,9 +46,8 @@ $token = optional_param('token', '', PARAM_ALPHANUM);
$hub = new hub(); $hub = new hub();
//check that the token/url couple exist and is not confirmed //check that the token/url couple exist and is not confirmed
$registeredhub = $hub->get_registeredhub($url); $registeredhub = $hub->get_unconfirmedhub($url);
if (!empty($registeredhub) and $registeredhub->confirmed == 0 if (!empty($registeredhub) and $registeredhub->token == $token) {
and $registeredhub->token == $token) {
$registeredhub->token = $newtoken; $registeredhub->token = $newtoken;
$registeredhub->confirmed = 1; $registeredhub->confirmed = 1;
@ -58,7 +57,7 @@ if (!empty($registeredhub) and $registeredhub->confirmed == 0
echo $OUTPUT->notification(get_string('registrationconfirmed', 'hub'), 'notifysuccess'); echo $OUTPUT->notification(get_string('registrationconfirmed', 'hub'), 'notifysuccess');
echo $OUTPUT->footer(); echo $OUTPUT->footer();
} else { } else {
throw new moodle_exception('wrongtoken'); throw new moodle_exception('wrongtoken', 'hub', $CFG->wwwroot.'/admin/registration/index.php');
} }

View file

@ -119,6 +119,7 @@ class site_registration_form extends moodleform {
$mform =& $this->_form; $mform =& $this->_form;
$huburl = $this->_customdata['huburl']; $huburl = $this->_customdata['huburl'];
$hubname = $this->_customdata['hubname']; $hubname = $this->_customdata['hubname'];
$password = $this->_customdata['password'];
$admin = get_admin(); $admin = get_admin();
$site = get_site(); $site = get_site();
@ -166,6 +167,7 @@ class site_registration_form extends moodleform {
//hidden parameters //hidden parameters
$mform->addElement('hidden', 'huburl', $huburl); $mform->addElement('hidden', 'huburl', $huburl);
$mform->addElement('hidden', 'hubname', $hubname); $mform->addElement('hidden', 'hubname', $hubname);
$mform->addElement('hidden', 'password', $password);
//the input parameters //the input parameters
$mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub')); $mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));

View file

@ -42,6 +42,7 @@ admin_externalpage_setup('registration');
$huburl = optional_param('huburl', '', PARAM_URL); $huburl = optional_param('huburl', '', PARAM_URL);
$password = optional_param('password', '', PARAM_TEXT);
$hubname = optional_param('hubname', '', PARAM_TEXT); $hubname = optional_param('hubname', '', PARAM_TEXT);
if (empty($huburl) or !confirm_sesskey()) { if (empty($huburl) or !confirm_sesskey()) {
throw new moodle_exception('cannotaccessthispage'); throw new moodle_exception('cannotaccessthispage');
@ -68,7 +69,8 @@ $registeredhub = $hub->get_registeredhub($huburl);
$siteregistrationform = new site_registration_form('', $siteregistrationform = new site_registration_form('',
array('alreadyregistered' => !empty($registeredhub->token), array('alreadyregistered' => !empty($registeredhub->token),
'huburl' => $huburl, 'hubname' => $hubname)); 'huburl' => $huburl, 'hubname' => $hubname,
'password' => $password));
$fromform = $siteregistrationform->get_data(); $fromform = $siteregistrationform->get_data();
if (!empty($fromform) and confirm_sesskey()) { if (!empty($fromform) and confirm_sesskey()) {
@ -125,17 +127,18 @@ if (!empty($fromform) and empty($update) and confirm_sesskey()) {
if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked if (!empty($fromform) and confirm_sesskey()) { // if the register button has been clicked
$params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name) $params = (array) $fromform; //we are using the form input as the redirection parameters (token, url and name)
if (empty($registeredhub)) { $unconfirmedhub = $hub->get_unconfirmedhub($huburl);
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
$registeredhub = new stdClass(); $unconfirmedhub = new stdClass();
$registeredhub->token = md5(uniqid(rand(),1)); $unconfirmedhub->token = md5(uniqid(rand(),1));
$registeredhub->huburl = $huburl; $unconfirmedhub->huburl = $huburl;
$registeredhub->hubname = $hubname; $unconfirmedhub->hubname = $hubname;
$registeredhub->confirmed = 0; $unconfirmedhub->confirmed = 0;
$registeredhub->id = $hub->add_registeredhub($registeredhub); $unconfirmedhub->id = $hub->add_registeredhub($unconfirmedhub);
} }
$params['token'] = $registeredhub->token; $params['token'] = $unconfirmedhub->token;
$params['url'] = $CFG->wwwroot; $params['url'] = $CFG->wwwroot;
redirect(new moodle_url(MOODLEORGHUBURL.'/local/hub/siteregistration.php', $params)); redirect(new moodle_url(MOODLEORGHUBURL.'/local/hub/siteregistration.php', $params));

View file

@ -175,5 +175,6 @@ $string['untrustme'] = 'Untrust';
$string['updatesite'] = 'Update registration on {$a}'; $string['updatesite'] = 'Update registration on {$a}';
$string['url'] = 'hub URL'; $string['url'] = 'hub URL';
$string['usersnumber'] = 'Number of users ({$a})'; $string['usersnumber'] = 'Number of users ({$a})';
$string['wrongtoken'] = 'The registration failed. Press continue and try again.';
$string['wrongurlformat'] = 'Bad URL format'; $string['wrongurlformat'] = 'Bad URL format';

View file

@ -169,6 +169,17 @@ class hub {
if (!empty($token)) { if (!empty($token)) {
$params['token'] = $token; $params['token'] = $token;
} }
$params['confirmed'] = 1;
$token = $DB->get_record('registration_hubs',$params);
return $token;
}
public function get_unconfirmedhub($huburl) {
global $DB;
$params = array();
$params['huburl'] = $huburl;
$params['confirmed'] = 0;
$token = $DB->get_record('registration_hubs',$params); $token = $DB->get_record('registration_hubs',$params);
return $token; return $token;
} }