Permalink
Browse files

Merge branch 'MDL-31762-MOODLE_21_STABLE' of git://github.com/mouneyr…

…ac/moodle into MOODLE_21_STABLE
  • Loading branch information...
2 parents 22ec5e8 + 69dcda2 commit b702373a4d2bc0d232df81fabbb858cb00ee50c4 Sam Hemelryk committed May 2, 2012
Showing with 23 additions and 3 deletions.
  1. +3 −3 user/externallib.php
  2. +20 −0 user/lib.php
View
@@ -40,7 +40,7 @@ public static function create_users_parameters() {
'users' => new external_multiple_structure(
new external_single_structure(
array(
- 'username' => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config'),
+ 'username' => new external_value(PARAM_USERNAME, 'Username policy is defined in Moodle security config. Must be lowercase.'),
'password' => new external_value(PARAM_RAW, 'Plain text password consisting of any characters'),
'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user'),
'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user'),
@@ -181,7 +181,7 @@ public static function create_users_returns() {
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'user id'),
- 'username' => new external_value(PARAM_RAW, 'user name'),
+ 'username' => new external_value(PARAM_USERNAME, 'user name'),
)
)
);
@@ -251,7 +251,7 @@ public static function update_users_parameters() {
new external_single_structure(
array(
'id' => new external_value(PARAM_NUMBER, 'ID of the user'),
- 'username' => new external_value(PARAM_RAW, 'Username policy is defined in Moodle security config', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED),
+ 'username' => new external_value(PARAM_USERNAME, 'Username policy is defined in Moodle security config. Must be lowercase.', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED),
'password' => new external_value(PARAM_RAW, 'Plain text password consisting of any characters', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED),
'firstname' => new external_value(PARAM_NOTAGS, 'The first name(s) of the user', VALUE_OPTIONAL, '',NULL_NOT_ALLOWED),
'lastname' => new external_value(PARAM_NOTAGS, 'The family name of the user', VALUE_OPTIONAL),
View
@@ -39,6 +39,15 @@ function user_create_user($user) {
$user = (object)$user;
}
+ //check username
+ if ($user->username !== textlib::strtolower($user->username)) {
+ throw new moodle_exception('usernamelowercase');
+ } else {
+ if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
+ throw new moodle_exception('invalidusername');
+ }
+ }
+
// save the password in a temp value for later
if (isset($user->password)) {
$userpassword = $user->password;
@@ -80,6 +89,17 @@ function user_update_user($user) {
$user = (object)$user;
}
+ //check username
+ if (isset($user->username)) {
+ if ($user->username !== textlib::strtolower($user->username)) {
+ throw new moodle_exception('usernamelowercase');
+ } else {
+ if ($user->username !== clean_param($user->username, PARAM_USERNAME)) {
+ throw new moodle_exception('invalidusername');
+ }
+ }
+ }
+
// unset password here, for updating later
if (isset($user->password)) {
$passwd = $user->password;

0 comments on commit b702373

Please sign in to comment.