mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-63174 user: core_user_create_users to throw exception on empty names
To be consistent with the web administration UI, we should not allow to create invalid user records with empty username, lastname or firstname via the web services.
This commit is contained in:
parent
6e445671c1
commit
0e99d58c35
2 changed files with 85 additions and 0 deletions
|
@ -157,6 +157,13 @@ class core_user_external extends external_api {
|
|||
$userids = array();
|
||||
$createpassword = false;
|
||||
foreach ($params['users'] as $user) {
|
||||
// Make sure that the username, firstname and lastname are not blank.
|
||||
foreach (array('username', 'firstname', 'lastname') as $fieldname) {
|
||||
if (trim($user[$fieldname]) === '') {
|
||||
throw new invalid_parameter_exception('The field '.$fieldname.' cannot be blank');
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure that the username doesn't already exist.
|
||||
if ($DB->record_exists('user', array('username' => $user['username'], 'mnethostid' => $CFG->mnet_localhost_id))) {
|
||||
throw new invalid_parameter_exception('Username already exists: '.$user['username']);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue