Changeset 25116


Ignore:
Timestamp:
Oct 24, 2013, 3:01:25 PM (10 years ago)
Author:
mistic100
Message:

bug 2988: register_user() must returns new user id

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/user_list.php

    r25018 r25116  
    205205    else
    206206    {
    207       $page['errors'] = register_user(
    208         $_POST['login'], $_POST['password'], $_POST['email'], false);
     207      register_user($_POST['login'],
     208                    $_POST['password'],
     209                    $_POST['email'],
     210                    false,
     211                    $page['errors']);
    209212
    210213      if (count($page['errors']) == 0)
     
    219222  if (isset($_POST['submit_add']))
    220223  {
    221     $page['errors'] = register_user(
    222       $_POST['login'], $_POST['password'], $_POST['email'], false);
     224    register_user($_POST['login'],
     225                  $_POST['password'],
     226                  $_POST['email'],
     227                  false,
     228                  $page['errors']);
    223229
    224230    if (count($page['errors']) == 0)
  • trunk/include/functions_user.inc.php

    r25019 r25116  
    120120   return $users_found[0];
    121121}
     122
     123/**
     124 * create a new user
     125 * @param string $login
     126 * @param string $password
     127 * @param string $mail_adress
     128 * @param bool $with_notifications
     129 * @param &array $errors
     130 * @return int|bool
     131 */
    122132function register_user($login, $password, $mail_address,
    123   $with_notification = true, $errors = array())
     133  $with_notification = true, &$errors = array())
    124134{
    125135  global $conf;
     
    172182  if (count($errors) == 0)
    173183  {
    174     // what will be the inserted id ?
    175     $query = '
    176 SELECT MAX('.$conf['user_fields']['id'].') + 1
    177   FROM '.USERS_TABLE.'
    178 ;';
    179     list($next_id) = pwg_db_fetch_row(pwg_query($query));
    180 
    181184    $insert =
    182185      array(
    183         $conf['user_fields']['id'] => $next_id,
    184186        $conf['user_fields']['username'] => pwg_db_real_escape_string($login),
    185187        $conf['user_fields']['password'] => $conf['password_hash']($password),
     
    188190
    189191    single_insert(USERS_TABLE, $insert);
     192    $user_id = pwg_db_insert_id();
    190193
    191194    // Assign by default groups
    192     {
    193       $query = '
     195    $query = '
    194196SELECT id
    195197  FROM '.GROUPS_TABLE.'
     
    197199  ORDER BY id ASC
    198200;';
    199       $result = pwg_query($query);
    200 
    201       $inserts = array();
    202       while ($row = pwg_db_fetch_assoc($result))
    203       {
    204           $inserts[] = array(
    205             'user_id' => $next_id,
    206             'group_id' => $row['id']
    207           );
    208       }
     201    $result = pwg_query($query);
     202
     203    $inserts = array();
     204    while ($row = pwg_db_fetch_assoc($result))
     205    {
     206        $inserts[] = array(
     207          'user_id' => $user_id,
     208          'group_id' => $row['id']
     209        );
    209210    }
    210211
     
    220221        $override=null;
    221222    }
    222     create_user_infos($next_id, $override);
     223    create_user_infos($user_id, $override);
    223224
    224225    if ($with_notification and $conf['email_admin_on_new_user'])
     
    245246    trigger_action('register_user',
    246247      array(
    247         'id'=>$next_id,
     248        'id'=>$user_id,
    248249        'username'=>$login,
    249250        'email'=>$mail_address,
    250251       )
    251252      );
    252   }
    253 
    254   return $errors;
     253     
     254    return $user_id;
     255  }
     256  else
     257  {
     258    return false;
     259  }
    255260}
    256261
  • trunk/include/user.inc.php

    r20599 r25116  
    6161    if (!($user['id'] = get_userid($remote_user)))
    6262    {
    63       register_user($remote_user, '', '', false);
    64       $user['id'] = get_userid($remote_user);
     63      $user['id'] = register_user($remote_user, '', '', false);
    6564    }
    6665  }
  • trunk/register.php

    r25018 r25116  
    5353  }
    5454
    55   $page['errors'] =
    56       register_user($_POST['login'],
    57                     $_POST['password'],
    58                     $_POST['mail_address'],
    59                     true,
    60                     $page['errors']);
     55  register_user($_POST['login'],
     56                $_POST['password'],
     57                $_POST['mail_address'],
     58                true,
     59                $page['errors']);
    6160
    6261  if (count($page['errors']) == 0)
Note: See TracChangeset for help on using the changeset viewer.