Skip to content

A phrails plugin that allows you to connect to twitter via oauth.

Notifications You must be signed in to change notification settings

mediaslave/phrails-twitter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This is a plugin that allows you to use phrails to authenticate with twitter.

Installation

This plugin relies on twitteroauth. It must be cloned in lib/abraham

http://github.com/abraham/twitteroauth/

Setup

There are a couple of items to set up.

Controller

class ApplicationController extends Controller
{
	//You Can change the layout here. 'application' is default.
	//Change to null to have no layout.
	//protected $pr_layout = 'my-cool-layout';

	/**
	 * Setup filters
	 *
	 * @return void
	 * @author Justin Palmer
	 **/
	public function __construct()
	{
		parent::__construct();
		$this->filters()->before('authenticate');
	}

	/**
	 * Authenticate the user so that there is a connection and a user.
	 *
	 * @return void
	 * @author Justin Palmer
	 **/
	public function authenticate()
	{		
		try{
			if($this->params('pr-plugin-twitter-id') === null)
				throw new Exception();
			$this->user = new TwitterUser();

			$r = $this->user->find($this->params('pr-plugin-twitter-id'));

			$this->user->props((array)$r);

			$connection = new PhrailsTwitter($this->user->token, $this->user->secret);

			$this->tuser = $connection->get('account/verify_credentials');
		}
		/*If we can't find the record or there is no session for this user.  Fall out.*/
		catch(RecordNotFoundException $e){$this->reset();}
		catch(Exception $e){$this->reset();}
	}
	/**
	 * undocumented function
	 *
	 * @return void
	 * @author Justin Palmer
	 **/
	private function reset()
	{
		$this->user = null;
		$this->tuser = null;
	}	
}

Routes

$Routes->add('twitter-redirect', '/twitter/redirect', 'Twitter', 'redirect');
$Routes->add('twitter-callback', '/twitter/callback', 'Twitter', 'callback');
$Routes->add('twitter-offline', '/twitter/offline', 'Twitter', 'offline');
$Routes->add('twitter-logout', '/twitter/logout', 'Twitter', 'logout');

About

A phrails plugin that allows you to connect to twitter via oauth.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages