Skip to content
Snippets Groups Projects
Commit 7c37db8a authored by matthias.grimm's avatar matthias.grimm
Browse files

mysql create user function

This patch adds the missing function createuser in the mysql auth module.
Some new SQL statements have to be defined so that it works:
$conf['auth']['mysql']['getgroupid']   to get the ID of a given group
$conf['auth']['mysql']['adduser']      to add a user to the database
$conf['auth']['mysql']['addusergroup'] to let the user join a given group

darcs-hash:20050508183140-45302-de96a42fd79801a5e9ab14cb476f56b2c9432d7c.gz
parent 919eeb46
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
}
......
......@@ -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 :
......@@ -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;
}
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment