Ignore:
Timestamp:
Aug 18, 2010, 10:56:53 PM (14 years ago)
Author:
Eric
Message:

Merge from Trunk to Branch 2.5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/NBC_UserAdvManager/branches/2.15/main.inc.php

    r6256 r6776  
    22/*
    33Plugin Name: UserAdvManager
    4 Version: 2.15.3
     4Version: 2.15.4
    55Description: Renforcer la gestion des utilisateurs - Enforce users management
    66Plugin URI: http://fr.piwigo.org/ext/extension_view.php?eid=216
     
    1313/*
    1414 ***** TODO List *****
    15 ++ Adding ASC and DESC ordering for user's lists tables (Ghost Tracker, UserList and Unvalidated) ?
    16 
    1715++ No validation needed for admins users comments (new trigger needed in comments.php ?)
    1816
     
    8078  if (!is_admin() and !is_a_guest())
    8179  {
    82     if ((isset($conf_UAM[17]) and $conf_UAM[17] == 'true') or (isset($conf_UAM[20]) and $conf_UAM[20] == 'true'))
     80    if ((isset($conf_UAM[16]) and $conf_UAM[16] == 'true') or (isset($conf_UAM[19]) and $conf_UAM[19] == 'true'))
    8381    {
    8482
     
    128126  $conf_UAM = unserialize($conf['UserAdvManager']);
    129127 
    130   /* Sending registration confirmation by email */
    131   if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or (isset($conf_UAM[2]) and $conf_UAM[2] == 'true'))
    132   {
    133     if (is_admin() and isset($conf_UAM[21]) and $conf_UAM[21] == 'true')
    134     {
    135     $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
    136     SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true);
    137     }
    138     elseif (is_admin() and isset($conf_UAM[21]) and $conf_UAM[21] == 'false')
    139     {
     128  if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
     129  {
     130    /* This is to send an information email and set user to "waiting" group or status until admin validation */
    140131    $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
    141132    SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false);
     133    setgroup($register_user['id']);// Set to "waiting" group or status until admin validation
     134  }
     135  elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'false') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
     136  {
     137    /* This is to set user to "wainting" group or status until admin validation */
     138    setgroup($register_user['id']);// Set to "waiting" group or status until admin validation
     139  }
     140  elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'false'))
     141  {
     142    /* This is to send an information email without validation key */
     143    $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
     144    SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false);
     145  }
     146  /* Sending registration confirmation by email */
     147  elseif ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true'))
     148  {
     149    if (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'true')
     150    {
     151      $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
     152      SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true);
     153    }
     154    elseif (is_admin() and isset($conf_UAM[20]) and $conf_UAM[20] == 'false')
     155    {
     156      $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
     157      SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], false);
    142158    }
    143159    elseif (!is_admin())
    144160    {
    145     $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
    146     SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true);
     161      $passwd = (isset($_POST['password'])) ? $_POST['password'] : '';
     162      SendMail2User(1, $register_user['id'], $register_user['username'], $passwd, $register_user['email'], true);
    147163    }
    148164  }
     
    159175  /* Cleanup for LastVisit table */
    160176  DeleteLastVisit($user_id);
     177  /* Cleanup Redirection settings */
     178  DeleteRedir($user_id);
    161179}
    162180
     
    253271
    254272  /* Password enforcement control */
    255   if (isset($conf_UAM[14]) and $conf_UAM[14] == 'true' and !empty($conf_UAM[15]))
     273  if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14]))
    256274  {
    257275    if (!empty($user['password']) and !is_admin())
     
    259277      $PasswordCheck = testpassword($user['password']);
    260278 
    261       if ($PasswordCheck < $conf_UAM[15])
     279      if ($PasswordCheck < $conf_UAM[14])
    262280      {
    263281        $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
    264         return($lang['reg_err_pass'] = l10n_args($message).$conf_UAM[15]);
    265       }
    266     }
    267     else if (!empty($user['password']) and is_admin() and isset($conf_UAM[16]) and $conf_UAM[16] == 'true')
     282        return($lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]);
     283      }
     284    }
     285    else if (!empty($user['password']) and is_admin() and isset($conf_UAM[15]) and $conf_UAM[15] == 'true')
    268286    {
    269287      $PasswordCheck = testpassword($user['password']);
    270288 
    271       if ($PasswordCheck < $conf_UAM[15])
     289      if ($PasswordCheck < $conf_UAM[14])
    272290      {
    273291        $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
    274         return($lang['reg_err_pass'] = l10n_args($message).$conf_UAM[15]);
    275       }
    276     }
    277   }
    278 
    279   /* Username non case sensitive */
    280   if (isset($conf_UAM[1]) and $conf_UAM[1] == 'true' and NotSensibleSearchUsername($_POST['login']))
    281   {
    282     return($lang['reg_err_login5'] = l10n('reg_err_login5'));
     292        return($lang['reg_err_pass'] = l10n_args($message).$conf_UAM[14]);
     293      }
     294    }
    283295  }
    284296
    285297  /* Username without forbidden keys */
    286   if (isset($conf_UAM[7]) and $conf_UAM[7] == 'true' and !empty($_POST['login']) and ValidateUsername($_POST['login']) and !is_admin())
     298  if (isset($conf_UAM[6]) and $conf_UAM[6] == 'true' and !empty($_POST['login']) and ValidateUsername($_POST['login']) and !is_admin())
    287299  {
    288300    $_POST['login'] = '';
    289     return($lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_UAM[8]."'");
     301    return($lang['reg_err_login1'] = l10n('reg_err_login6')."'".$conf_UAM[7]."'");
    290302  }
    291303
    292304  /* Email without forbidden domains */
    293   if (isset($conf_UAM[12]) and $conf_UAM[12] == 'true' and !empty($_POST['mail_address']) and ValidateEmailProvider($_POST['mail_address']) and !is_admin())
     305  if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['mail_address']) and ValidateEmailProvider($_POST['mail_address']) and !is_admin())
    294306  {
    295307    $_POST['mail_address'] = '';
    296     return($lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_UAM[13]."'");
     308    return($lang['reg_err_login1'] = l10n('reg_err_login7')."'".$conf_UAM[12]."'");
    297309  }
    298310}
     
    309321    $conf_UAM = unserialize($conf['UserAdvManager']);
    310322
     323    if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true'))
     324    {
     325      $user_idsOK = array();
     326      if (!check_consult($user['id'], $user_idsOK))
     327      {
     328        $user_idsOK[] = $user['id'];
     329       
     330        $query = "
     331          UPDATE ".CONFIG_TABLE."
     332          SET value = \"".implode(',', $user_idsOK)."\"
     333          WHERE param = 'UserAdvManager_Redir';";
     334         
     335        pwg_query($query);
     336      }
     337    }
     338
    311339    if (isset($_POST['validate']) and !is_admin())
    312340    {
    313341      /* Email without forbidden domains */
    314       if (isset($conf_UAM[12]) and $conf_UAM[12] == 'true' and !empty($_POST['mail_address']))
     342      if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['mail_address']))
    315343      {
    316344        if (ValidateEmailProvider($_POST['mail_address']))
    317345        {
    318           $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[13]."'");
     346          $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[12]."'");
    319347          unset($_POST['validate']);
    320348        }
     
    328356       
    329357        /* Password enforcement control */
    330         if (isset($conf_UAM[14]) and $conf_UAM[14] == 'true' and !empty($conf_UAM[15]))
     358        if (isset($conf_UAM[13]) and $conf_UAM[13] == 'true' and !empty($conf_UAM[14]))
    331359        {
    332360          $PasswordCheck = testpassword($_POST['use_new_pwd']);
    333361         
    334           if ($PasswordCheck < $conf_UAM[15])
     362          if ($PasswordCheck < $conf_UAM[14])
    335363          {
    336364            $message = get_l10n_args('reg_err_login4_%s', $PasswordCheck);
    337             $template->append('errors', l10n_args($message).$conf_UAM[15]);
     365            $template->append('errors', l10n_args($message).$conf_UAM[14]);
    338366            unset($_POST['use_new_pwd']);
    339367            unset($_POST['validate']);
     
    343371     
    344372      /* Sending registration confirmation by email */
    345       if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or (isset($conf_UAM[2]) and $conf_UAM[2] == 'true'))
     373      if ((isset($conf_UAM[0]) and $conf_UAM[0] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'true') or (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
    346374      {
    347375        $confirm_mail_need = false;
     
    356384         
    357385          list($current_email) = pwg_db_fetch_row(pwg_query($query));
    358      
    359           if ($_POST['mail_address'] != $current_email and ( isset($conf_UAM[2]) and $conf_UAM[2] == 'true'))
     386
     387          /* This is to send a new validation key */
     388          if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'true'))
    360389       
    361390            $confirm_mail_need = true;
     391
     392          /* This is to set the user to "waiting" group or status until admin validation */
     393          if ($_POST['mail_address'] != $current_email and (isset($conf_UAM[1]) and $conf_UAM[1] == 'local'))
     394       
     395            setgroup($register_user['id']);// Set to "waiting" group or status until admin validation
     396            $confirm_mail_need = false;
    362397        }
    363398       
     
    380415
    381416
     417// RedirectToProfile - Thx to LucMorizur
     418// redirects a visitor (not generic (forbidden) neither admin) to his
     419// profile.php page
     420//
     421// no variable, no return
     422add_event_handler('login_success', 'RedirectToProfile');
     423
     424function RedirectToProfile()
     425{
     426  global $conf, $user;
     427 
     428  $conf_UAM = unserialize($conf['UserAdvManager']);
     429
     430  if ((isset($conf_UAM[21]) and $conf_UAM[21] == 'true'))
     431  {
     432    $user_idsOK = array();
     433    if (!check_consult($user['id'], $user_idsOK))
     434      redirect(PHPWG_ROOT_PATH.'profile.php');
     435  }
     436}
     437
     438
    382439add_event_handler('init', 'UAM_InitPage');
    383440/* *** Important ! This is necessary to make email exclusion work in admin's users management panel *** */
     
    395452    {
    396453      /* Email without forbidden domains */
    397       if (isset($conf_UAM[12]) and $conf_UAM[12] == 'true' and !empty($_POST['email']) and ValidateEmailProvider($_POST['email']))
    398       {
    399         $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[13]."'");
     454      if (isset($conf_UAM[11]) and $conf_UAM[11] == 'true' and !empty($_POST['email']) and ValidateEmailProvider($_POST['email']))
     455      {
     456        $template->append('errors', l10n('reg_err_login7')."'".$conf_UAM[12]."'");
    400457        unset($_POST['submit_add']);
    401458      }
     
    415472
    416473/* User creation OR update */
    417   if (isset($conf_UAM[6]) and $conf_UAM[6] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest')
     474  if (isset($conf_UAM[5]) and $conf_UAM[5] == 'true' and $conf['comments_forall'] == 'true' and $comm['author'] == 'guest')
    418475  {
    419476    $comment_action = 'reject';
Note: See TracChangeset for help on using the changeset viewer.