Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Facebook Connect Support Thread


Guest

Recommended Posts

Hello People, I found this ...

 

this website explains how to integrate facebook connect with your page step by step, gives a link to the requirements for what facebook required.

This perhaps may be of great help for you to tailor them to the contribution of oscommerce

this is the link of the page:

http://www.emenia.es/crear-aplicacion-facebook-phpsdk-oauth/and this is the link of the sample files with the new requirements:https://github.com/facebook/php-sdk/

if I can adapt, or someone manages to do so, post here, please

Link to comment
Share on other sites

Hi How about, well I wanted to tell you make some changes ... at least now when I click on the facebook connect button works and allows users to deploy the app on Facebook ... but what fails is to write down the names of the client when running the facebook connect, maybe to go forward .. detail:

- As said before, replace the files in the catalog / includes / classes / files in the src folder downloaded here http:// [url=https://github.com/facebook/php-sdk/]https://github.com/facebook/php-sdk/ [/ url]

 

- Then in fbconnect.php

<?php
//Facebook Connect
$fbconfig['appid' ]  = ""; //your application id
$fbconfig['api'   ]  = ""; //your api key
$fbconfig['secret']  = ""; //your application secret
   // Create our Application instance.
   $facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
  'cookie' => true,
   ));

 

remove the api, which apparently serves no pa na ..

 

 
[font="Courier New"]<?php
//Facebook Connect
$fbconfig['appid' ]  = ""; //your application id
$fbconfig['secret']  = ""; //your application secret

   // Create our Application instance.
   $facebook = new Facebook(array(
     'appId'  => $fbconfig['appid'],
     'secret' => $fbconfig['secret'],
   ));[/font]

AND THEN IN

 [/font]
[font="Courier New"][font="Courier New"]$session = $facebook->getSession();

   $fbme = null;
   // Session based graph API call.
   if ($session) {
       $uid = $facebook->getUser();
       $fbme = $facebook->api('/me');
   }

?>[/font][/font]
[font="Courier New"]

 

suggesting I changed the link [/ url], replacing $ uid and $ fbme of our old code ...

 

$uid = $facebook->getUser();[/font]
[font="Courier New"]if ($uid) {
 try {
   // Procedemos a saber si tenemos a un usuario que se ha identificado en Facebook que está autentificado.
   // Si hay algún error se guarda en un archivo de texto (error_log)
   $fbme = $facebook->api('/me');
 } catch (FacebookApiException $e) {
   error_log($e);
   $uid = null;
 }
}[/font]
[font="Courier New"]?>

good and following the last link http://www.emenia.es/crear-aplicacion-facebook-phpsdk-oauth/ [/ url]

in create_account.php and login.php

 

<fb:login-button autologoutlink="true" perms="email,offline_access,user_birthday,user_location,user_work_history,user_religion_politics,user_relationships">Login with Facebook</fb:login-button>

remplace by

<fb:login-button autologoutlink="true" scope="email,offline_access,user_birthday,user_location,user_work_history,user_religion_politics,user_relationships">Conectarse con Facebook</fb:login-button>

good try and tell me, Greetings

Edited by juanmasi1
Link to comment
Share on other sites

Yo actualicé lo mio a OAuth 2.0 y me funciona perfecto.

 

- Descargar el nuevo PHP-SDK de: "https://github.com/facebook/php-sdk/"

- Subir los archivos de la carpeta: "\facebook-php-sdk-4ea94b9\src\" a: "catalog/includes/classes/"

 

En catalog/fbconnect.php

<?php
// Facebook Connect
 $fbconfig['appid' ]  = "xxxxxxxxxxxxxxx"; // your application id
 $fbconfig['api'   ]  = ""; // your api key
 $fbconfig['secret']  = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // your application secret

   // Create our Application instance.
   $facebook = new Facebook(array(
     'appId'  => $fbconfig['appid'],
     'secret' => $fbconfig['secret'],
     'cookie' => true,
   ));

   // We may or may not have this data based on a $_GET or $_COOKIE based session.
   // If we get a session here, it means we found a correctly signed session using
   // the Application Secret only Facebook and the Application know. We dont know
   // if it is still valid until we make an API call using the session. A session
   // can become invalid if it has already expired (should not be getting the
   // session back in this case) or if the user logged out of Facebook.
   $user = $facebook->getUser();

   $fbme = null;
   // Session based graph API call.
   if ($user) {
     try {
       $uid = $facebook->getUser();
       $fbme = $facebook->api('/me');
     } catch (FacebookApiException $e) {
       echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
       $user = null;
     }
   }
?>

 

 

En catalog/login.php

Ojo!!!! todo debe ir debajo de: require('includes/application_top.php');

 require('includes/application_top.php');

// Facebook Connect
 include('includes/classes/facebook.php');
 include_once('fbconnect.php');

// If user is logged in and session is valid.
 if ($fbme) {
 // Collect some data using legacy api
   $param = array(
    'method'     => 'users.getinfo',
    'uids'       => $fbme['id'],
    'fields'     => 'birthday_date, locale',
    'callback'   => ''
   );
   try{
     $info = $facebook->api($param);
   }
   catch(FacebookApiException $e) {
     error_log("Legacy Api Calling Error!");
     echo '<pre>' . htmlspecialchars(print_r($e, true)) . '</pre>';
     $fbme = null;
   }
 }

 

<div id="fb-root"></div>
   <script type="text/javascript">
           window.fbAsyncInit = function() {
               FB.init({appId: '<?php echo $fbconfig['appid']; ?>', status: false, cookie: true, xfbml: true, oauth: true});
               /* All the events registered */
               FB.Event.subscribe('auth.login', function(response) {
                   // do something with response
                   login();
               });
               FB.Event.subscribe('auth.logout', function(response) {
                   // do something with response
                   logout();
               });
           };
           (function() {
               var e = document.createElement('script');
               e.type = 'text/javascript';
               e.src = document.location.protocol +
                   '//connect.facebook.net/es_LA/all.js';
               e.async = true;
               document.getElementById('fb-root').appendChild(e);
           }());
           function login(){
               document.location.href = "login.php";
           }
           function logout(){
               document.location.href = "logoff.php";
           }
           function createAccount(){
               document.location.href = "create_account.php";
           }
   </script>
<p>
 <fb:login-button autologoutlink="true" scope="email, offline_access, user_birthday, user_location, user_about_me, user_work_history, sms, user_website, user_groups, user_online_presence">Identificarme con Facebook</fb:login-button>
</p>

 

 

En catalog/create_account.php

Ojo!!!! todo debe ir debajo de: require('includes/application_top.php');

 require('includes/application_top.php');

// Facebook Connect
 include('includes/classes/facebook.php');
 include_once('fbconnect.php');

// If user is logged in and session is valid.
 if ($fbme){
// Collect some data using legacy api
   $param  =   array(
    'method'     => 'users.getinfo',
    'uids'       => $fbme['id'],
    'fields'     => 'birthday_date, locale',
    'callback'   => ''
   );

   try{
     $info = $facebook->api($param);
   }
   catch(FacebookApiException $e){
     error_log("Legacy Api Calling Error!");
     echo '<pre>' . htmlspecialchars(print_r($e, true)) . '</pre>';
     $fbme = null;
   }
   // Convert fb gender
   if ($fbme['gender'] == 'female') {
     $fbgender = 'f';
   }elseif ($fbme['gender'] == 'male') {
     $fbgender = 'm';
   }
// Convert fb birthday
 function fb_birthday($birthday) {
   list($m, $d, $a) = explode("/", $birthday);
   return $d . "/" . $m . "/" . $a;
   }
 }

 

<div id="fb-root"></div>
   <script type="text/javascript">
           window.fbAsyncInit = function() {
               FB.init({appId: '<?php echo $fbconfig['appid' ]; ?>', status: false, cookie: true, xfbml: true, oauth: true});

               /* All the events registered */
               FB.Event.subscribe('auth.login', function(response) {
                   // do something with response
                   login();
               });
               FB.Event.subscribe('auth.logout', function(response) {
                   // do something with response
                   logout();
               });
           };
           (function() {
               var e = document.createElement('script');
               e.type = 'text/javascript';
               e.src = document.location.protocol +
                   '//connect.facebook.net/es_LA/all.js';
               e.async = true;
               document.getElementById('fb-root').appendChild(e);
           }());

           function login(){
               document.location.href = "create_account.php";
           }

           function logout(){
               document.location.href = "logoff.php";
           }
   </script>
       <?php if ($fbme) {
             } else { ?>
             <p>
               <fb:login-button autologoutlink="true" scope="email, offline_access, user_birthday, user_location, user_about_me, user_work_history, sms, user_website, user_groups, user_online_presence">Registrarme usando Facebook</fb:login-button>
             </p>
       <?php } ?>

 

 

En catalog/logoff.php debajo de: $cart->reset();

 $cart->reset();

// Facebook Connect
 include('includes/classes/facebook.php');
 include_once('fbconnect.php');

 if ($fbme > 0) {
 tep_session_unregister('fb_' . $facebook->getAppId() . '_user_id');
 tep_session_unregister('fb_' . $facebook->getAppId() . '_code');
 tep_session_unregister('fb_' . $facebook->getAppId() . '_access_token');
 // setcookie('fbsr_' . $facebook->getAppId(), '', time()-100, '/', '.' . HTTP_COOKIE_DOMAIN);
 setcookie('fbsr_' . $facebook->getAppId());
 }

Edited by gjferrando
Link to comment
Share on other sites

Hi How about, well I wanted to tell you make some changes ... at least now when I click on the facebook connect button works and allows users to deploy the app on Facebook ... but what fails is to write down the names of the client when running the facebook connect, maybe to go forward ..

 

Need to be replaced "$session" per "$user"

Link to comment
Share on other sites

Yo actualicé lo mio a OAuth 2.0 y me funciona perfecto.

 

- Descargar el nuevo PHP-SDK de: "https://github.com/facebook/php-sdk/"

- Subir los archivos de la carpeta: "\facebook-php-sdk-4ea94b9\src\" a: "catalog/includes/classes/"

 

En catalog/fbconnect.php

<?php
// Facebook Connect
 $fbconfig['appid' ]  = "xxxxxxxxxxxxxxx"; // your application id
 $fbconfig['api'   ]  = ""; // your api key
 $fbconfig['secret']  = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // your application secret

// Create our Application instance.
$facebook = new Facebook(array(
  'appId'  => $fbconfig['appid'],
  'secret' => $fbconfig['secret'],
  'cookie' => true,
));

// We may or may not have this data based on a $_GET or $_COOKIE based session.
// If we get a session here, it means we found a correctly signed session using
// the Application Secret only Facebook and the Application know. We dont know
// if it is still valid until we make an API call using the session. A session
// can become invalid if it has already expired (should not be getting the
// session back in this case) or if the user logged out of Facebook.
$user = $facebook->getUser();

$fbme = null;
// Session based graph API call.
if ($user) {
  try {
	$uid = $facebook->getUser();
	$fbme = $facebook->api('/me');
  } catch (FacebookApiException $e) {
	echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
	$user = null;
  }
}
?>

 

 

En catalog/login.php

Ojo!!!! todo debe ir debajo de: require('includes/application_top.php');

 require('includes/application_top.php');

// Facebook Connect
 include('includes/classes/facebook.php');
 include_once('fbconnect.php');

// If user is logged in and session is valid.
 if ($fbme) {
 // Collect some data using legacy api
$param = array(
 'method'	 => 'users.getinfo',
 'uids'	   => $fbme['id'],
 'fields'	 => 'birthday_date, locale',
 'callback'   => ''
);
try{
  $info = $facebook->api($param);
}
catch(FacebookApiException $e) {
  error_log("Legacy Api Calling Error!");
  echo '<pre>' . htmlspecialchars(print_r($e, true)) . '</pre>';
  $fbme = null;
}
 }

 

<div id="fb-root"></div>
<script type="text/javascript">
		window.fbAsyncInit = function() {
			FB.init({appId: '<?php echo $fbconfig['appid']; ?>', status: false, cookie: true, xfbml: true, oauth: true});
			/* All the events registered */
			FB.Event.subscribe('auth.login', function(response) {
				// do something with response
				login();
			});
			FB.Event.subscribe('auth.logout', function(response) {
				// do something with response
				logout();
			});
		};
		(function() {
			var e = document.createElement('script');
			e.type = 'text/javascript';
			e.src = document.location.protocol +
				'//connect.facebook.net/es_LA/all.js';
			e.async = true;
			document.getElementById('fb-root').appendChild(e);
		}());
		function login(){
			document.location.href = "login.php";
		}
		function logout(){
			document.location.href = "logoff.php";
		}
		function createAccount(){
			document.location.href = "create_account.php";
		}
</script>
<p>
 <fb:login-button autologoutlink="true" scope="email, offline_access, user_birthday, user_location, user_about_me, user_work_history, sms, user_website, user_groups, user_online_presence">Identificarme con Facebook</fb:login-button>
</p>

 

 

En catalog/create_account.php

Ojo!!!! todo debe ir debajo de: require('includes/application_top.php');

 require('includes/application_top.php');

// Facebook Connect
 include('includes/classes/facebook.php');
 include_once('fbconnect.php');

// If user is logged in and session is valid.
 if ($fbme){
// Collect some data using legacy api
$param  =   array(
 'method'	 => 'users.getinfo',
 'uids'	   => $fbme['id'],
 'fields'	 => 'birthday_date, locale',
 'callback'   => ''
);

try{
  $info = $facebook->api($param);
}
catch(FacebookApiException $e){
  error_log("Legacy Api Calling Error!");
  echo '<pre>' . htmlspecialchars(print_r($e, true)) . '</pre>';
  $fbme = null;
}
// Convert fb gender
if ($fbme['gender'] == 'female') {
  $fbgender = 'f';
}elseif ($fbme['gender'] == 'male') {
  $fbgender = 'm';
}
// Convert fb birthday
 function fb_birthday($birthday) {
list($m, $d, $a) = explode("/", $birthday);
return $d . "/" . $m . "/" . $a;
}
 }

 

<div id="fb-root"></div>
<script type="text/javascript">
		window.fbAsyncInit = function() {
			FB.init({appId: '<?php echo $fbconfig['appid' ]; ?>', status: false, cookie: true, xfbml: true, oauth: true});

			/* All the events registered */
			FB.Event.subscribe('auth.login', function(response) {
				// do something with response
				login();
			});
			FB.Event.subscribe('auth.logout', function(response) {
				// do something with response
				logout();
			});
		};
		(function() {
			var e = document.createElement('script');
			e.type = 'text/javascript';
			e.src = document.location.protocol +
				'//connect.facebook.net/es_LA/all.js';
			e.async = true;
			document.getElementById('fb-root').appendChild(e);
		}());

		function login(){
			document.location.href = "create_account.php";
		}

		function logout(){
			document.location.href = "logoff.php";
		}
</script>
	<?php if ($fbme) {
		  } else { ?>
		  <p>
			<fb:login-button autologoutlink="true" scope="email, offline_access, user_birthday, user_location, user_about_me, user_work_history, sms, user_website, user_groups, user_online_presence">Registrarme usando Facebook</fb:login-button>
		  </p>
	<?php } ?>

 

 

En catalog/logoff.php debajo de: $cart->reset();

 $cart->reset();

// Facebook Connect
 include('includes/classes/facebook.php');
 include_once('fbconnect.php');

 if ($fbme > 0) {
 tep_session_unregister('fb_' . $facebook->getAppId() . '_user_id');
 tep_session_unregister('fb_' . $facebook->getAppId() . '_code');
 tep_session_unregister('fb_' . $facebook->getAppId() . '_access_token');
 // setcookie('fbsr_' . $facebook->getAppId(), '', time()-100, '/', '.' . HTTP_COOKIE_DOMAIN);
 setcookie('fbsr_' . $facebook->getAppId());
 }

 

 

Corregir catalog/logoff.php

 

Reemplazar:

 

// setcookie('fbsr_' . $facebook->getAppId(), '', time()-100, '/', '.' . HTTP_COOKIE_DOMAIN);

setcookie('fbsr_' . $facebook->getAppId());

 

Por:

 

unset($_COOKIE['fbsr_' . $facebook->getAppId()]);

setcookie('fbsr_' . $facebook->getAppId(), NULL, -1);

 

Obs.: Agregar estas dos líneas para que no aparezca en el "log" el error: Unknown algorithm. Expected HMAC-SHA256

Edited by gjferrando
Link to comment
Share on other sites

Sigo colaborando..

 

Para que funcione en Internet Explorer, Chrome y Mozilla Firefox (no probé en los otros, pero seguro funciona)

 

Reemplazar:

 

document.location.href = "login.php";

por:

 

setTimeout('document.location.href = "login.php"', 0);

o

 

window.location.reload();

por:

 

setTimeout('document.location.reload()',0);

Edited by gjferrando
Link to comment
Share on other sites

Sigo colaborando..

 

Para que funcione en Internet Explorer, Chrome y Mozilla Firefox (no probé en los otros, pero seguro funciona)

 

Reemplazar:

 

document.location.href = "login.php";

por:

 

setTimeout('document.location.href = "login.php"', 0);

o

 

window.location.reload();

por:

 

setTimeout('document.location.reload()',0);

Guille existe un problema con la contribución ahora, pasa que...

uno hace click en el boton de facebook, popup de facebook requiere los permisos para la app, uno lo acepta, desaparece el popup, se refresca la pagina de create_account y el problema viene acá... no escribe los datos del usuario en el formulario de registro... pero sin embargo si yo refresco de nuevo la pagina Voila!!! si aparecen los datos, podés suponer a que se debe esto?, un abrazo

Link to comment
Share on other sites

Guille existe un problema con la contribución ahora, pasa que...

uno hace click en el boton de facebook, popup de facebook requiere los permisos para la app, uno lo acepta, desaparece el popup, se refresca la pagina de create_account y el problema viene acá... no escribe los datos del usuario en el formulario de registro... pero sin embargo si yo refresco de nuevo la pagina Voila!!! si aparecen los datos, podés suponer a que se debe esto?, un abrazo

 

Si, me pasaba lo mismo con Internet Explorer y Mozilla Firefox por eso le agregué el setTimeout('document.location.href = "create_account.php"', 0);

 

Cuál navegador usas..?

Edited by gjferrando
Link to comment
Share on other sites

 

Si, me pasaba lo mismo con Internet Explorer y Mozilla Firefox por eso le agregué el setTimeout('document.location.href = "create_account.php"', 0);

 

Cuál navegador usas..?

Justo habia probado con estos dos, Mozilla Firefox y Exlorer, y con Chrome pasa algo raro me lleva a logoff, ahora esta linea va en create account y login ? setTimeout('document.location.href = "create_account.php"', 0); igualmente voy a probar no es el drama esto, y te cuento si me encuentro con algun problema, pero te recomiendo una vez probado subirlo a las contribuciones de oscomerce, sería de gran utilidad para la comunidad...un abrazo y gracias por tu tiempo thumbsup.gif

Link to comment
Share on other sites

Justo habia probado con estos dos, Mozilla Firefox y Exlorer, y con Chrome pasa algo raro me lleva a logoff, ahora esta linea va en create account y login ? setTimeout('document.location.href = "create_account.php"', 0); igualmente voy a probar no es el drama esto, y te cuento si me encuentro con algun problema, pero te recomiendo una vez probado subirlo a las contribuciones de oscomerce, sería de gran utilidad para la comunidad...un abrazo y gracias por tu tiempo thumbsup.gif

Probé y anda de maravilla, todavia no lo probe en mozilla o en crhrome, pero no creo que haya problemas, un abrazo y gracias

Link to comment
Share on other sites

Hey Everyone!

 

I don't have these codes in my files::

 

<tr>
					<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
					<td align="right"><?php echo tep_image_submit('button_login.gif', IMAGE_BUTTON_LOGIN); ?></td>
					<td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
				  </tr>

 

<tr>
	<td class="smallText"><br><?php echo sprintf(TEXT_ORIGIN_LOGIN, tep_href_link(FILENAME_LOGIN, tep_get_all_get_params(), 'SSL')); ?></td>
  </tr>
  <tr>
	<td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
  </tr>

 


 

I'm going to try adding the code that I'm supposed to add before/after anyway, just to see what happens. Looking forward to an answer! smile.gif Thanks!

 

Have you find a solution for the osc 2.3.1?

And to all others we don't speak spanish....

One amateur made the Arc, 5.000 pro made the Titanic...

Link to comment
Share on other sites

Here is some info of the changes, I did not fix it myself yet, anyone else get it?smile.png

 

http://developers.fa.../blog/post/614/

https://developers.f.../blog/post/525/

 

Btw. Now when I did a resetting, nothing happens when I click the fb.button. The same problem for me now with 2.2 RC2 as you before with OScommerce version 2.3.1

Hi Andreas, if you change the code Its work perfect now

Link to comment
Share on other sites

Has everyone solved problems with the latest FB SDK. I have a problem since December 2011. It looks like when I click the "login with facebook" button logout() is called (i have an alert() there) and the user does log in.

I have already modified fbconnect.php and $fbme variable is OK. I have no idea what is going on.

Osc 2.2.

Edited by kshop
Link to comment
Share on other sites

  • 2 weeks later...

Hello! everything Works now with the new modifications… but the customer cannot log out, everything seems do so, but when hit account or perform an activity in the web page he will be logged in automat, does no matter that his session on facebook itself was finished.

 

Any clue?

I think that was something with

 

On

Find

'cookie' => true,

Change by

'cookie' => false,

 

 

Or

On login.php

Find

<fb:login-button autologoutlink="true"

 

Changing to

<fb:login-button autologoutlink="false"

Link to comment
Share on other sites

Has everyone solved problems with the latest FB SDK. I have a problem since December 2011. It looks like when I click the "login with facebook" button logout() is called (i have an alert() there) and the user does log in.

I have already modified fbconnect.php and $fbme variable is OK. I have no idea what is going on.

Osc 2.2.

I have made my own FB login code, I deleted all the FB javascript and do not use FB SDK anymore. I put a link (fb image button) to the file facebook login file in the login.php and in create_account.php. It's not perfect, but it works. The facebook login file is as follows:

<?php
//Facebook Connect

require('includes/application_top.php');
define('FILENAME_DO_FBLOGIN','dofblogin.php');//this file
// If user is logged in and session is valid.
if(!isset($_GET["code"]))
{
   $_SESSION['state'] = md5(uniqid(rand(), TRUE)); //CSRF protection
 $url="https://graph.facebook.com/oauth/authorize?client_id=".$fbconfig['appid' ]."&redirect_uri=".tep_href_link(FILENAME_DO_FBLOGIN)."&state="
   . $_SESSION['state'];
 header("location:".$url);
  exit();
}

 if(isset($_GET["code"]))
{
   if($_REQUEST['state'] == $_SESSION['state']) {
 $token_url ="https://graph.facebook.com/oauth/access_token?client_id="
  . $fbconfig['appid' ] . "&redirect_uri=" . tep_href_link(FILENAME_DO_FBLOGIN)
  . "&client_secret=" . $fbconfig['secret']
  . "&code=" . $_GET['code'];

   $access_token = file_get_contents($token_url);
   $_SESSION["access_token"]=$access_token;
  //$_SESSION["steps_facebook"]="authorized";


 $graph_url = "https://graph.facebook.com/me?" .$_SESSION["access_token"];
 $results = json_decode(file_get_contents($graph_url));


if(isset($results->id))
{   //user is logged in into FB
  $fb_customer_query = tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_email_address = '" . $results->email . "'");
  $fb_customer_check = tep_db_num_rows($fb_customer_query);

 if($fb_customer_check <= 0){
    //check for id, email may not be available in case the user has changed FB privacy settings
    $fb_customer_query = tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where fb_user_id = '" . $results->id . "'");  
    $fb_customer_check = tep_db_num_rows($fb_customer_query);
  }
  // if user is logged in, set current user's login FB login (merge)
  if (($fb_customer_check <= 0) and (!empty($_SESSION['customer_id']))){
    $fb_customer_query = tep_db_query("select customers_id, customers_firstname, customers_password, customers_email_address, customers_default_address_id from " . TABLE_CUSTOMERS . " where customers_id = '" . (int)$_SESSION['customer_id'] . "'");  
    $fb_customer_check = tep_db_num_rows($fb_customer_query);
  }
  if ($fb_customer_check > 0){
    if (SESSION_RECREATE == 'True') {
	  tep_session_recreate();
    }

  $fb_customer = tep_db_fetch_array($fb_customer_query);

  $fb_country_query = tep_db_query("select entry_country_id, entry_zone_id from " . TABLE_ADDRESS_BOOK . " where customers_id = '" . (int)$fb_customer['customers_id'] . "' and address_book_id = '" . (int)$fb_customer['customers_default_address_id'] . "'");
   $fb_country = tep_db_fetch_array($fb_country_query);
  $customer_default_address_id = $fb_customer['customers_default_address_id'];
    global  $customer_first_name;
  $customer_first_name = $fb_customer['customers_firstname'];
  $customer_country_id = $fb_country['entry_country_id'];
  $customer_zone_id = $fb_country['entry_zone_id'];
  $_SESSION['customer_id']=$fb_customer['customers_id'];
    $_SESSION['customer_default_address_id']=$customer_default_address_id;
    $_SESSION['customer_first_name']=$customer_first_name;
    $_SESSION['customer_country_id']=$customer_country_id;
    $_SESSION['customer_zone_id']=$customer_zone_id;

    tep_db_query("update " . TABLE_CUSTOMERS . " set fb_user_id = " . $results->id . " where customers_id = '" . (int)$fb_customer['customers_id']. "'");
  tep_db_query("update " . TABLE_CUSTOMERS_INFO . " set customers_info_date_of_last_logon = now(), customers_info_number_of_logons = customers_info_number_of_logons+1 where customers_info_id = '" . (int)$fb_customer['customers_id'] . "'");


  //restore cart contents
  //$cart->restore_contents();

	 if (sizeof($navigation->snapshot) > 0) {
	   $origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
	    $navigation->clear_snapshot();
	   tep_redirect($origin_href);
	 } else {
	  tep_redirect(tep_href_link(FILENAME_DEFAULT));
	 }
 }else{
	  //fb user not found in customers table
	  $account=array();
	  $account['customers_nickname']=$results->first_name;
	  $account['customers_firstname']=$results->first_name;
	  $account['customers_lastname']=$results->last_name;
	  /*if (isset($results->gender)){
	    if ($results->gender=='female'){
		  $account['customers_gender']='f';
	    } else {
		  $account['customers_gender']='m';
	    }
	  } else {
	    $account['customers_gender']='m';
	  }
	  */
	  if (isset($results->email)) {
	  $account['customers_email_address']=$results->email;
	  } else {
	    $account['customers_email_address']=tep_create_random_value(10).'@[member='unknown'].addr';
	  }
	  $newpass = tep_create_random_value(8);
	  $crypted_password = tep_encrypt_password($newpass);
	  $account['customers_password']=$crypted_password;
	  $account['fb_user_id']=$results->id;
	  $account['customers_default_address_id']=1;

	  tep_db_perform(TABLE_CUSTOMERS,$account);
	  $fb_customer_query = tep_db_query("select customers_id from " . TABLE_CUSTOMERS . " where fb_user_id = '" . $results->id . "'");  
	  $fb_customer = tep_db_fetch_array($fb_customer_query);
	  $_SESSION['customer_id']=$fb_customer['customers_id'];
	  $_SESSION['customer_default_address_id']=1;

	  tep_redirect(tep_href_link(FILENAME_ACCOUNT_EDIT));//account_edit

  }
}//results->id

} else {
   echo("The state does not match. You may be a victim of CSRF.");
 }
 }//code

 require(DIR_WS_INCLUDES . 'application_bottom.php');
?>

Link to comment
Share on other sites

I have made my own FB login code, I deleted all the FB javascript and do not use FB SDK anymore. I put a link (fb image button) to the file facebook login file in the login.php and in create_account.php. It's not perfect, but it works. The facebook login file is as follows:

 

 

hello.. where did you place the code???

Link to comment
Share on other sites

hello.. where did you place the code???

The code above is in a separate file "dofblogin.php". In the login.php there is following code:

	  <tr>
		<td width="50%" align="right" valign="top"><?php echo '<a href="' . tep_href_link(FILENAME_CREATE_ACCOUNT, '', 'SSL') . '">' . tep_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a>'; ?></td>
		<td width="50%" align="right" valign="top"><?php echo tep_image_submit('button_login.gif', IMAGE_BUTTON_LOGIN); ?></td>
	  </tr>
	  <tr>
<td>
</td>
<td width="50%" align="right" valign="top">
<?php
echo '<a href="' . tep_href_link(FILENAME_DO_FBLOGIN, '', 'SSL') . '">' . tep_image_button('button_fb_login.png', IMAGE_BUTTON_LOGIN) . '</a>';
?>
</td>
</tr>

create_account.php:

<!-- body_text //-->
<td width="100%" valign="top"><?php echo tep_draw_form('account_edit', tep_href_link(FILENAME_CREATE_ACCOUNT_PROCESS, '', 'SSL'), 'post', 'onSubmit="return check_form();"') . tep_draw_hidden_field('action', 'process'); ?><table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
	<td><table border="0" width="100%" cellspacing="0" cellpadding="0">
	  <tr>
		<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
		<td class="pageHeading" align="right"><?php //echo tep_image(DIR_WS_IMAGES . 'table_background_account.gif', HEADING_TITLE, HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
	  </tr>
	</table></td>
  </tr>
<tr>
 <td>
 <?php
 echo '<a href="' . tep_href_link(FILENAME_DO_FBLOGIN, '', 'SSL') . '">' . tep_image_button('button_fb_login.png', IMAGE_BUTTON_LOGIN) . '</a>';
 ?>
 </td>
</tr>

the definition define('FILENAME_DO_FBLOGIN','dofblogin.php'); should be moved to includes/filenames.php

$fbconfig['secret'], $fbconfig['appid' ] could be placed in the includes/config.php and replaced by define().

You should uncomment the line

//$cart->restore_contents();

 

My osc 2.2 is very heavily modified, however I have posted the entire dofblogin.php file above, so it should work with no problems.

Edited by kshop
Link to comment
Share on other sites

By the way it seems google will abandon its google friend connect very soon, however the code to use google account for logging in should be almost identical the one above if I am right. I had found and example of multi login (google, fb, yahoo, twitter...) somewhere on the internet (code.google.com ???). I cannot find it now when I need :-(

Edited by kshop
Link to comment
Share on other sites

By the way it seems google will abandon its google friend connect very soon, however the code to use google account for logging in should be almost identical the one above if I am right. I had found and example of multi login (google, fb, yahoo, twitter...) somewhere on the internet (code.google.com ???). I cannot find it now when I need :-(

openid????

Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...