Giter Site home page Giter Site logo

facebookextension4yii's Introduction

Facebook Extension for the Yii Web Framework

Authenticate a Facebook user within a Yii Web Application and consequently use the Facebook API. This extension is based on PHP-SDK.

Developed by @ielshareef.

Installation

Clone the repo onto your machine Copy it to the protected/extensions folder in your Yii Web Application root Rename the folder to "facebook" Update the config file:

'import'=>array(
	'application.models.*',
	'application.components.*',
	'ext.facebook.*',
	'ext.facebook.lib.*',
)

Add an action to your Controller (default is SiteController.php under protected/controllers)

// Facebook log in
public function actionFacebooklogin() {
	Yii::import('ext.facebook.*');
    $ui = new FacebookUserIdentity(YOUR APP ID, YOUR APP SECRET);
	if ($ui->authenticate()) {
        $user=Yii::app()->user;
        $user->login($ui);
    	$this->redirect($user->returnUrl);
 	} else {
    	throw new CHttpException(401, $ui->error);
	}
}

The default actionLogout() can handle all types of authentication logouts, so you don't need a new one

In your layout's main.php file, edit the menu to all the Facebook login:

<?php $this->widget('zii.widgets.CMenu',array(
	'items'=>array(
		....
		array('label'=>'Sign in with Twitter', 'url'=>array('/site/twitterlogin'), 'visible'=>Yii::app()->user->isGuest),
		array('label'=>'Sign in with Facebook', 'url'=>array('/site/facebooklogin'), 'visible'=>Yii::app()->user->isGuest),
		array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
		array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
	),
)); ?>

You are all good to go!

Authenticated User Data

Once the user is authenticated, his/her information will be stored in Yii::app()->session['facebook_user'].

facebookextension4yii's People

Contributors

ielshareef avatar

Stargazers

FatFrank avatar  avatar buggy09 avatar Rodrigo Z. Armond avatar Sonny Lazuardi avatar Thørsten Køhpeiss avatar  avatar Martin Samami ッ avatar Milan Zivkovic avatar Sarah Lewis avatar Vinzenz Weber avatar Kenny Meyer avatar Marat avatar

Watchers

 avatar Willian Viana avatar FatFrank avatar

facebookextension4yii's Issues

error

hai im try to use your ' FacebookExtension4Yii ' .but when i click on the link ,it redirect to facebook authdialoge(loginurl),but it shows an error.(An error occurred. Please try again later.).please help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.