diff --git a/lib/user.php b/lib/user.php index b19af940795b..1289f7e2abb6 100644 --- a/lib/user.php +++ b/lib/user.php @@ -156,7 +156,7 @@ public static function setupBackends() { * * Allowed characters in the username are: "a-z", "A-Z", "0-9" and "_.@-" */ - public static function createUser( $uid, $password ) { + public static function createUser( $uid, $password, $email ) { // Check the name for bad characters // Allowed are: "a-z", "A-Z", "0-9" and "_.@-" if( preg_match( '/[^a-zA-Z0-9 _\.@\-]/', $uid )) { @@ -171,6 +171,10 @@ public static function createUser( $uid, $password ) { if(trim($password) == '') { throw new Exception('A valid password must be provided'); } + // No empty email + if(trim($email) === '') { + throw new Exception('A valid email must be provided'); + } // Check if user already exists if( self::userExistsForCreation($uid) ) { @@ -179,7 +183,7 @@ public static function createUser( $uid, $password ) { $run = true; - OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => $uid, "password" => $password )); + OC_Hook::emit( "OC_User", "pre_createUser", array( "run" => &$run, "uid" => $uid, "password" => $password, "email" => $email )); if( $run ) { //create the user in the first backend that supports creating users @@ -187,8 +191,8 @@ public static function createUser( $uid, $password ) { if(!$backend->implementsActions(OC_USER_BACKEND_CREATE_USER)) continue; - $backend->createUser($uid, $password); - OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => $uid, "password" => $password )); + $backend->createUser($uid, $password, $email); + OC_Hook::emit( "OC_User", "post_createUser", array( "uid" => $uid, "password" => $password, "email" => $email )); return self::userExists($uid); } diff --git a/lib/user/database.php b/lib/user/database.php index 210c7f3e1eb2..2edab51d80e5 100644 --- a/lib/user/database.php +++ b/lib/user/database.php @@ -63,14 +63,14 @@ private function getHasher() { * Creates a new user. Basic checking of username is done in OC_User * itself, not in its subclasses. */ - public function createUser( $uid, $password ) { + public function createUser( $uid, $password, $email ) { if( $this->userExists($uid) ) { return false; }else{ $hasher=$this->getHasher(); $hash = $hasher->HashPassword($password.OC_Config::getValue('passwordsalt', '')); - $query = OC_DB::prepare( 'INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )' ); - $result = $query->execute( array( $uid, $hash)); + $query = OC_DB::prepare( 'INSERT INTO `*PREFIX*users` ( `uid`, `password`, `email` ) VALUES( ?, ?, ? )' ); + $result = $query->execute( array( $uid, $hash, $email)); return $result ? true : false; } diff --git a/settings/ajax/createuser.php b/settings/ajax/createuser.php index 56653bed6bd7..cb9b1e99ada3 100644 --- a/settings/ajax/createuser.php +++ b/settings/ajax/createuser.php @@ -25,10 +25,11 @@ } $username = $_POST["username"]; $password = $_POST["password"]; +$email = $_POST["email"]; // Return Success story try { - if (!OC_User::createUser($username, $password)) { + if (!OC_User::createUser($username, $password, $email)) { OC_JSON::error(array('data' => array( 'message' => 'User creation failed for '.$username ))); exit(); } diff --git a/settings/js/users.js b/settings/js/users.js index 4a358a4392d6..c1908f53ef11 100644 --- a/settings/js/users.js +++ b/settings/js/users.js @@ -409,6 +409,7 @@ $(document).ready(function () { event.preventDefault(); var username = $('#newusername').val(); var password = $('#newuserpassword').val(); + var email = $('#newuseremail').val(); if ($.trim(username) == '') { OC.dialogs.alert( t('settings', 'A valid username must be provided'), @@ -421,6 +422,12 @@ $(document).ready(function () { t('settings', 'Error creating user')); return false; } + if ($.trim(email) == '') { + OC.dialogs.alert( + t('settings', 'A valid email must be provided'), + t('settings', 'Error creating user')); + return false; + } var groups = $('#newusergroups').prev().children('div').data('settings').checked; $('#newuser').get(0).reset(); $.post( @@ -428,6 +435,7 @@ $(document).ready(function () { { username: username, password: password, + email: email, groups: groups }, function (result) { diff --git a/settings/templates/users.php b/settings/templates/users.php index 6113337f4eeb..37a5ddc5dde8 100644 --- a/settings/templates/users.php +++ b/settings/templates/users.php @@ -20,7 +20,7 @@