Ciao a tutti,
Sto facendo un sito con typo3 e ho bisogno di integrare il login facebook nel mio sito in modo che quando effettuo il login su facebook sia effettuato il login anche sul mio sito.
Questo è il codice attuale :
require 'typo3conf/ext/fbconnect/sdk/facebook.php';
$facebook = new Facebook(array(
'appId' => 'MY APP ID',
'secret' => 'MY SECRET APP ID ',
));
$fbUserId = $facebook->getUser();
if ($fbUserId) {
$content .= $fbUserId . '
';
$userInfo = $facebook->api('/' . $fbUserId);
$resLoginTest = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
'uid, password', // SELECT ...
'fe_users' , // FROM (databasename)...
'email = ' . $userInfo['email'] // WHERE...
);
$userIdTest = '';
while($rowloginTest = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($resLoginTest)){
$userIdTest = $rowloginTest['uid'];
$password = $rowloginTest['password'];
//echo $rowloginTest['email'];
}
if($userIdTest != ''){
// User is already in moms registered --> login:
$content .= $userIdTest . '
';
$loginData = array(
'username' => $userInfo['username'],
'uident_text' => $password,
'status' => 'login'
);
$GLOBALS['TSFE']->fe_user->checkPid = ''; //do not use a particular pid
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord($info['db_user'], $loginData['username']);
$GLOBALS['TSFE']->fe_user->createUserSession($user);
}else{
$content .= $userInfo['email'] . '
';
// User doesn't exist in moms --> register
$feUserRecord = array (
'username' => $userInfo['username'],
'password' => $userInfo['password'],
'name' => $userInfo['name'],
'first_name' => $userInfo['first_name'],
'last_name' => $userInfo['last_name'],
'email' => $userInfo['email'],
'crdate' => mktime()
);
$res = $GLOBALS['TYPO3_DB']->exec_INSERTquery ('fe_users', $feUserRecord);
}
// echo 'WELCOME '.$userInfo['name'];
//
$content .= 'Welcome '. $userInfo['name'] . ' - ' . $userInfo['username']. ' - ' . $userInfo['email'];
} else {
$content .= '<fb:login-button show-faces="true" scope="email,user_checkins"></fb:login-button>';
}
$content .= '<div id="fb-root"></div>
<script>
// Additional JS functions here
window.fbAsyncInit = function() {
FB.init({
appId : MY APP ID , // App ID
channelUrl : CHANNEL URL // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Additional init code here
};
// Load the SDK Asynchronously
(function(d){
var js, id = facebook-jssdk, ref = d.getElementsByTagName(script)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(script); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>';
Per ora il login a facebook viene effettuato, ma non nel mio sito, come se non dal getUser ricevesse Null ma se ricarico un paio di volta il sito compare stampata la mia id.
Cosa c'è che non va ?
Grazie in anticipo