Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-25027 Web Service: added email validation to create_users() - jus…

…t like GUI
  • Loading branch information...
commit 12166ca08d3620a72d472e48a6c8b037e811f2f1 1 parent 70a752c
Aparup Banerjee nebgor authored
Showing with 11 additions and 5 deletions.
  1. +11 −5 user/externallib.php
16 user/externallib.php
View
@@ -83,6 +83,7 @@ public static function create_users_parameters() {
*/
public static function create_users($users) {
global $CFG, $DB;
+ require_once($CFG->dirroot."/lib/weblib.php");
require_once($CFG->dirroot."/user/lib.php");
require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function
//TODO: move the functions somewhere else as
@@ -131,15 +132,20 @@ public static function create_users($users) {
throw new invalid_parameter_exception('Invalid theme: '.$user['theme']);
}
- // Start of User info validation.
- // Lets make sure we validate current user info as handled by current GUI. see user/editadvanced_form.php function validation()
- // ok, there is no validation currently.
- // End of user info validation.
-
$user['confirmed'] = true;
$user['mnethostid'] = $CFG->mnet_localhost_id;
$user['id'] = user_create_user($user);
+ // Start of user info validation.
+ // Lets make sure we validate current user info as handled by current GUI. see user/editadvanced_form.php function validation()
+ if (!validate_email($user['email'])) {
+ throw new invalid_parameter_exception('Email address is invalid: '.$user['email']);
+ } else if ($DB->record_exists('user', array('email'=>$user['email'], 'mnethostid'=>$user['mnethostid']))) {
+ throw new invalid_parameter_exception('Email address already exists: '.$user['email']);
+ }
+ // End of user info validation.
+
+
// custom fields
if(!empty($user['customfields'])) {
foreach($user['customfields'] as $customfield) {
Please sign in to comment.
Something went wrong with that request. Please try again.