2008-05-27 20:42:19 +09:00
|
|
|
<?php
|
2009-08-10 21:48:50 +09:00
|
|
|
/**
|
|
|
|
* Handler for remote subscription finish callback
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* @category Action
|
2009-08-28 03:16:45 +09:00
|
|
|
* @package StatusNet
|
|
|
|
* @author Evan Prodromou <evan@status.net>
|
|
|
|
* @author Robin Millette <millette@status.net>
|
2009-08-10 21:48:50 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
2009-08-28 03:16:45 +09:00
|
|
|
* @link http://status.net/
|
2009-08-10 21:48:50 +09:00
|
|
|
*
|
2009-08-26 07:14:12 +09:00
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
2011-07-16 04:13:57 +09:00
|
|
|
* Copyright (C) 2008-2011, StatusNet, Inc.
|
2008-05-27 20:42:19 +09:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-08-10 21:48:50 +09:00
|
|
|
**/
|
2008-05-27 20:42:19 +09:00
|
|
|
|
2009-08-26 23:41:36 +09:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
2008-05-27 20:42:19 +09:00
|
|
|
|
2011-07-16 04:13:57 +09:00
|
|
|
require_once dirname(__FILE__) . '/../extlib/libomb/service_consumer.php';
|
|
|
|
require_once dirname(__FILE__) . '/../lib/omb.php';
|
2008-05-27 20:42:19 +09:00
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
/**
|
|
|
|
* Handler for remote subscription finish callback
|
|
|
|
*
|
|
|
|
* When a remote user subscribes a local user, a redirect to this action is
|
2010-07-20 11:09:09 +09:00
|
|
|
* issued after the remote user authorized their service to subscribe.
|
2009-08-10 21:48:50 +09:00
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package Laconica
|
2009-09-16 11:28:59 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-08-10 21:48:50 +09:00
|
|
|
* @author Robin Millette <millette@controlyourself.ca>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
|
|
|
* @link http://laconi.ca/
|
|
|
|
*/
|
2008-12-24 04:49:23 +09:00
|
|
|
class FinishremotesubscribeAction extends Action
|
|
|
|
{
|
2009-08-10 21:48:50 +09:00
|
|
|
/**
|
|
|
|
* Class handler.
|
|
|
|
*
|
|
|
|
* @param array $args query arguments
|
|
|
|
*
|
|
|
|
* @return nothing
|
|
|
|
*
|
2011-02-01 00:39:54 +09:00
|
|
|
*/
|
2008-12-24 04:33:23 +09:00
|
|
|
function handle($args)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
2008-05-27 20:42:19 +09:00
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
/* Restore session data. RemotesubscribeAction should have stored
|
|
|
|
this entry. */
|
|
|
|
$service = unserialize($_SESSION['oauth_authorization_request']);
|
2008-12-24 04:19:07 +09:00
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
if (!$service) {
|
2011-02-01 00:39:54 +09:00
|
|
|
// TRANS: Client error displayed when subscribing to a remote profile and an unexpected response is received.
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('Not expecting this response!'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
common_debug('stored request: '. print_r($service, true), __FILE__);
|
2008-07-08 18:51:13 +09:00
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
/* Create user objects for both users. Do it early for request
|
|
|
|
validation. */
|
2013-08-18 20:04:58 +09:00
|
|
|
$user = User::getKV('uri', $service->getListeneeURI());
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
if (!$user) {
|
2011-02-01 00:39:54 +09:00
|
|
|
// TRANS: Client error displayed when subscribing to a remote profile that does not exist.
|
2009-08-21 19:13:24 +09:00
|
|
|
$this->clientError(_('User being listened to does not exist.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$other = User::getKV('uri', $service->getListenerURI());
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
if ($other) {
|
2011-02-01 00:39:54 +09:00
|
|
|
// TRANS: Client error displayed when subscribing to a remote profile that is a local profile.
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('You can use the local subscription!'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$remote = Remote_profile::getKV('uri', $service->getListenerURI());
|
2009-11-26 05:07:19 +09:00
|
|
|
if ($remote) {
|
|
|
|
// Note remote profile may not have been saved yet.
|
|
|
|
// @fixme not convinced this is correct at all!
|
2009-08-21 19:13:24 +09:00
|
|
|
|
2013-08-18 20:04:58 +09:00
|
|
|
$profile = Profile::getKV($remote->id);
|
2009-08-21 19:13:24 +09:00
|
|
|
|
2009-11-26 05:07:19 +09:00
|
|
|
if ($user->hasBlocked($profile)) {
|
2011-02-01 00:39:54 +09:00
|
|
|
// TRANS: Client error displayed when subscribing to a remote profile that is blocked form subscribing to.
|
2009-11-26 05:07:19 +09:00
|
|
|
$this->clientError(_('That user has blocked you from subscribing.'));
|
|
|
|
return;
|
|
|
|
}
|
2009-08-21 19:13:24 +09:00
|
|
|
}
|
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
/* Perform the handling itself via libomb. */
|
|
|
|
try {
|
2009-08-21 19:13:24 +09:00
|
|
|
$service->finishAuthorization();
|
2009-08-10 21:48:50 +09:00
|
|
|
} catch (OAuthException $e) {
|
|
|
|
if ($e->getMessage() == 'The authorized token does not equal the ' .
|
|
|
|
'submitted token.') {
|
2011-02-01 00:39:54 +09:00
|
|
|
// TRANS: Client error displayed when subscribing to a remote profile without providing an authorised token.
|
2009-08-21 19:13:24 +09:00
|
|
|
$this->clientError(_('You are not authorized.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
2009-08-10 21:48:50 +09:00
|
|
|
} else {
|
2011-02-01 00:39:54 +09:00
|
|
|
// TRANS: Client error displayed when subscribing to a remote profile and conversion of the request token to access token fails.
|
2009-08-21 19:13:24 +09:00
|
|
|
$this->clientError(_('Could not convert request token to ' .
|
2009-08-10 21:48:50 +09:00
|
|
|
'access token.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
2009-08-10 21:48:50 +09:00
|
|
|
} catch (OMB_RemoteServiceException $e) {
|
2011-02-01 00:39:54 +09:00
|
|
|
// TRANS: Client error displayed when subscribing to a remote profile fails because of an unsupported version of the OMB protocol.
|
2009-08-21 19:13:24 +09:00
|
|
|
$this->clientError(_('Remote service uses unknown version of ' .
|
|
|
|
'OMB protocol.'));
|
2009-08-10 21:48:50 +09:00
|
|
|
return;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
common_debug('Got exception ' . print_r($e, true), __FILE__);
|
|
|
|
$this->clientError($e->getMessage());
|
2008-12-08 12:15:32 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
/* The service URLs are not accessible from datastore, so setting them
|
|
|
|
after insertion of the profile. */
|
2013-08-18 20:04:58 +09:00
|
|
|
$remote = Remote_profile::getKV('uri', $service->getListenerURI());
|
2009-08-10 21:48:50 +09:00
|
|
|
$orig_remote = clone($remote);
|
2008-12-15 22:48:24 +09:00
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
$remote->postnoticeurl =
|
|
|
|
$service->getServiceURI(OMB_ENDPOINT_POSTNOTICE);
|
|
|
|
$remote->updateprofileurl =
|
|
|
|
$service->getServiceURI(OMB_ENDPOINT_UPDATEPROFILE);
|
2008-12-15 22:48:24 +09:00
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
if (!$remote->update($orig_remote)) {
|
2011-02-01 00:39:54 +09:00
|
|
|
// TRANS: Server error displayed when subscribing to a remote profile fails because the remote profile could not be updated.
|
2010-04-10 07:07:20 +09:00
|
|
|
$this->serverError(_('Error updating remote profile.'));
|
2009-08-10 21:48:50 +09:00
|
|
|
return;
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-05-27 20:42:19 +09:00
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
/* Clear the session data. */
|
2008-12-24 04:19:07 +09:00
|
|
|
unset($_SESSION['oauth_authorization_request']);
|
2008-07-08 18:51:13 +09:00
|
|
|
|
2009-08-10 21:48:50 +09:00
|
|
|
/* If we show subscriptions in reverse chronological order, the new one
|
|
|
|
should show up close to the top of the page. */
|
2008-12-24 04:19:07 +09:00
|
|
|
common_redirect(common_local_url('subscribers', array('nickname' =>
|
2009-04-02 04:30:59 +09:00
|
|
|
$user->nickname)),
|
|
|
|
303);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-09-04 15:55:04 +09:00
|
|
|
}
|