2008-06-17 14:35:01 +01:00
|
|
|
<?php
|
|
|
|
/*
|
2009-08-25 23:14:12 +01:00
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
2009-08-25 23:12:20 +01:00
|
|
|
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
2008-06-17 14:35:01 +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-26 15:41:36 +01:00
|
|
|
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
|
2008-06-17 14:35:01 +01:00
|
|
|
|
2009-08-04 12:45:16 +01:00
|
|
|
require_once INSTALLDIR.'/plugins/OpenID/openid.php';
|
2008-06-17 15:51:40 +01:00
|
|
|
|
2008-12-23 19:49:23 +00:00
|
|
|
class OpenidloginAction extends Action
|
|
|
|
{
|
2008-12-23 19:33:23 +00:00
|
|
|
function handle($args)
|
|
|
|
{
|
2008-12-23 19:19:07 +00:00
|
|
|
parent::handle($args);
|
2009-08-21 21:38:39 +01:00
|
|
|
if (common_is_real_login()) {
|
2009-12-08 20:17:11 +00:00
|
|
|
$this->clientError(_m('Already logged in.'));
|
2008-12-23 19:19:07 +00:00
|
|
|
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
|
|
$openid_url = $this->trimmed('openid_url');
|
2008-08-29 05:09:25 +01:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
# CSRF protection
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
if (!$token || $token != common_session_token()) {
|
2009-12-08 20:17:11 +00:00
|
|
|
$this->showForm(_m('There was a problem with your session token. Try again, please.'), $openid_url);
|
2008-12-23 19:19:07 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-08-29 04:59:34 +01:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$rememberme = $this->boolean('rememberme');
|
2009-01-22 23:17:08 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
common_ensure_session();
|
2009-01-22 23:17:08 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$_SESSION['openid_rememberme'] = $rememberme;
|
2009-01-22 23:17:08 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
$result = oid_authenticate($openid_url,
|
|
|
|
'finishopenidlogin');
|
2009-01-22 23:17:08 +00:00
|
|
|
|
2008-12-23 19:19:07 +00:00
|
|
|
if (is_string($result)) { # error message
|
|
|
|
unset($_SESSION['openid_rememberme']);
|
2009-01-22 23:17:08 +00:00
|
|
|
$this->showForm($result, $openid_url);
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$openid_url = oid_get_last();
|
2009-01-22 23:17:08 +00:00
|
|
|
$this->showForm(null, $openid_url);
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-17 14:35:01 +01:00
|
|
|
|
2009-01-22 23:17:08 +00:00
|
|
|
function getInstructions()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2009-02-05 16:46:17 +00:00
|
|
|
if (common_logged_in() && !common_is_real_login() &&
|
|
|
|
common_get_returnto()) {
|
|
|
|
// rememberme logins have to reauthenticate before
|
|
|
|
// changing any profile settings (cookie-stealing protection)
|
2009-12-08 20:17:11 +00:00
|
|
|
return _m('For security reasons, please re-login with your ' .
|
2009-02-05 16:46:17 +00:00
|
|
|
'[OpenID](%%doc.openid%%) ' .
|
|
|
|
'before changing your settings.');
|
|
|
|
} else {
|
2009-12-08 20:17:11 +00:00
|
|
|
return _m('Login with an [OpenID](%%doc.openid%%) account.');
|
2009-02-05 16:46:17 +00:00
|
|
|
}
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-07-01 18:24:29 +01:00
|
|
|
|
2009-01-22 23:17:08 +00:00
|
|
|
function showPageNotice()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2009-01-22 23:17:08 +00:00
|
|
|
if ($this->error) {
|
|
|
|
$this->element('div', array('class' => 'error'), $this->error);
|
2008-12-23 19:19:07 +00:00
|
|
|
} else {
|
2009-01-22 23:17:08 +00:00
|
|
|
$instr = $this->getInstructions();
|
2008-12-23 19:19:07 +00:00
|
|
|
$output = common_markup_to_html($instr);
|
2009-01-15 22:57:15 +00:00
|
|
|
$this->elementStart('div', 'instructions');
|
|
|
|
$this->raw($output);
|
|
|
|
$this->elementEnd('div');
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
|
|
|
}
|
2008-07-01 18:24:29 +01:00
|
|
|
|
2009-09-03 20:42:50 +01:00
|
|
|
function showScripts()
|
|
|
|
{
|
|
|
|
parent::showScripts();
|
|
|
|
$this->autofocus('openid_url');
|
|
|
|
}
|
|
|
|
|
2009-01-22 23:17:08 +00:00
|
|
|
function title()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2009-12-08 20:17:11 +00:00
|
|
|
return _m('OpenID Login');
|
2009-01-22 23:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showForm($error=null, $openid_url)
|
|
|
|
{
|
|
|
|
$this->error = $error;
|
|
|
|
$this->openid_url = $openid_url;
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
function showContent() {
|
2008-12-23 19:19:07 +00:00
|
|
|
$formaction = common_local_url('openidlogin');
|
2009-01-15 22:57:15 +00:00
|
|
|
$this->elementStart('form', array('method' => 'post',
|
2009-01-23 08:52:04 +00:00
|
|
|
'id' => 'form_openid_login',
|
|
|
|
'class' => 'form_settings',
|
2008-12-23 19:19:07 +00:00
|
|
|
'action' => $formaction));
|
2009-01-23 08:52:04 +00:00
|
|
|
$this->elementStart('fieldset');
|
2009-12-08 20:17:11 +00:00
|
|
|
$this->element('legend', null, _m('OpenID login'));
|
2009-01-15 22:57:15 +00:00
|
|
|
$this->hidden('token', common_session_token());
|
2009-01-23 08:52:04 +00:00
|
|
|
|
|
|
|
$this->elementStart('ul', 'form_data');
|
|
|
|
$this->elementStart('li');
|
2009-12-08 20:17:11 +00:00
|
|
|
$this->input('openid_url', _m('OpenID URL'),
|
2009-01-22 23:17:08 +00:00
|
|
|
$this->openid_url,
|
2009-12-08 20:17:11 +00:00
|
|
|
_m('Your OpenID URL'));
|
2009-01-23 08:52:04 +00:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementStart('li', array('id' => 'settings_rememberme'));
|
2009-12-08 20:17:11 +00:00
|
|
|
$this->checkbox('rememberme', _m('Remember me'), false,
|
|
|
|
_m('Automatically login in the future; ' .
|
2008-12-23 19:19:07 +00:00
|
|
|
'not for shared computers!'));
|
2009-01-23 08:52:04 +00:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementEnd('ul');
|
2009-12-08 20:17:11 +00:00
|
|
|
$this->submit('submit', _m('Login'));
|
2009-01-23 08:52:04 +00:00
|
|
|
$this->elementEnd('fieldset');
|
2009-01-15 22:57:15 +00:00
|
|
|
$this->elementEnd('form');
|
2009-01-22 23:17:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function showLocalNav()
|
|
|
|
{
|
|
|
|
$nav = new LoginGroupNav($this);
|
|
|
|
$nav->show();
|
2008-12-23 19:19:07 +00:00
|
|
|
}
|
2008-06-17 14:35:01 +01:00
|
|
|
}
|