2008-06-17 14:35:01 +01:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Laconica - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, Controlez-Vous, Inc.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!defined('LACONICA')) { exit(1); }
|
|
|
|
|
2008-06-17 15:51:40 +01:00
|
|
|
require_once(INSTALLDIR.'/lib/openid.php');
|
|
|
|
|
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);
|
|
|
|
if (common_logged_in()) {
|
2009-01-15 23:03:38 +00:00
|
|
|
$this->clientError(_('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-01-22 23:17:08 +00:00
|
|
|
$this->showForm(_('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
|
|
|
{
|
2008-12-23 19:19:07 +00:00
|
|
|
return _('Login with an [OpenID](%%doc.openid%%) account.');
|
|
|
|
}
|
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-01-22 23:17:08 +00:00
|
|
|
function title()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2009-01-22 23:17:08 +00:00
|
|
|
return _('OpenID Login');
|
|
|
|
}
|
|
|
|
|
|
|
|
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',
|
2008-12-23 19:19:07 +00:00
|
|
|
'id' => 'openidlogin',
|
|
|
|
'action' => $formaction));
|
2009-01-15 22:57:15 +00:00
|
|
|
$this->hidden('token', common_session_token());
|
|
|
|
$this->input('openid_url', _('OpenID URL'),
|
2009-01-22 23:17:08 +00:00
|
|
|
$this->openid_url,
|
2008-12-23 19:19:07 +00:00
|
|
|
_('Your OpenID URL'));
|
2009-01-15 22:57:15 +00:00
|
|
|
$this->checkbox('rememberme', _('Remember me'), false,
|
2008-12-23 19:19:07 +00:00
|
|
|
_('Automatically login in the future; ' .
|
|
|
|
'not for shared computers!'));
|
2009-01-15 22:57:15 +00:00
|
|
|
$this->submit('submit', _('Login'));
|
|
|
|
$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
|
|
|
}
|