mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-04-27 19:59:56 +03:00
bug 2988: register_user() must returns new user id
git-svn-id: http://piwigo.org/svn/trunk@25116 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
d6211432ec
commit
2d2a2e2813
4 changed files with 45 additions and 36 deletions
|
@ -119,8 +119,18 @@ function search_case_username($username)
|
|||
else
|
||||
return $users_found[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new user
|
||||
* @param string $login
|
||||
* @param string $password
|
||||
* @param string $mail_adress
|
||||
* @param bool $with_notifications
|
||||
* @param &array $errors
|
||||
* @return int|bool
|
||||
*/
|
||||
function register_user($login, $password, $mail_address,
|
||||
$with_notification = true, $errors = array())
|
||||
$with_notification = true, &$errors = array())
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
@ -171,41 +181,32 @@ function register_user($login, $password, $mail_address,
|
|||
// if no error until here, registration of the user
|
||||
if (count($errors) == 0)
|
||||
{
|
||||
// what will be the inserted id ?
|
||||
$query = '
|
||||
SELECT MAX('.$conf['user_fields']['id'].') + 1
|
||||
FROM '.USERS_TABLE.'
|
||||
;';
|
||||
list($next_id) = pwg_db_fetch_row(pwg_query($query));
|
||||
|
||||
$insert =
|
||||
array(
|
||||
$conf['user_fields']['id'] => $next_id,
|
||||
$conf['user_fields']['username'] => pwg_db_real_escape_string($login),
|
||||
$conf['user_fields']['password'] => $conf['password_hash']($password),
|
||||
$conf['user_fields']['email'] => $mail_address
|
||||
);
|
||||
|
||||
single_insert(USERS_TABLE, $insert);
|
||||
$user_id = pwg_db_insert_id();
|
||||
|
||||
// Assign by default groups
|
||||
{
|
||||
$query = '
|
||||
$query = '
|
||||
SELECT id
|
||||
FROM '.GROUPS_TABLE.'
|
||||
WHERE is_default = \''.boolean_to_string(true).'\'
|
||||
ORDER BY id ASC
|
||||
;';
|
||||
$result = pwg_query($query);
|
||||
$result = pwg_query($query);
|
||||
|
||||
$inserts = array();
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$inserts[] = array(
|
||||
'user_id' => $next_id,
|
||||
'group_id' => $row['id']
|
||||
);
|
||||
}
|
||||
$inserts = array();
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$inserts[] = array(
|
||||
'user_id' => $user_id,
|
||||
'group_id' => $row['id']
|
||||
);
|
||||
}
|
||||
|
||||
if (count($inserts) != 0)
|
||||
|
@ -219,7 +220,7 @@ SELECT id
|
|||
if ( !get_browser_language($override['language']) )
|
||||
$override=null;
|
||||
}
|
||||
create_user_infos($next_id, $override);
|
||||
create_user_infos($user_id, $override);
|
||||
|
||||
if ($with_notification and $conf['email_admin_on_new_user'])
|
||||
{
|
||||
|
@ -244,14 +245,18 @@ SELECT id
|
|||
|
||||
trigger_action('register_user',
|
||||
array(
|
||||
'id'=>$next_id,
|
||||
'id'=>$user_id,
|
||||
'username'=>$login,
|
||||
'email'=>$mail_address,
|
||||
)
|
||||
);
|
||||
|
||||
return $user_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
function build_user( $user_id, $use_cache )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue