diff --git a/inc/auth.php b/inc/auth.php index ca6fb20deeff0c1b6d4434a8c8058befe0fa1cbd..26be26d453894e7eb73db14e88c82b03ab45918c 100644 --- a/inc/auth.php +++ b/inc/auth.php @@ -389,7 +389,8 @@ function register(){ } //okay try to create the user - $pass = auth_createUser($_POST['login'],$_POST['fullname'],$_POST['email']); + $pass = auth_pwgen(); + $pass = auth_createUser($_POST['login'],$pass,$_POST['fullname'],$_POST['email']); if(empty($pass)){ msg($lang['reguexists'],-1); return false; diff --git a/inc/auth_ldap.php b/inc/auth_ldap.php index 1ab5206a7f579ae1f78f22c816bc9a89f933aad2..6c852810d7af0fbde01768d7a940a6a909a32f1e 100644 --- a/inc/auth_ldap.php +++ b/inc/auth_ldap.php @@ -199,7 +199,7 @@ function auth_getUserData($user){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function auth_createUser($user,$name,$mail){ +function auth_createUser($user,$pass,$name,$mail){ msg("Sorry. Creating users is not supported by the LDAP backend",-1); return null; } diff --git a/inc/auth_mysql.php b/inc/auth_mysql.php index a4fafec3bfb0b5f60dbcee096d07cef06c8a0169..ac835ae17cd20f10260217cd83157153948be222 100644 --- a/inc/auth_mysql.php +++ b/inc/auth_mysql.php @@ -43,10 +43,11 @@ function auth_mysql_runsql($sql_string) { $resultarray[]=$temparray; } mysql_free_result ($result); - } - if (mysql_insert_id($link)) { + } elseif (mysql_insert_id($link)) { $resultarray = mysql_insert_id($link); //give back ID on insert - } + } else + $resultarray = 0; // asure that the return value is valid + mysql_close ($link); return $resultarray; } @@ -55,7 +56,9 @@ function auth_mysql_runsql($sql_string) { * Check user+password [required auth function] * * Checks if the given user exists and the given - * plaintext password is correct + * plaintext password is correct. Furtheron it + * might be checked wether the user is member of + * the right group * * @author Andreas Gohr <andi@splitbrain.org> * @return bool @@ -65,6 +68,7 @@ function auth_checkPass($user,$pass){ $cnf = $conf['auth']['mysql']; $sql = str_replace('%u',addslashes($user),$cnf['passcheck']); + $sql = str_replace('%g',addslashes($conf['defaultgroup']),$sql); $sql = str_replace('%p',addslashes($pass),$sql); $result = auth_mysql_runsql($sql); return(count($result)); @@ -107,14 +111,51 @@ function auth_getUserData($user){ /** * Create a new User [required auth function] * - * Not implemented + * user string username + * pass string password + * name string full name of the user + * mail string email address * - * @author Andreas Gohr <andi@splitbrain.org> + * Returns false if the user already exists, null when an error + * occoured and the cleartext password of the new user if + * everything went well. + * + * The user HAS TO be added to the default group by this + * function + * + * @author Matthias Grimm <matthiasgrimm@users.sourceforge.net> */ -function auth_createUser($user,$name,$mail){ - msg("Sorry. Creating users is not supported by the MySQL backend, yet",-1); - return null; -} +function auth_createUser($user,$pass,$name,$mail){ + global $conf; + $cnf = $conf['auth']['mysql']; + + $info = auth_getUserData($user); + if ($info != false) return false; + + $sql = str_replace('%g',$conf['defaultgroup'],$cnf['getgroupid']); + $result = auth_mysql_runsql($sql); + + if (count($result) == 1) { + $gid = $result[0]['gid']; + + $sql = str_replace('%u',$user,$cnf['adduser']); + $sql = str_replace('%p',$pass,$sql); + $sql = str_replace('%n',$name,$sql); + $sql = str_replace('%e',$mail,$sql); + $uid = auth_mysql_runsql($sql); + + if ($uid != 0) { + $sql = str_replace('%uid',$uid,$cnf['addusergroup']); + $sql = str_replace('%gid',$gid,$sql); + auth_mysql_runsql($sql); + return $pass; + } else + msg("Registering of the new user '$user' failed!", -1); + } else + msg("The default group is not cleanly defined in the database!", -1); + return null; +} + //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/auth_pgsql.php b/inc/auth_pgsql.php index 0bbea07e7f8dee0d4aa5929107ca298653e17579..e9c36eb588ba5b6c40eda92fbc76c98f327a596c 100644 --- a/inc/auth_pgsql.php +++ b/inc/auth_pgsql.php @@ -103,7 +103,7 @@ function auth_getUserData($user){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function auth_createUser($user,$name,$mail){ +function auth_createUser($user,$pass,$name,$mail){ msg("Sorry. Creating users is not supported by the PgSQL backend, yet",-1); return null; } diff --git a/inc/auth_plain.php b/inc/auth_plain.php index 33b5e2374e2b60a2d401e7b6fc8eea5e5a3b00e9..93168a26f87fffd894bd358eef77b1c5c4b5f669 100644 --- a/inc/auth_plain.php +++ b/inc/auth_plain.php @@ -64,13 +64,12 @@ function auth_getUserData($user){ * * @author Andreas Gohr <andi@splitbrain.org> */ -function auth_createUser($user,$name,$mail){ +function auth_createUser($user,$pass,$name,$mail){ global $conf; $users = auth_plain_loadUserData(); if(isset($users[$user])) return false; - $pass = auth_pwgen(); $userline = join(':',array($user, md5($pass), $name,