Giter VIP home page Giter VIP logo

crugeconnector's Introduction

CrugeConnector

Remote Login using Google, Facebook and others (extensible) for Yii Framework.

author:

Christian Salazar H. [email protected]

licence:

http://opensource.org/licenses/bsd-license.php

full wiki, documentation & installation:

http://yiiframeworkenespanol.org/wiki/index.php?title=CrugeConnector

(Source Code & Comments in English)

Screen Shot:

CrugeConnector Screen Capture

Quick Setup:

1- in protected/config/main.php, under 'imports' key:

'application.extensions.crugeconnector.*',

2- in protected/config/main.php, under 'components' key:

	'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://yoursite.com/app/facebook-callback.php',
				// required by remote interface:
				'client_id'=>"yourappid",
				'client_secret'=>"yoursecretid",
				'scope'=>'email, read_stream',
			),	
			'google'=>array(
				// required by crugeconnector:
				'enabled'=>true,
				'class'=>'ext.crugeconnector.clients.Google',
				'callback'=>'http://yoursite.com/app1/google-callback.php',
				// required by remote interface:
				'hostname'=>'yoursite.com',
				'identity'=>'https://www.google.com/accounts/o8/id',
				'scope'=>array('contact/email'),
			),
			'tester'=>array(
				// required by crugeconnector:
				'enabled'=>false,
				'class'=>'ext.crugeconnector.clients.Tester',
				// required by remote interface:
			),
		),
	),

3- in protected/controllers/siteContoller.php (by default)

	public function actions()
	{
		return array(
			'captcha'=>array(
				'class'=>'CCaptchaAction',
				'backColor'=>0xFFFFFF,
			),
			'page'=>array(
				'class'=>'CViewAction',
			),
			// ADD THIS:
			'crugeconnector'=>array('class'=>'CrugeConnectorAction'),
		);
	}

	// and this actions:

	public function actionLoginSuccess($key){

		$loginData = Yii::app()->crugeconnector->getStoredData();
		// loginData: remote user information in JSON format.

		$info = $loginData;
		$this->renderText('<h1>Welcome!</h1><p>'.$info.'</p> key='.$key);
	}

	public function actionLoginError($key, $message=''){
		$this->renderText('<h1>Login Error</h1><p>'.$message.'</p> key='.$key);
	}

4- insert the component into your protected/views/site/login view:

	<?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 } ?>

5- create a callback (one for google and another one for facebook)

<?php
// SAVE AS yourapp/facebook-callback.php, review your config main settings, must match.

// SELECT URL MODE.

// USE THIS WHEN URL MANAGER IS ACTIVATED, must match your URL rules: 
// DONT FORGET "?" at the end.
// $url = "index.php/site/crugeconnector/crugekey/facebook/crugemode/callback?";

// USE THIS WHEN YOU ARE NOT USING URL MANAGER:
// 
$url = "index.php?r=/site/crugeconnector&crugekey=facebook&crugemode=callback";

// common code:
foreach($_GET as $key=>$val)
	$url .= "&".$key."=".urlencode($val);
header("Location: ".$url);

crugeconnector's People

Contributors

christiansalazar avatar

Stargazers

Franchesco Romero avatar Vincent avatar

Watchers

Imad Mohammad Mujeeb avatar Vincent avatar

Forkers

netcafehanh

crugeconnector's Issues

Configuration issues

I am still having issues trying to make this work (got CSRF errors). However I've noticed that crugeconnector expects "pretty URL" to be off.

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.