Created
November 17, 2011 13:56
-
-
Save nojimage/1373193 to your computer and use it in GitHub Desktop.
CakePHP-TwimとxAuthの実装例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* for development env | |
*/ | |
class DATABASE_CONFIG { | |
public $default = array( | |
'driver' => 'mysql', | |
'persistent' => false, | |
'host' => 'localhost', | |
'login' => 'user', | |
'password' => 'password', | |
'database' => 'database_name', | |
'encoding' => 'utf8', | |
'prefix' => '', | |
); | |
public $twitter = array( | |
'datasource' => 'Twim.TwimSource', | |
'oauth_consumer_key' => 'YOUR_CONSUMER_KEY', | |
'oauth_consumer_secret' => 'YOUR_CONSUMER_SECRET', | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* @var $this CodeCompletionView */ | |
echo $this->Form->create('User'); | |
echo $this->Form->input('x_auth_username'); | |
echo $this->Form->input('x_auth_password', array('type' => 'password')); | |
echo $this->Form->end(__('Login', true)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* @var $this CodeCompletionView */ | |
echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'tweet'))); | |
echo $this->Form->input('tweet', array('type' => 'textarea')); | |
echo $this->Form->end(__('Tweet', true)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UsersController extends AppController { | |
public $name = 'Users'; | |
public $uses = array(); | |
public $helpers = array('Twim.Twitter'); | |
public function login() { | |
if (!empty($this->data)) { | |
$params = am(array('x_auth_mode' => 'client_auth'), $this->data['User']); | |
$TwimOauth = ClassRegistry::init('Twim.TwimOauth'); | |
/* @var $TwimOauth TwimOauth */ | |
$accessToken = $TwimOauth->getAccessToken($params); | |
$this->Session->write('accessToken', $accessToken); | |
$this->redirect(array('action' => 'tweet')); | |
} | |
} | |
public function tweet() { | |
if (!empty($this->data)) { | |
$TwimStatus = ClassRegistry::init('Twim.TwimStatus'); | |
/* @var $TwimStatus TwimStatus */ | |
$accessToken = $this->Session->read('accessToken'); | |
$TwimStatus->getDataSource()->setToken($accessToken); | |
$this->Session->setFlash(__('tweet now.', true)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Authを使用してなかったり、大幅にはしょってます。