Skip to content

Commit

Permalink
MDL-52781 core_user: replace direct PARAM_ usages.
Browse files Browse the repository at this point in the history
This commit replace as much as possible of clean_param and PARAM_ usages related to user object.
Also few unit tests has been changed to match the new validation
  • Loading branch information
lameze committed Apr 21, 2016
1 parent 7a06720 commit ac9768f
Show file tree
Hide file tree
Showing 16 changed files with 219 additions and 217 deletions.
12 changes: 6 additions & 6 deletions admin/tool/uploaduser/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@
// normalize username
$originalusername = $user->username;
if ($standardusernames) {
$user->username = clean_param($user->username, PARAM_USERNAME);
$user->username = core_user::clean_field($user->username, 'username');
}

// make sure we really have username
Expand All @@ -295,7 +295,7 @@
continue;
}

if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
if ($user->username !== core_user::clean_field($user->username, 'username')) {
$upt->track('status', get_string('invalidusername', 'error', 'username'), 'error');
$upt->track('username', $errorstr, 'error');
$userserrors++;
Expand Down Expand Up @@ -443,7 +443,7 @@
}

if ($standardusernames) {
$oldusername = clean_param($user->oldusername, PARAM_USERNAME);
$oldusername = core_user::clean_field($user->oldusername, 'username');
} else {
$oldusername = $user->oldusername;
}
Expand Down Expand Up @@ -597,7 +597,7 @@
if (empty($user->lang)) {
// Do not change to not-set value.
continue;
} else if (clean_param($user->lang, PARAM_LANG) === '') {
} else if (core_user::clean_field($user->lang, 'lang') === '') {
$upt->track('status', get_string('cannotfindlang', 'error', $user->lang), 'warning');
continue;
}
Expand Down Expand Up @@ -774,7 +774,7 @@

if (empty($user->lang)) {
$user->lang = '';
} else if (clean_param($user->lang, PARAM_LANG) === '') {
} else if (core_user::clean_field($user->lang, 'lang') === '') {
$upt->track('status', get_string('cannotfindlang', 'error', $user->lang), 'warning');
$user->lang = '';
}
Expand Down Expand Up @@ -1177,7 +1177,7 @@
$rowcols['status'] = array();

if (isset($rowcols['username'])) {
$stdusername = clean_param($rowcols['username'], PARAM_USERNAME);
$stdusername = core_user::clean_field($rowcols['username'], 'username');
if ($rowcols['username'] !== $stdusername) {
$rowcols['status'][] = get_string('invalidusernameupload');
}
Expand Down
12 changes: 6 additions & 6 deletions admin/tool/uploaduser/user_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,28 @@ function definition () {

$choices = array(0 => get_string('emaildisplayno'), 1 => get_string('emaildisplayyes'), 2 => get_string('emaildisplaycourse'));
$mform->addElement('select', 'maildisplay', get_string('emaildisplay'), $choices);
$mform->setDefault('maildisplay', $CFG->defaultpreference_maildisplay);
$mform->setDefault('maildisplay', core_user::get_property_default('maildisplay'));

$choices = array(0 => get_string('textformat'), 1 => get_string('htmlformat'));
$mform->addElement('select', 'mailformat', get_string('emailformat'), $choices);
$mform->setDefault('mailformat', $CFG->defaultpreference_mailformat);
$mform->setDefault('mailformat', core_user::get_property_default('mailformat'));
$mform->setAdvanced('mailformat');

$choices = array(0 => get_string('emaildigestoff'), 1 => get_string('emaildigestcomplete'), 2 => get_string('emaildigestsubjects'));
$mform->addElement('select', 'maildigest', get_string('emaildigest'), $choices);
$mform->setDefault('maildigest', $CFG->defaultpreference_maildigest);
$mform->setDefault('maildigest', core_user::get_property_default('maildigest'));
$mform->setAdvanced('maildigest');

$choices = array(1 => get_string('autosubscribeyes'), 0 => get_string('autosubscribeno'));
$mform->addElement('select', 'autosubscribe', get_string('autosubscribe'), $choices);
$mform->setDefault('autosubscribe', $CFG->defaultpreference_autosubscribe);
$mform->setDefault('autosubscribe', core_user::get_property_default('autosubscribe'));

$mform->addElement('text', 'city', get_string('city'), 'maxlength="120" size="25"');
$mform->setType('city', PARAM_TEXT);
if (empty($CFG->defaultcity)) {
$mform->setDefault('city', $templateuser->city);
} else {
$mform->setDefault('city', $CFG->defaultcity);
$mform->setDefault('city', core_user::get_property_default('city'));
}

$choices = get_string_manager()->get_list_of_countries();
Expand All @@ -256,7 +256,7 @@ function definition () {
if (empty($CFG->country)) {
$mform->setDefault('country', $templateuser->country);
} else {
$mform->setDefault('country', $CFG->country);
$mform->setDefault('country', core_user::get_property_default('country'));
}
$mform->setAdvanced('country');

Expand Down
Loading

0 comments on commit ac9768f

Please sign in to comment.