2008-06-18 15:53:20 +09:00
|
|
|
<?php
|
2009-01-17 05:25:46 +09:00
|
|
|
/**
|
2009-08-26 07:12:20 +09:00
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
2008-06-18 15:53:20 +09:00
|
|
|
*
|
2009-01-17 05:25:46 +09:00
|
|
|
* Complete adding an OpenID
|
|
|
|
*
|
|
|
|
* PHP version 5
|
|
|
|
*
|
|
|
|
* LICENCE: This program is free software: you can redistribute it and/or modify
|
2008-06-18 15:53:20 +09:00
|
|
|
* 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-01-17 05:25:46 +09:00
|
|
|
*
|
|
|
|
* @category Settings
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-08-26 07:12:20 +09:00
|
|
|
* @copyright 2008-2009 StatusNet, Inc.
|
2009-01-17 05:25:46 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2008-06-18 15:53:20 +09:00
|
|
|
*/
|
|
|
|
|
2009-08-26 23:41:36 +09:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) {
|
2009-01-17 05:25:46 +09:00
|
|
|
exit(1);
|
|
|
|
}
|
2008-06-18 15:53:20 +09:00
|
|
|
|
2009-08-04 20:45:16 +09:00
|
|
|
require_once INSTALLDIR.'/plugins/OpenID/openid.php';
|
2009-01-17 05:25:46 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Complete adding an OpenID
|
|
|
|
*
|
|
|
|
* Handle the return from an OpenID verification
|
|
|
|
*
|
|
|
|
* @category Settings
|
2009-08-26 07:12:20 +09:00
|
|
|
* @package StatusNet
|
2009-08-26 07:19:04 +09:00
|
|
|
* @author Evan Prodromou <evan@status.net>
|
2009-01-17 05:25:46 +09:00
|
|
|
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
|
2009-08-26 07:16:46 +09:00
|
|
|
* @link http://status.net/
|
2009-01-17 05:25:46 +09:00
|
|
|
*/
|
2008-06-18 15:53:20 +09:00
|
|
|
|
2008-12-24 04:49:23 +09:00
|
|
|
class FinishaddopenidAction extends Action
|
|
|
|
{
|
2009-01-17 05:25:46 +09:00
|
|
|
var $msg = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the redirect back from OpenID confirmation
|
|
|
|
*
|
|
|
|
* Check to see if the user's logged in, and then try
|
|
|
|
* to use the OpenID login system.
|
|
|
|
*
|
|
|
|
* @param array $args $_REQUEST arguments
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2008-06-18 15:53:20 +09:00
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function handle($args)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
|
|
|
if (!common_logged_in()) {
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: Client error message
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->clientError(_m('Not logged in.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
} else {
|
2009-01-17 05:25:46 +09:00
|
|
|
$this->tryLogin();
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-17 05:25:46 +09:00
|
|
|
/**
|
|
|
|
* Try to log in using OpenID
|
|
|
|
*
|
|
|
|
* Check the OpenID for validity; potentially store it.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
|
|
|
function tryLogin()
|
|
|
|
{
|
2009-12-03 02:47:02 +09:00
|
|
|
$consumer = oid_consumer();
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
$response = $consumer->complete(common_local_url('finishaddopenid'));
|
|
|
|
|
|
|
|
if ($response->status == Auth_OpenID_CANCEL) {
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: Status message in case the response from the OpenID provider is that the logon attempt was cancelled.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->message(_m('OpenID authentication cancelled.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
} else if ($response->status == Auth_OpenID_FAILURE) {
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: OpenID authentication failed; display the error message.
|
|
|
|
// TRANS: %s is the error message.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->message(sprintf(_m('OpenID authentication failed: %s'),
|
2009-01-17 05:25:46 +09:00
|
|
|
$response->message));
|
2008-12-24 04:19:07 +09:00
|
|
|
} else if ($response->status == Auth_OpenID_SUCCESS) {
|
|
|
|
|
2009-01-17 05:25:46 +09:00
|
|
|
$display = $response->getDisplayIdentifier();
|
2008-12-24 04:19:07 +09:00
|
|
|
$canonical = ($response->endpoint && $response->endpoint->canonicalID) ?
|
|
|
|
$response->endpoint->canonicalID : $display;
|
|
|
|
|
|
|
|
$sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
|
|
|
|
|
|
|
|
if ($sreg_resp) {
|
|
|
|
$sreg = $sreg_resp->contents();
|
|
|
|
}
|
|
|
|
|
2010-05-19 02:39:56 +09:00
|
|
|
// Launchpad teams extension
|
|
|
|
if (!oid_check_teams($response)) {
|
|
|
|
$this->message(_m('OpenID authentication aborted: you are not allowed to login to this site.'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-03 02:47:02 +09:00
|
|
|
$cur = common_current_user();
|
2009-01-17 05:25:46 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$other = oid_get_user($canonical);
|
|
|
|
|
|
|
|
if ($other) {
|
|
|
|
if ($other->id == $cur->id) {
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: message in case a user tries to add an OpenID that is already connected to them.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->message(_m('You already have this OpenID!'));
|
2008-12-24 04:19:07 +09:00
|
|
|
} else {
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: message in case a user tries to add an OpenID that is already used by another user.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->message(_m('Someone else already has this OpenID.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-01-17 05:25:46 +09:00
|
|
|
// start a transaction
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
$cur->query('BEGIN');
|
|
|
|
|
|
|
|
$result = oid_link_user($cur->id, $canonical, $display);
|
|
|
|
|
|
|
|
if (!$result) {
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: message in case the OpenID object cannot be connected to the user.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->message(_m('Error connecting user.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($sreg) {
|
|
|
|
if (!oid_update_user($cur, $sreg)) {
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: message in case the user or the user profile cannot be saved in StatusNet.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->message(_m('Error updating profile'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-17 05:25:46 +09:00
|
|
|
// success!
|
2008-12-24 04:19:07 +09:00
|
|
|
|
|
|
|
$cur->query('COMMIT');
|
|
|
|
|
|
|
|
oid_set_last($display);
|
|
|
|
|
2009-04-02 04:30:59 +09:00
|
|
|
common_redirect(common_local_url('openidsettings'), 303);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-17 05:25:46 +09:00
|
|
|
/**
|
|
|
|
* Show a failure message
|
|
|
|
*
|
|
|
|
* Something went wrong. Save the message, and show the page.
|
|
|
|
*
|
|
|
|
* @param string $msg Error message to show
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function message($msg)
|
|
|
|
{
|
2009-01-17 05:25:46 +09:00
|
|
|
$this->message = $msg;
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Title of the page
|
|
|
|
*
|
|
|
|
* @return string title
|
|
|
|
*/
|
|
|
|
|
|
|
|
function title()
|
|
|
|
{
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: Title after getting the status of the OpenID authorisation request.
|
2009-12-09 05:17:11 +09:00
|
|
|
return _m('OpenID Login');
|
2009-01-17 05:25:46 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show error message
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
|
|
|
|
function showPageNotice()
|
|
|
|
{
|
|
|
|
if ($this->message) {
|
|
|
|
$this->element('p', 'error', $this->message);
|
|
|
|
}
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-06-18 15:53:20 +09:00
|
|
|
}
|