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();
//check that the token/url couple exist and is not confirmed
$registeredhub = $hub->get_registeredhub($url);
if (!empty($registeredhub) and $registeredhub->confirmed == 0
and $registeredhub->token == $token) {
$registeredhub = $hub->get_unconfirmedhub($url);
if (!empty($registeredhub) and $registeredhub->token == $token) {
$registeredhub->token = $newtoken;
$registeredhub->confirmed = 1;
@ -58,7 +57,7 @@ if (!empty($registeredhub) and $registeredhub->confirmed == 0
echo $OUTPUT->notification(get_string('registrationconfirmed', 'hub'), 'notifysuccess');
echo $OUTPUT->footer();
} 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;
$huburl = $this->_customdata['huburl'];
$hubname = $this->_customdata['hubname'];
$password = $this->_customdata['password'];
$admin = get_admin();
$site = get_site();
@ -166,6 +167,7 @@ class site_registration_form extends moodleform {
//hidden parameters
$mform->addElement('hidden', 'huburl', $huburl);
$mform->addElement('hidden', 'hubname', $hubname);
$mform->addElement('hidden', 'password', $password);
//the input parameters
$mform->addElement('header', 'moodle', get_string('registrationinfo', 'hub'));

View file

@ -42,6 +42,7 @@ admin_externalpage_setup('registration');
$huburl = optional_param('huburl', '', PARAM_URL);
$password = optional_param('password', '', PARAM_TEXT);
$hubname = optional_param('hubname', '', PARAM_TEXT);
if (empty($huburl) or !confirm_sesskey()) {
throw new moodle_exception('cannotaccessthispage');
@ -68,7 +69,8 @@ $registeredhub = $hub->get_registeredhub($huburl);
$siteregistrationform = new site_registration_form('',
array('alreadyregistered' => !empty($registeredhub->token),
'huburl' => $huburl, 'hubname' => $hubname));
'huburl' => $huburl, 'hubname' => $hubname,
'password' => $password));
$fromform = $siteregistrationform->get_data();
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
$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
$registeredhub = new stdClass();
$registeredhub->token = md5(uniqid(rand(),1));
$registeredhub->huburl = $huburl;
$registeredhub->hubname = $hubname;
$registeredhub->confirmed = 0;
$registeredhub->id = $hub->add_registeredhub($registeredhub);
$unconfirmedhub = new stdClass();
$unconfirmedhub->token = md5(uniqid(rand(),1));
$unconfirmedhub->huburl = $huburl;
$unconfirmedhub->hubname = $hubname;
$unconfirmedhub->confirmed = 0;
$unconfirmedhub->id = $hub->add_registeredhub($unconfirmedhub);
}
$params['token'] = $registeredhub->token;
$params['token'] = $unconfirmedhub->token;
$params['url'] = $CFG->wwwroot;
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['url'] = 'hub URL';
$string['usersnumber'] = 'Number of users ({$a})';
$string['wrongtoken'] = 'The registration failed. Press continue and try again.';
$string['wrongurlformat'] = 'Bad URL format';

View file

@ -169,6 +169,17 @@ class hub {
if (!empty($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);
return $token;
}