2008-05-27 12:42:19 +01:00
|
|
|
<?php
|
2009-08-10 13:48:50 +01:00
|
|
|
/**
|
|
|
|
* Handler for remote subscription finish callback
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package Laconica
|
|
|
|
* @author Evan Prodromou <evan@controlyourself.ca>
|
|
|
|
* @author Robin Millette <millette@controlyourself.ca>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
|
|
|
* @link http://laconi.ca/
|
|
|
|
*
|
2008-05-27 12:42:19 +01:00
|
|
|
* Laconica - a distributed open-source microblogging tool
|
2009-06-21 00:12:55 +01:00
|
|
|
* Copyright (C) 2008, 2009, Control Yourself, Inc.
|
2008-05-27 12:42:19 +01: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 13:48:50 +01:00
|
|
|
**/
|
2008-05-27 12:42:19 +01:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
if (!defined('LACONICA')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-05-27 12:42:19 +01:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
require_once INSTALLDIR.'/extlib/libomb/service_consumer.php';
|
|
|
|
require_once INSTALLDIR.'/lib/omb.php';
|
2008-05-27 12:42:19 +01:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
/**
|
|
|
|
* Handler for remote subscription finish callback
|
|
|
|
*
|
|
|
|
* When a remote user subscribes a local user, a redirect to this action is
|
|
|
|
* issued after the remote user authorized his service to subscribe.
|
|
|
|
*
|
|
|
|
* @category Action
|
|
|
|
* @package Laconica
|
|
|
|
* @author Evan Prodromou <evan@controlyourself.ca>
|
|
|
|
* @author Robin Millette <millette@controlyourself.ca>
|
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
|
|
|
|
* @link http://laconi.ca/
|
|
|
|
*/
|
2008-12-23 19:49:23 +00:00
|
|
|
class FinishremotesubscribeAction extends Action
|
|
|
|
{
|
2008-07-08 10:51:13 +01:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
/**
|
|
|
|
* Class handler.
|
|
|
|
*
|
|
|
|
* @param array $args query arguments
|
|
|
|
*
|
|
|
|
* @return nothing
|
|
|
|
*
|
|
|
|
**/
|
2008-12-23 19:33:23 +00:00
|
|
|
function handle($args)
|
|
|
|
{
|
2008-12-23 19:19:07 +00:00
|
|
|
parent::handle($args);
|
2008-05-27 12:42:19 +01:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
/* Restore session data. RemotesubscribeAction should have stored
|
|
|
|
this entry. */
|
|
|
|
$service = unserialize($_SESSION['oauth_authorization_request']);
|
2008-12-23 19:19:07 +00:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
if (!$service) {
|
2009-01-15 23:03:38 +00:00
|
|
|
$this->clientError(_('Not expecting this response!'));
|
2008-12-23 19:19:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
common_debug('stored request: '. print_r($service, true), __FILE__);
|
2008-07-08 10:51:13 +01:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
/* Create user objects for both users. Do it early for request
|
|
|
|
validation. */
|
|
|
|
$listenee = $service->getListeneeURI();
|
|
|
|
$user = User::staticGet('uri', $listenee);
|
2008-12-23 19:19:07 +00:00
|
|
|
|
|
|
|
if (!$user) {
|
2009-01-15 23:03:38 +00:00
|
|
|
$this->clientError(_('User being listened to doesn\'t exist.'));
|
2008-12-23 19:19:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
$other = User::staticGet('uri', $service->getListenerURI());
|
2008-12-23 19:19:07 +00:00
|
|
|
|
|
|
|
if ($other) {
|
2009-01-15 23:03:38 +00:00
|
|
|
$this->clientError(_('You can use the local subscription!'));
|
2008-12-23 19:19:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
/* Perform the handling itself via libomb. */
|
|
|
|
try {
|
|
|
|
$service->finishAuthorization($listenee);
|
|
|
|
} catch (OAuthException $e) {
|
|
|
|
if ($e->getMessage() == 'The authorized token does not equal the ' .
|
|
|
|
'submitted token.') {
|
|
|
|
$this->clientError(_('Not authorized.'));
|
2008-12-23 19:19:07 +00:00
|
|
|
return;
|
2009-08-10 13:48:50 +01:00
|
|
|
} else {
|
|
|
|
$this->clientError(_('Couldn\'t convert request token to ' .
|
|
|
|
'access token.'));
|
2008-12-23 19:19:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-08-10 13:48:50 +01:00
|
|
|
} catch (OMB_RemoteServiceException $e) {
|
|
|
|
$this->clientError(_('Unknown version of OMB protocol.'));
|
|
|
|
return;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
common_debug('Got exception ' . print_r($e, true), __FILE__);
|
|
|
|
$this->clientError($e->getMessage());
|
2008-12-08 03:15:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
/* The service URLs are not accessible from datastore, so setting them
|
|
|
|
after insertion of the profile. */
|
|
|
|
$remote = Remote_profile::staticGet('uri', $service->getListenerURI());
|
2008-12-15 13:48:24 +00:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
$orig_remote = clone($remote);
|
2008-12-15 13:48:24 +00:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
$remote->postnoticeurl =
|
|
|
|
$service->getServiceURI(OMB_ENDPOINT_POSTNOTICE);
|
|
|
|
$remote->updateprofileurl =
|
|
|
|
$service->getServiceURI(OMB_ENDPOINT_UPDATEPROFILE);
|
2008-12-15 13:48:24 +00:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
if (!$remote->update($orig_remote)) {
|
|
|
|
$this->serverError(_('Error updating remote profile'));
|
|
|
|
return;
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-05-27 12:42:19 +01:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
/* Clear the session data. */
|
2008-12-23 19:19:07 +00:00
|
|
|
unset($_SESSION['oauth_authorization_request']);
|
2008-07-08 10:51:13 +01:00
|
|
|
|
2009-08-10 13:48:50 +01:00
|
|
|
/* If we show subscriptions in reverse chronological order, the new one
|
|
|
|
should show up close to the top of the page. */
|
2008-12-23 19:19:07 +00:00
|
|
|
common_redirect(common_local_url('subscribers', array('nickname' =>
|
2009-04-01 20:30:59 +01:00
|
|
|
$user->nickname)),
|
|
|
|
303);
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-09-04 07:55:04 +01:00
|
|
|
}
|