Ignore:
Timestamp:
Apr 9, 2013, 6:46:57 PM (11 years ago)
Author:
Eric
Message:

Version 2.5.8:
Add accounts synchronization from FluxBB to Piwigo
Bug fixed : Missing function in audit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Register_FluxBB/include/functions.inc.php

    r22091 r22092  
    640640
    641641/**
     642 * Add new registered user in Piwigo users table from audit/synch action
     643 * To solve password synch problem, passwords are reset to NULL to force users to get a new password on their profile page
     644 *
     645 * @return : $error
     646 */
     647function Synch_Piwigo_Adduser($fluxbb_id, $username, $email)
     648{
     649  global $conf;
     650  load_language('plugin.lang', REGFLUXBB_PATH);
     651
     652  if (!get_userid_by_email($email) and !get_userid($username))
     653  {
     654    // find a password
     655    $password = generate_key(8);
     656
     657    $error = register_user($username, $password, $email, false);
     658
     659    if (empty($error))
     660    {
     661      include_once(PHPWG_ROOT_PATH.'include/functions_mail.inc.php');
     662
     663      $keyargs_content = array(
     664        get_l10n_args('Hello %s,', $login),
     665        get_l10n_args('To synchronize your forum access with the gallery you have been registered at %s!', $conf['gallery_title']),
     666        get_l10n_args('', ''),
     667        get_l10n_args('Here are your connection settings', ''),
     668        get_l10n_args('Username: %s', $login),
     669        get_l10n_args('Password: %s', $password),
     670        get_l10n_args('Email: %s', $mail_address),
     671        get_l10n_args('', ''),
     672        get_l10n_args('Please change your password at your first connexion on the gallery', ''),
     673        get_l10n_args('', ''),
     674        get_l10n_args('If you think you\'ve received this email in error, please contact us at %s', get_webmaster_mail_address()),
     675      );
     676
     677      pwg_mail(
     678        $mail_address,
     679        array(
     680          'subject' => '['.$conf['gallery_title'].'] '.l10n('Registration'),
     681          'content' => l10n_args($keyargs_content),
     682          'content_format' => 'text/plain',
     683          )
     684      );
     685
     686      $pwg_id = get_userid($username);
     687
     688      FluxBB_Linkuser($pwg_id, $fluxbb_id, "NOK");
     689     
     690      $error = false;
     691    }
     692  }
     693  else $error = true;
     694
     695  return $error;
     696}
     697
     698
     699/**
     700 * Update user information in FluxBB users table from audit/synch action
     701 * Standard FluxBB_Updateuser() function is not used because of existing password mismatch
     702 * To solve password synch problem, passwords are reset to NULL to force users to get a new password by using "forgotten password" function
     703 */
     704function Synch_FluxBB_Updateuser($pwg_id, $username, $adresse_mail)
     705{
     706  global $conf;
     707 
     708  include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
     709  $conf_Register_FluxBB = unserialize($conf['Register_FluxBB']);
     710  $password = NULL;
     711
     712// Select users to update in ID link table
     713  $query = '
     714SELECT id_user_FluxBB as FluxBB_id
     715FROM '.Register_FluxBB_ID_TABLE.'
     716WHERE id_user_pwg = '.$pwg_id.'
     717;';
     718
     719  $row = pwg_db_fetch_assoc(pwg_query($query));
     720
     721  if (!empty($row))
     722  {
     723    $query = '
     724UPDATE '.FluxBB_USERS_TABLE.'
     725SET username = "'.pwg_db_real_escape_string($username).'", email = "'.$adresse_mail.'", password = "'.$password.'"
     726WHERE id = '.$row['FluxBB_id'].'
     727AND "'.pwg_db_real_escape_string($username).'" NOT IN ("18","16")
     728AND "'.pwg_db_real_escape_string($username).'" <> "'.stripslashes($conf_Register_FluxBB['FLUXBB_ADMIN']).'"
     729;';
     730
     731    pwg_query($query);
     732
     733    FluxBB_Linkuser($pwg_id, $row['FluxBB_id'], "NOK");
     734  }
     735  else
     736  {
     737    $query = '
     738SELECT id as FluxBB_id
     739FROM '.FluxBB_USERS_TABLE.'
     740WHERE BINARY username = BINARY "'.pwg_db_real_escape_string($username).'"
     741AND "'.pwg_db_real_escape_string($username).'" <> "'.stripslashes($conf_Register_FluxBB['FLUXBB_ADMIN']).'"
     742;';
     743
     744    $row = pwg_db_fetch_assoc(pwg_query($query));
     745
     746    if (!empty($row))
     747    {
     748      $query = '
     749UPDATE '.FluxBB_USERS_TABLE.'
     750SET username = "'.pwg_db_real_escape_string($username).'", email = "'.$adresse_mail.'", password = "'.$password.'"
     751WHERE id = '.$row['FluxBB_id'].'
     752AND "'.pwg_db_real_escape_string($username).'" NOT IN ("18","16")
     753AND "'.pwg_db_real_escape_string($username).'" <> "'.stripslashes($conf_Register_FluxBB['FLUXBB_ADMIN']).'"
     754;';
     755
     756      pwg_query($query);
     757
     758      FluxBB_Linkuser($pwg_id, $row['FluxBB_id'], "NOK");
     759    }
     760  }
     761}
     762
     763
     764/**
     765 * Reg_FluxBB_PwdSynch
     766 * Checks if a password needs to be resynch between Piwigo and FluxBB
     767 *
     768 * @uid        : the user id
     769 *
     770 * @returns    : true if the password is NOT synchronized (NOK) else false
     771 *
     772 */
     773function Reg_FluxBB_PwdSynch($uid)
     774{
     775  $query = '
     776SELECT PwdSynch
     777FROM '.Register_FluxBB_ID_TABLE.'
     778WHERE id_user_pwg='.$uid.'
     779;';
     780
     781  $result = pwg_db_fetch_assoc(pwg_query($query));
     782
     783  if($result['PwdSynch'] == "NOK" or is_null($result['PwdSynch']))
     784  {
     785    return true;
     786  }
     787  else return false;
     788}
     789
     790
     791/**
    642792 * Search linked users
    643793 */
Note: See TracChangeset for help on using the changeset viewer.