Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…t like GUI
  • Loading branch information...
commit 12166ca08d3620a72d472e48a6c8b037e811f2f1 1 parent 70a752c
Aparup Banerjee authored February 21, 2012

Showing 1 changed file with 11 additions and 5 deletions. Show diff stats Hide diff stats

  1. 16  user/externallib.php
16  user/externallib.php
@@ -83,6 +83,7 @@ public static function create_users_parameters() {
83 83
      */
84 84
     public static function create_users($users) {
85 85
         global $CFG, $DB;
  86
+        require_once($CFG->dirroot."/lib/weblib.php");
86 87
         require_once($CFG->dirroot."/user/lib.php");
87 88
         require_once($CFG->dirroot."/user/profile/lib.php"); //required for customfields related function
88 89
                                                              //TODO: move the functions somewhere else as
@@ -131,15 +132,20 @@ public static function create_users($users) {
131 132
                 throw new invalid_parameter_exception('Invalid theme: '.$user['theme']);
132 133
             }
133 134
 
134  
-            // Start of User info validation.
135  
-            // Lets make sure we validate current user info as handled by current GUI. see user/editadvanced_form.php function validation()
136  
-            // ok, there is no validation currently.
137  
-            // End of user info validation.
138  
-
139 135
             $user['confirmed'] = true;
140 136
             $user['mnethostid'] = $CFG->mnet_localhost_id;
141 137
             $user['id'] = user_create_user($user);
142 138
 
  139
+            // Start of user info validation.
  140
+            // Lets make sure we validate current user info as handled by current GUI. see user/editadvanced_form.php function validation()
  141
+            if (!validate_email($user['email'])) {
  142
+                throw new invalid_parameter_exception('Email address is invalid: '.$user['email']);
  143
+            } else if ($DB->record_exists('user', array('email'=>$user['email'], 'mnethostid'=>$user['mnethostid']))) {
  144
+                throw new invalid_parameter_exception('Email address already exists: '.$user['email']);
  145
+            }
  146
+            // End of user info validation.
  147
+
  148
+
143 149
             // custom fields
144 150
             if(!empty($user['customfields'])) {
145 151
                 foreach($user['customfields'] as $customfield) {

0 notes on commit 12166ca

Please sign in to comment.
Something went wrong with that request. Please try again.