[EXTENSION] Yet another facebook connect

Hi all.

I was looking for extension "Facebook connect".

Have found a lot of freelance links and one extension - http://www.yiiframework.com/extension/facebook-connect but didn’t like it. So I wrote my own extension with permission check.

Because I can’t submit it to the extensions library I place it here.

Installation

Place files "FBAccount.php" and "facebook.php" to the components directory (application.components, for example). I use it in my admin module (admin.components.facebook.*)

How to use?

Use it in actionLogin action.

An example:




// ... you controller's code goes here ...


	public function actionLogin() {

		if(Yii::app()->user->isGuest)

		{

			$account = new FBAccount(

			  /* APPID */,

			  /* APPSECRET */

			);

			

			// Succefully logged in

			if($account->authenticate()) {

				$allowed = array(

					'1456063890'

				);

				

				// If we need to check permissions

				if($account->isAllowed($allowed)) {

					// User IDs are allowed

					Yii::app()->user->login($account);

				} else {

					// Succefully logged in, but ID is not allowed

					$reason = "You are logged in, but don not have permission to view this page";

				}

			} else {

				// Authentication is unsuccessful

				$reason = "Authentication is unsuccessful";

			}

			

			$this->renderPartial('login', array(

				'reason' => (!empty($reason) ? $reason : 'You are not logged in to view this page'),

				'button' => $account->getLoginButton()

			));

		} else $this->redirect(Yii::app()->user->returnUrl);

	}



I hope you liked it! :)

Can you post a demo please?

BTW… I didn’t understand this “Use it in actionLogin action.”, where I supposed to put that code in?

Thanks.

and how about Login.php

I mind, how about use login-button facebook