Permalink
Browse files

Removed demo controllers, they will be imported into the user guide f…

…or the module
  • Loading branch information...
1 parent 206c200 commit 5b49c016785f88f03a41830ac02bdb6869335414 @shadowhand shadowhand committed Jul 4, 2010
Showing with 0 additions and 134 deletions.
  1. +0 −75 classes/controller/oauth.php
  2. +0 −26 classes/controller/oauth/google.php
  3. +0 −33 classes/controller/oauth/twitter.php
@@ -1,75 +0,0 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-
-abstract class Controller_OAuth extends Controller {
-
- protected $provider;
-
- protected $consumer;
-
- protected $token;
-
- public function before()
- {
- parent::before();
-
- // Load the configuration for this provider
- $config = Kohana::config("oauth.{$this->provider}");
-
- // Create an consumer from the config
- $this->consumer = OAuth_Consumer::factory($config);
-
- // Load the provider
- $this->provider = OAuth_Provider::factory($this->provider);
-
- if ($token = Cookie::get('oauth_token'))
- {
- // Get the token from storage
- $this->token = unserialize($token);
- }
- }
-
- public function action_login()
- {
- // We will need a callback URL for the user to return to
- $callback = URL::site($this->request->uri(array('action' => 'complete')), Request::$protocol);
-
- // Add the callback URL to the consumer
- $this->consumer->callback($callback);
-
- // Get a request token for the consumer
- $token = $this->provider->request_token($this->consumer);
-
- // Store the token
- Cookie::set('oauth_token', serialize($token));
-
- // Redirect to the twitter login page
- $this->request->redirect($this->provider->authorize_url($token));
- }
-
- public function action_complete()
- {
- if ($this->token AND $this->token->token !== Arr::get($_REQUEST, 'oauth_token'))
- {
- // Delete the token, it is not valid
- Cookie::delete('oauth_token');
-
- // Send the user back to the beginning
- $this->request->redirect($this->request->uri(array('action' => 'index')));
- }
-
- // Get the verifier
- $verifier = Arr::get($_REQUEST, 'oauth_verifier');
-
- // Store the verifier in the token
- $this->token->verifier($verifier);
-
- // Exchange the request token for an access token
- $token = $this->provider->access_token($this->consumer, $this->token);
-
- // Store the token
- Cookie::set('oauth_token', serialize($token));
-
- $this->request->redirect($this->request->uri(array('action' => FALSE)));
- }
-
-} // End OAuth
@@ -1,26 +0,0 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-
-class Controller_OAuth_Google extends Controller_OAuth {
-
- protected $provider = 'google';
-
- public function action_index()
- {
- if ($this->token AND $this->token->name === 'access')
- {
- $this->request->response = Request::factory($this->request->uri(array('action' => 'profile')))->execute();
- }
- else
- {
- $this->request->response = HTML::anchor($this->request->uri(array('action' => 'login')), 'Login with Google');
- }
- }
-
- public function action_profile()
- {
- $response = $this->provider->user_profile($this->consumer, $this->token);
-
- echo Kohana::debug(json_decode((string) $response));
- }
-
-} // End OAuth_Twitter
@@ -1,33 +0,0 @@
-<?php defined('SYSPATH') or die('No direct script access.');
-
-class Controller_OAuth_Twitter extends Controller_OAuth {
-
- protected $provider = 'twitter';
-
- public function action_index()
- {
- if ($this->token AND $this->token->name === 'access')
- {
- $this->request->response = Request::factory($this->request->uri(array('action' => 'tweet')))->execute();
- }
- else
- {
- $this->request->response = HTML::anchor($this->request->uri(array('action' => 'login')), 'Login with Twitter');
- }
- }
-
- public function action_tweet()
- {
- $this->request->response = View::factory('oauth/twitter/tweet')
- ->bind('response', $response)
- ->bind('tweet', $tweet);
-
- if ($tweet = Arr::get($_POST, 'tweet'))
- {
- $response = $this->provider->status_update($this->consumer, $this->token, $tweet);
-
- $response = Kohana::debug(json_decode($response));
- }
- }
-
-} // End OAuth_Twitter

0 comments on commit 5b49c01

Please sign in to comment.