MDL-42173 administration: Fix alternate name warnings during registration

This commit is contained in:
Ankit Agarwal 2013-10-07 11:16:24 +08:00
parent 83a3e35e56
commit 0859a08d37
2 changed files with 16 additions and 15 deletions

View File

@ -25,6 +25,7 @@
*/
require('../config.php');
require_once($CFG->dirroot . '/user/editlib.php');
// Try to prevent searching for sites that allow sign-up.
if (!isset($CFG->additionalhtmlhead)) {
@ -60,6 +61,11 @@ if ($mform_signup->is_cancelled()) {
$user->mnethostid = $CFG->mnet_localhost_id;
$user->secret = random_string(15);
$user->auth = $CFG->registerauth;
// Initialize alternate name fields to empty strings.
$namefields = array_diff(get_all_user_name_fields(), useredit_get_required_name_fields());
foreach ($namefields as $namefield) {
$user->$namefield = '';
}
$authplugin->user_signup($user, true); // prints notice and link to login/index.php
exit; //never reached

View File

@ -28,6 +28,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot . '/user/editlib.php');
class login_signup_form extends moodleform {
function definition() {
@ -59,23 +60,17 @@ class login_signup_form extends moodleform {
$mform->setType('email2', PARAM_NOTAGS);
$mform->addRule('email2', get_string('missingemail'), 'required', null, 'server');
$nameordercheck = new stdClass();
$nameordercheck->firstname = 'a';
$nameordercheck->lastname = 'b';
if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325
$mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
$mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
} else {
$mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
$mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
$namefields = useredit_get_required_name_fields();
foreach ($namefields as $field) {
$mform->addElement('text', $field, get_string($field), 'maxlength="100" size="30"');
$mform->setType($field, PARAM_TEXT);
$stringid = 'missing' . $field;
if (!get_string_manager()->string_exists($stringid, 'moodle')) {
$stringid = 'required';
}
$mform->addRule($field, get_string($stringid), 'required', null, 'server');
}
$mform->setType('firstname', PARAM_TEXT);
$mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'server');
$mform->setType('lastname', PARAM_TEXT);
$mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'server');
$mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="20"');
$mform->setType('city', PARAM_TEXT);
$mform->addRule('city', get_string('missingcity'), 'required', null, 'server');