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