I downloaded hybrid auth version 2.1.2 and tried setting it up by following these instructions.
http://www.yiiframework.com/wiki/459/integrating-hybridauth-directly-into-yii-without-an-extension/
But when I click on this link on my login page
<a href="login?provider=facebook">facebook</a>
all it does it redirects to this link. And I don't get any facebook popup whats so ever.
http://localhost/dev/?hauth.start=Facebook&hauth.time=1387565904
In my site controller I edited my actionLogin() to this and added actionSocialLogin() too. Any idea why this doesn't work?
/**
* Displays the login page
*/
public function actionLogin()
{
if (!isset($_GET['provider']))
{
if(app()->user->isGuest()){
$model = new LoginForm;
// if it is ajax validation request
if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
echo CActiveForm::validate($model);
app()->end();
}
// collect user input data
if (isset($_POST['LoginForm'])) {
$model->attributes = $_POST['LoginForm'];
// validate user input and redirect to the previous page if valid
if ($model->validate() && $model->login()) {
$user = app()->user->getUser();
User::model()->updateByPk($user->id, array('last_login' => new CDbExpression('NOW()')));
if (isset($_POST['ajax'])) {
echo app()->user->getHomeUrl();
app()->end();
} else {
$this->redirect(app()->user->returnUrl);
}
} else {
if (isset($_POST['ajax'])) {
echo "bad";
app()->end();
} else {
app()->user->setFlash('error', 'Login failed. Please try again.');
}
}
}
// display the login form
$this->render('login', array('model' => $model));
} else {
$this->redirect(array('/user/update', 'id' => app()->user->id));
}
}
else {
try
{
//Yii::import('ext.components.HybridAuthIdentity');
$haComp = new HybridAuthIdentity();
if (!$haComp->validateProviderName($_GET['provider']))
throw new CHttpException ('500', 'Invalid Action. Please try again.');
$haComp->adapter = $haComp->hybridAuth->authenticate($_GET['provider']);
$haComp->userProfile = $haComp->adapter->getUserProfile();
$haComp->login();
$this->redirect('http://localhost/dev/'); //redirect to the user logged in section..
$haComp->processLogin(); //further action based on successful login or re-direct user to the required url
}
catch (Exception $e)
{
//process error message as required or as mentioned in the HybridAuth 'Simple Sign-in script' documentation
$this->redirect('/site/index');
return;
}
}
}
public function actionSocialLogin()
{
//Yii::import('ext.components.HybridAuthIdentity');
$path = Yii::getPathOfAlias('ext.HybridAuth');
require_once $path . '/hybridauth-' . HybridAuthIdentity::VERSION . '/hybridauth/index.php';
}
/**
* Logs out the current user and redirect to homepage.
*/
public function actionLogout() {
app()->user->logout();
$this->redirect(app()->homeUrl);
}
and i have this in my HybridAuthIdentity class
public function login()
{
$this->username = $this->userProfile->email; //CUserIdentity
Yii::app()->user->login($this, 0);
}
public function authenticate()
{
return true;
}
also what do i add to write data into this DB?
`userId` int(11) NOT NULL,
`loginProvider` varchar(50) NOT NULL,
`loginProviderIdentifier` varchar(100) NOT NULL,