static function getByUserID($user_id, $service)
{
if (empty($user_id) || empty($service)) {
- return null;
+ throw new ServerException('Empty user_id or service for Foreign_link::getByUserID');
}
$flink = new Foreign_link();
-
$flink->service = $service;
$flink->user_id = $user_id;
$flink->limit(1);
- $result = $flink->find(true);
+ if (!$flink->find(true)) {
+ throw new NoResultException($flink);
+ }
- return empty($result) ? null : $flink;
+ return $flink;
}
static function getByForeignID($foreign_id, $service)
{
if (empty($foreign_id) || empty($service)) {
- return null;
- } else {
- $flink = new Foreign_link();
- $flink->service = $service;
- $flink->foreign_id = $foreign_id;
- $flink->limit(1);
+ throw new ServerException('Empty foreign_id or service for Foreign_link::getByForeignID');
+ }
- $result = $flink->find(true);
+ $flink = new Foreign_link();
+ $flink->service = $service;
+ $flink->foreign_id = $foreign_id;
+ $flink->limit(1);
- return empty($result) ? null : $flink;
+ if (!$flink->find(true)) {
+ throw new NoResultException($flink);
}
+
+ return $flink;
}
function set_flags($noticesend, $noticerecv, $replysync, $friendsync)
if (!defined('GNUSOCIAL')) { exit(1); }
require_once dirname(__DIR__) . '/twitter.php';
+require_once INSTALLDIR . '/lib/oauthclient.php';
/**
* Class for doing OAuth authentication against Twitter
}
}
}
-
- // $this->oauth_token is only populated once Twitter authorizes our
- // request token. If it's empty we're at the beginning of the auth
- // process
- if (empty($this->oauth_token)) {
- // authorizeRequestToken either throws an exception or redirects
- $this->authorizeRequestToken();
- } else {
- $this->saveAccessToken();
- }
}
protected function doPost()
{
try {
// Get a new request token and authorize it
-
$client = new TwitterOAuthClient();
$req_tok = $client->getTwitterRequestToken();
// Sock the request token away in the session temporarily
-
$_SESSION['twitter_request_token'] = $req_tok->key;
$_SESSION['twitter_request_token_secret'] = $req_tok->secret;
$twitter_user = null;
try {
-
- $client = new TwitterOAuthClient($_SESSION['twitter_request_token'],
- $_SESSION['twitter_request_token_secret']);
+ $client = new TwitterOAuthClient($_SESSION['twitter_request_token'], $_SESSION['twitter_request_token_secret']);
// Exchange the request token for an access token
-
$atok = $client->getTwitterAccessToken($this->verifier);
// Test the access token and get the user's Twitter info
-
$client = new TwitterOAuthClient($atok->key, $atok->secret);
$twitter_user = $client->verifyCredentials();
$e->getMessage()
);
common_log(LOG_INFO, 'Twitter bridge - ' . $msg);
- $this->serverError(
- // TRANS: Server error displayed when linking to a Twitter account fails.
- _m('Could not link your Twitter account.')
- );
+ // TRANS: Server error displayed when linking to a Twitter account fails.
+ throw new ServerException(_m('Could not link your Twitter account.'));
}
- if (common_logged_in()) {
+ if ($this->scoped instanceof Profile) {
// Save the access token and Twitter user info
$this->saveForeignLink($this->scoped->getID(), $twitter_user->id, $atok);
$this->tw_fields = array("screen_name" => $twitter_user->screen_name,
"fullname" => $twitter_user->name);
$this->access_token = $atok;
- $this->tryLogin();
+ return $this->tryLogin();
}
// Clean up the the mess we made in the session
return _m('Twitter Account Setup');
}
+ public function showPage()
+ {
+ // $this->oauth_token is only populated once Twitter authorizes our
+ // request token. If it's empty we're at the beginning of the auth
+ // process
+ if (empty($this->oauth_token)) {
+ // authorizeRequestToken either throws an exception or redirects
+ $this->authorizeRequestToken();
+ } else {
+ $this->saveAccessToken();
+ }
+
+ parent::showPage();
+ }
+
/**
* @fixme much of this duplicates core code, which is very fragile.
* Should probably be replaced with an extensible mini version of
*/
function showContent()
{
- if (!empty($this->message_text)) {
- $this->element('p', null, $this->message);
- return;
- }
-
$this->elementStart('form', array('method' => 'post',
'id' => 'form_settings_twitter_connect',
'class' => 'form_settings',
$this->hidden('token', common_session_token());
// Don't allow new account creation if site is flagged as invite only
- if (common_config('site', 'inviteonly') == false) {
+ if (common_config('site', 'inviteonly') == false) {
$this->elementStart('fieldset');
$this->element('legend', null,
// TRANS: Fieldset legend.
return '';
}
- function message($msg)
- {
- $this->message_text = $msg;
- $this->showPage();
- }
-
function createNewUser()
{
if (!Event::handle('StartRegistrationTry', array($this))) {
common_real_login(true);
$this->goHome($user->nickname);
}
-
- } else {
-
- common_debug('TwitterBridge Plugin - ' .
- "No flink found for twuid: $this->twuid - new user");
-
- $this->showForm(null, $this->bestNewNickname());
}
+ common_debug('TwitterBridge Plugin - ' .
+ "No flink found for twuid: $this->twuid - new user");
+
+ return;
+ throw new ServerException(_m('No foreign link found for Twitter user'));
}
function goHome($nickname)