Reputation: 465
I am trying to get a log in with facebook working on Yii site using Crugeconnector. http://yiiframeworkenespanol.org/wiki/index.php?title=CrugeConnector . It is in Spanish but Google Translate works well with it.
Anyway my problem at the moment is that the successfunction is not being called and I have no idea why. The following code is in my main.php under components array.
'crugeconnector'=>array(
'class'=>'ext.crugeconnector.CrugeConnector',
'hostcontrollername'=>'site',
'onSuccess'=>array('site/loginsuccess'),
'onError'=>array('site/loginerror'),
'clients'=>array(
'facebook'=>array(
// required by crugeconnector:
'enabled'=>true,
'class'=>'ext.crugeconnector.clients.Facebook',
'callback'=>'http://smecontracts.ie/6/facebook-callback.php',
// required by remote interface:
'client_id'=>"290200194448698",
'client_secret'=>"0608f1e94db5a3a8b6612af1c61fb25d",
'scope'=>'email, read_stream',
),
The next batch of code is under my site controller.
public function actionLoginSuccess($key){
error_log("In Sitecontroller successful login page", 0);
$loginData = Yii::app()->crugeconnector->getStoredData();
// loginData: remote user information in JSON format.
$info = $loginData;
error_log($info, 0);
$this->renderText('<h1>Welcome!</h1><p>'.$info.'</p> key='.$key);
$this->redirect(Yii::app()->params["GREETINGS_PAGE_LINK"]);
}
The actionLoginSuccess function is never being called. I have calls to the log files that are never being called as can be seen above. Finally the facebook-callback.php looks as follows.
<?php
error_log("In facebook-callback page", 0);
$yii=dirname(__FILE__).'/../yii/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
defined('YII_DEBUG') or define('YII_DEBUG',false);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
$_GET['r'] = '/site/crugeconnector'; // <--using 'site' ?
$_GET['crugekey'] = 'facebook'; // <--facebook key
$_GET['crugemode'] = 'callback';
require_once($yii);
Yii::createWebApplication($config)->run();
?>
This page is being called. The error_log above does get called however the only thing happening is that the user is being brought back to the main welcome page on my website which was set the in facebook app creation. I have no idea where to go from here, I need to retrieve the information from facebook and create an account using Yii, which would be done fairly easily if the login success function worked but there lies my problem.
Thanks for any help.
Upvotes: 1
Views: 387
Reputation: 558
im the author on this yii extension. the problem is not the callback itself. the problem is your own access rules. try making that actions required by the extension to be user-free, in other words, those actions should be out of any access rule. In your yii applicacion tell the system that this action are enabled to be executed by a anonymouse user (the * (asterisc) in the access rules).
hope it helps you.
Upvotes: 1
Reputation: 187
I think you put this function in site controller and if function exist than put only one line.
public function actions() {
return array(
'crugeconnector' => array('class' => 'CrugeConnectorAction'),
);
}
And for Facebook button use this:
<?php if(Yii::app()->crugeconnector->hasEnabledClients){ ?>
<div class='crugeconnector'>
<span>Use your Facebook or Google account:</span>
<ul>
<?php
$cc = Yii::app()->crugeconnector;
foreach($cc->enabledClients as $key=>$config){
$image = CHtml::image($cc->getClientDefaultImage($key));
echo "<li>".CHtml::link($image,
$cc->getClientLoginUrl($key))."</li>";
}
?>
</ul>
</div>
<?php } ?>
Upvotes: 0