Ignore:
Timestamp:
Oct 30, 2013, 1:54:46 PM (10 years ago)
Author:
plg
Message:

feature 1668, user manager redesign: ability to add a new user (call to pwg.users.add through AJAX)

Move the "send connection settings" code to function register_user (avoid code duplication).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_user.inc.php

    r25116 r25237  
    126126 * @param string $password
    127127 * @param string $mail_adress
    128  * @param bool $with_notifications
     128 * @param bool $notify_admin
    129129 * @param &array $errors
     130 * @param bool $notify_user
    130131 * @return int|bool
    131132 */
    132 function register_user($login, $password, $mail_address,
    133   $with_notification = true, &$errors = array())
     133function register_user($login, $password, $mail_address, $notify_admin=true, &$errors = array(), $notify_user=false)
    134134{
    135135  global $conf;
     
    170170  }
    171171
    172   $errors = trigger_event('register_user_check',
    173               $errors,
    174               array(
    175                 'username'=>$login,
    176                 'password'=>$password,
    177                 'email'=>$mail_address,
    178               )
    179             );
     172  $errors = trigger_event(
     173    'register_user_check',
     174    $errors,
     175    array(
     176      'username'=>$login,
     177      'password'=>$password,
     178      'email'=>$mail_address,
     179      )
     180    );
    180181
    181182  // if no error until here, registration of the user
    182183  if (count($errors) == 0)
    183184  {
    184     $insert =
    185       array(
    186         $conf['user_fields']['username'] => pwg_db_real_escape_string($login),
    187         $conf['user_fields']['password'] => $conf['password_hash']($password),
    188         $conf['user_fields']['email'] => $mail_address
    189         );
     185    $insert = array(
     186      $conf['user_fields']['username'] => pwg_db_real_escape_string($login),
     187      $conf['user_fields']['password'] => $conf['password_hash']($password),
     188      $conf['user_fields']['email'] => $mail_address
     189      );
    190190
    191191    single_insert(USERS_TABLE, $insert);
     
    204204    while ($row = pwg_db_fetch_assoc($result))
    205205    {
    206         $inserts[] = array(
    207           'user_id' => $user_id,
    208           'group_id' => $row['id']
     206      $inserts[] = array(
     207        'user_id' => $user_id,
     208        'group_id' => $row['id']
    209209        );
    210210    }
     
    216216
    217217    $override = null;
    218     if ($with_notification and $conf['browser_language'])
    219     {
    220       if ( !get_browser_language($override['language']) )
     218    if ($notify_admin and $conf['browser_language'])
     219    {
     220      if (!get_browser_language($override['language']))
     221      {
    221222        $override=null;
     223      }
    222224    }
    223225    create_user_infos($user_id, $override);
    224226
    225     if ($with_notification and $conf['email_admin_on_new_user'])
     227    if ($notify_admin and $conf['email_admin_on_new_user'])
    226228    {
    227229      include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
    228       $admin_url = get_absolute_root_url()
    229                    .'admin.php?page=user_list&username='.$login;
    230 
    231       $keyargs_content = array
    232       (
     230      $admin_url = get_absolute_root_url().'admin.php?page=user_list&username='.$login;
     231
     232      $keyargs_content = array(
    233233        get_l10n_args('User: %s', stripslashes($login)),
    234234        get_l10n_args('Email: %s', $_POST['mail_address']),
    235235        get_l10n_args('', ''),
    236236        get_l10n_args('Admin: %s', $admin_url)
    237       );
    238 
    239       pwg_mail_notification_admins
    240       (
     237        );
     238
     239      pwg_mail_notification_admins(
    241240        get_l10n_args('Registration of %s', stripslashes($login)),
    242241        $keyargs_content
    243       );
    244     }
    245 
    246     trigger_action('register_user',
     242        );
     243    }
     244
     245    if ($notify_user and email_check_format($mail_address))
     246    {
     247      include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
     248           
     249      $keyargs_content = array(
     250        get_l10n_args('Hello %s,', $login),
     251        get_l10n_args('Thank you for registering at %s!', $conf['gallery_title']),
     252        get_l10n_args('', ''),
     253        get_l10n_args('Here are your connection settings', ''),
     254        get_l10n_args('Username: %s', $login),
     255        get_l10n_args('Password: %s', $password),
     256        get_l10n_args('Email: %s', $mail_address),
     257        get_l10n_args('', ''),
     258        get_l10n_args('If you think you\'ve received this email in error, please contact us at %s', get_webmaster_mail_address()),
     259        );
     260       
     261      pwg_mail(
     262        $mail_address,
     263        array(
     264          'subject' => '['.$conf['gallery_title'].'] '.l10n('Registration'),
     265          'content' => l10n_args($keyargs_content),
     266          'content_format' => 'text/plain',
     267          )
     268        );
     269    }
     270
     271    trigger_action(
     272      'register_user',
    247273      array(
    248274        'id'=>$user_id,
    249275        'username'=>$login,
    250276        'email'=>$mail_address,
    251        )
     277        )
    252278      );
    253279     
Note: See TracChangeset for help on using the changeset viewer.