Commit 6cd7a4a4 authored by mmn's avatar mmn

TwitterBridge messing about, Twitter OAuth requires Authorization header now?

https://dev.twitter.com/oauth/reference/post/oauth/request_token says that
the request should be a GET with a specific HTTP header instead of query
string parameters for OAuth?
parent 5933056a
......@@ -124,11 +124,11 @@ class Foreign_link extends Managed_DataObject
$fuser->limit(1);
if ($fuser->find(true)) {
return $fuser;
if (!$fuser->find(true)) {
throw new NoResultException($fuser);
}
return null;
return $fuser;
}
function getUser()
......
......@@ -42,32 +42,33 @@ class Foreign_user extends Managed_DataObject
}
static function getForeignUser($id, $service) {
$fuser = new Foreign_user();
$fuser->id = $id;
$fuser->service = $service;
$fuser->limit(1);
$result = $fuser->find(true);
if (!$fuser->find(true)) {
throw new NoResultException($fuser);
}
return empty($result) ? null : $fuser;
return $fuser;
}
static function getByNickname($nickname, $service)
{
if (empty($nickname) || empty($service)) {
return null;
} else {
$fuser = new Foreign_user();
$fuser->service = $service;
$fuser->nickname = $nickname;
$fuser->limit(1);
throw new ServerException('Empty nickname or service for Foreign_user::getByNickname');
}
$result = $fuser->find(true);
$fuser = new Foreign_user();
$fuser->service = $service;
$fuser->nickname = $nickname;
$fuser->limit(1);
return empty($result) ? null : $fuser;
if (!$fuser->find(true)) {
throw new NoResultException($fuser);
}
return $fuser;
}
}
......@@ -918,12 +918,9 @@ class Facebookclient
static function addFacebookUser($fbuser)
{
// remove any existing, possibly outdated, record
$luser = Foreign_user::getForeignUser($fbuser->id, FACEBOOK_SERVICE);
if (!empty($luser)) {
$result = $luser->delete();
try {
$fuser = Foreign_user::getForeignUser($fbuser->id, FACEBOOK_SERVICE);
$result = $fuser->delete();
if ($result != false) {
common_log(
LOG_INFO,
......@@ -935,6 +932,8 @@ class Facebookclient
__FILE__
);
}
} catch (NoResultException $e) {
// no old foreign users exist for this id
}
$fuser = new Foreign_user();
......
......@@ -26,9 +26,7 @@
* @link http://status.net/
*/
if (!defined('STATUSNET')) {
exit(1);
}
if (!defined('GNUSOCIAL')) { exit(1); }
require_once __DIR__ . '/twitter.php';
......@@ -387,12 +385,11 @@ class TwitterBridgePlugin extends Plugin
{
$n2s = Notice_to_status::getKV('notice_id', $notice->id);
if (!empty($n2s)) {
if ($n2s instanceof Notice_to_status) {
$flink = Foreign_link::getByUserID($notice->profile_id,
TWITTER_SERVICE); // twitter service
$flink = Foreign_link::getByUserID($notice->profile_id, TWITTER_SERVICE); // twitter service
if (empty($flink)) {
if (!$flink instanceof Foreign_link) {
return true;
}
......@@ -424,15 +421,14 @@ class TwitterBridgePlugin extends Plugin
*/
function onEndFavorNotice(Profile $profile, Notice $notice)
{
$flink = Foreign_link::getByUserID($profile->id,
TWITTER_SERVICE); // twitter service
$flink = Foreign_link::getByUserID($profile->getID(), TWITTER_SERVICE); // twitter service
if (empty($flink)) {
if (!$flink instanceof Foreign_link) {
return true;
}
if (!TwitterOAuthClient::isPackedToken($flink->credentials)) {
$this->log(LOG_INFO, "Skipping fave processing for {$profile->id} since link is not OAuth.");
$this->log(LOG_INFO, "Skipping fave processing for {$profile->getID()} since link is not OAuth.");
return true;
}
......
......@@ -28,9 +28,7 @@
* @link http://status.net/
*/
if (!defined('STATUSNET') && !defined('LACONICA')) {
exit(1);
}
if (!defined('GNUSOCIAL')) { exit(1); }
require_once dirname(__DIR__) . '/twitter.php';
......@@ -46,20 +44,8 @@ require_once dirname(__DIR__) . '/twitter.php';
*
* @see SettingsAction
*/
class TwitterloginAction extends Action
class TwitterloginAction extends LoginAction
{
function handle($args)
{
parent::handle($args);
if (common_is_real_login()) {
// TRANS: Client error displayed when trying to log in using Twitter while already logged in to StatusNet.
$this->clientError(_m('Already logged in.'));
}
$this->showPage();
}
function title()
{
// TRANS: Title for login using Twitter page.
......@@ -72,15 +58,6 @@ class TwitterloginAction extends Action
return _m('Login with your Twitter account');
}
function showPageNotice()
{
$instr = $this->getInstructions();
$output = common_markup_to_html($instr);
$this->elementStart('div', 'instructions');
$this->raw($output);
$this->elementEnd('div');
}
function showContent()
{
$this->elementStart('a', array('href' => common_local_url('twitterauthorization',
......
......@@ -111,7 +111,7 @@ class TwitterOAuthClient extends OAuthClient
*
* @return OAuthToken $token the request token
*/
function getRequestToken()
function getTwitterRequestToken()
{
return parent::getRequestToken(
self::$requestTokenURL,
......@@ -142,7 +142,7 @@ class TwitterOAuthClient extends OAuthClient
*
* @return OAuthToken $token the access token
*/
function getAccessToken($verifier = null)
function getTwitterAccessToken($verifier = null)
{
return parent::getAccessToken(
self::$accessTokenURL,
......
......@@ -28,16 +28,17 @@ function add_twitter_user($twitter_id, $screen_name)
// Clear out any bad old foreign_users with the new user's legit URL
// This can happen when users move around or fakester accounts get
// repoed, and things like that.
$luser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
if (!empty($luser)) {
$result = $luser->delete();
try {
$fuser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
$result = $fuser->delete();
if ($result != false) {
common_log(
LOG_INFO,
"Twitter bridge - removed old Twitter user: $screen_name ($twitter_id)."
);
}
} catch (NoResultException $e) {
// no old foreign users exist for this id
}
$fuser = new Foreign_user();
......@@ -49,9 +50,8 @@ function add_twitter_user($twitter_id, $screen_name)
$fuser->created = common_sql_now();
$result = $fuser->insert();
if (empty($result)) {
common_log(LOG_WARNING,
"Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name.");
if ($result === false) {
common_log(LOG_WARNING, "Twitter bridge - failed to add new Twitter user: $twitter_id - $screen_name.");
common_log_db_error($fuser, 'INSERT', __FILE__);
} else {
common_log(LOG_INFO,
......@@ -66,11 +66,10 @@ function save_twitter_user($twitter_id, $screen_name)
{
// Check to see whether the Twitter user is already in the system,
// and update its screen name and uri if so.
$fuser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
try {
$fuser = Foreign_user::getForeignUser($twitter_id, TWITTER_SERVICE);
if (!empty($fuser)) {
// Delete old record if Twitter user changed screen name
if ($fuser->nickname != $screen_name) {
$oldname = $fuser->nickname;
$fuser->delete();
......@@ -80,11 +79,13 @@ function save_twitter_user($twitter_id, $screen_name)
$screen_name,
$oldname));
}
} else {
} catch (NoResultException $e) {
// No old users exist for this id
// Kill any old, invalid records for this screen name
$fuser = Foreign_user::getByNickname($screen_name, TWITTER_SERVICE);
if (!empty($fuser)) {
// XXX: Is this really only supposed to be run if the above getForeignUser fails?
try {
$fuser = Foreign_user::getByNickname($screen_name, TWITTER_SERVICE);
$fuser->delete();
common_log(
LOG_INFO,
......@@ -95,6 +96,8 @@ function save_twitter_user($twitter_id, $screen_name)
$fuser->id
)
);
} catch (NoResultException $e) {
// No old users exist for this screen_name
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment