2008-06-17 22:35:01 +09:00
|
|
|
<?php
|
|
|
|
/*
|
2009-08-26 07:14:12 +09:00
|
|
|
* StatusNet - the distributed open-source microblogging tool
|
2009-08-26 07:12:20 +09:00
|
|
|
* Copyright (C) 2008, 2009, StatusNet, Inc.
|
2008-06-17 22:35:01 +09: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/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-09 03:23:53 +09:00
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-06-17 22:35:01 +09:00
|
|
|
|
2009-08-04 20:45:16 +09:00
|
|
|
require_once INSTALLDIR.'/plugins/OpenID/openid.php';
|
2008-06-17 23:51:40 +09:00
|
|
|
|
2008-12-24 04:49:23 +09:00
|
|
|
class OpenidloginAction extends Action
|
|
|
|
{
|
2008-12-24 04:33:23 +09:00
|
|
|
function handle($args)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
2009-08-22 05:38:39 +09:00
|
|
|
if (common_is_real_login()) {
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: Client error message trying to log on with OpenID while already logged on.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->clientError(_m('Already logged in.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
2010-05-19 02:39:56 +09:00
|
|
|
$provider = common_config('openid', 'trusted_provider');
|
|
|
|
if ($provider) {
|
|
|
|
$openid_url = $provider;
|
2010-05-29 08:52:17 +09:00
|
|
|
if (common_config('openid', 'append_username')) {
|
|
|
|
$openid_url .= $this->trimmed('openid_username');
|
|
|
|
}
|
2010-05-19 02:39:56 +09:00
|
|
|
} else {
|
|
|
|
$openid_url = $this->trimmed('openid_url');
|
|
|
|
}
|
2008-08-29 13:09:25 +09:00
|
|
|
|
2010-03-26 05:58:05 +09:00
|
|
|
oid_assert_allowed($openid_url);
|
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$rememberme = $this->boolean('rememberme');
|
2009-01-23 08:17:08 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
common_ensure_session();
|
2009-01-23 08:17:08 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$_SESSION['openid_rememberme'] = $rememberme;
|
2009-01-23 08:17:08 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$result = oid_authenticate($openid_url,
|
|
|
|
'finishopenidlogin');
|
2009-01-23 08:17:08 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if (is_string($result)) { # error message
|
|
|
|
unset($_SESSION['openid_rememberme']);
|
2009-01-23 08:17:08 +09:00
|
|
|
$this->showForm($result, $openid_url);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$openid_url = oid_get_last();
|
2009-01-23 08:17:08 +09:00
|
|
|
$this->showForm(null, $openid_url);
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
}
|
2008-06-17 22:35:01 +09:00
|
|
|
|
2009-01-23 08:17:08 +09:00
|
|
|
function getInstructions()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-02-06 01:46:17 +09: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)
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: OpenID plugin message. Rememberme logins have to reauthenticate before changing any profile settings.
|
|
|
|
// TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
|
2009-12-09 05:17:11 +09:00
|
|
|
return _m('For security reasons, please re-login with your ' .
|
2009-02-06 01:46:17 +09:00
|
|
|
'[OpenID](%%doc.openid%%) ' .
|
|
|
|
'before changing your settings.');
|
|
|
|
} else {
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: OpenID plugin message.
|
|
|
|
// TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
|
2009-12-09 05:17:11 +09:00
|
|
|
return _m('Login with an [OpenID](%%doc.openid%%) account.');
|
2009-02-06 01:46:17 +09:00
|
|
|
}
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-07-02 02:24:29 +09:00
|
|
|
|
2009-01-23 08:17:08 +09:00
|
|
|
function showPageNotice()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-01-23 08:17:08 +09:00
|
|
|
if ($this->error) {
|
|
|
|
$this->element('div', array('class' => 'error'), $this->error);
|
2008-12-24 04:19:07 +09:00
|
|
|
} else {
|
2009-01-23 08:17:08 +09:00
|
|
|
$instr = $this->getInstructions();
|
2008-12-24 04:19:07 +09:00
|
|
|
$output = common_markup_to_html($instr);
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementStart('div', 'instructions');
|
|
|
|
$this->raw($output);
|
|
|
|
$this->elementEnd('div');
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
}
|
2008-07-02 02:24:29 +09:00
|
|
|
|
2009-09-04 04:42:50 +09:00
|
|
|
function showScripts()
|
|
|
|
{
|
|
|
|
parent::showScripts();
|
2010-05-29 08:52:17 +09:00
|
|
|
if (common_config('openid', 'trusted_provider')) {
|
|
|
|
if (common_config('openid', 'append_username')) {
|
|
|
|
$this->autofocus('openid_username');
|
|
|
|
} else {
|
|
|
|
$this->autofocus('rememberme');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$this->autofocus('openid_url');
|
|
|
|
}
|
2009-09-04 04:42:50 +09:00
|
|
|
}
|
|
|
|
|
2009-01-23 08:17:08 +09:00
|
|
|
function title()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: OpenID plugin message. Title.
|
2009-12-09 05:17:11 +09:00
|
|
|
return _m('OpenID Login');
|
2009-01-23 08:17:08 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function showForm($error=null, $openid_url)
|
|
|
|
{
|
|
|
|
$this->error = $error;
|
|
|
|
$this->openid_url = $openid_url;
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
function showContent() {
|
2008-12-24 04:19:07 +09:00
|
|
|
$formaction = common_local_url('openidlogin');
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementStart('form', array('method' => 'post',
|
2009-01-23 17:52:04 +09:00
|
|
|
'id' => 'form_openid_login',
|
|
|
|
'class' => 'form_settings',
|
2008-12-24 04:19:07 +09:00
|
|
|
'action' => $formaction));
|
2009-01-23 17:52:04 +09:00
|
|
|
$this->elementStart('fieldset');
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: OpenID plugin logon form legend.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->element('legend', null, _m('OpenID login'));
|
2009-01-23 17:52:04 +09:00
|
|
|
|
|
|
|
$this->elementStart('ul', 'form_data');
|
|
|
|
$this->elementStart('li');
|
2010-05-19 02:39:56 +09:00
|
|
|
$provider = common_config('openid', 'trusted_provider');
|
2010-05-29 08:52:17 +09:00
|
|
|
$appendUsername = common_config('openid', 'append_username');
|
2010-05-19 02:39:56 +09:00
|
|
|
if ($provider) {
|
|
|
|
$this->element('label', array(), _m('OpenID provider'));
|
|
|
|
$this->element('span', array(), $provider);
|
2010-05-29 08:52:17 +09:00
|
|
|
if ($appendUsername) {
|
|
|
|
$this->element('input', array('id' => 'openid_username',
|
|
|
|
'name' => 'openid_username',
|
|
|
|
'style' => 'float: none'));
|
|
|
|
}
|
2010-05-19 02:39:56 +09:00
|
|
|
$this->element('p', 'form_guide',
|
2010-05-29 08:52:17 +09:00
|
|
|
($appendUsername ? _m('Enter your username.') . ' ' : '') .
|
2010-05-19 02:39:56 +09:00
|
|
|
_m('You will be sent to the provider\'s site for authentication.'));
|
|
|
|
$this->hidden('openid_url', $provider);
|
|
|
|
} else {
|
2010-05-20 04:51:25 +09:00
|
|
|
// TRANS: OpenID plugin logon form field label.
|
2010-05-19 02:39:56 +09:00
|
|
|
$this->input('openid_url', _m('OpenID URL'),
|
|
|
|
$this->openid_url,
|
2010-05-20 04:51:25 +09:00
|
|
|
// TRANS: OpenID plugin logon form field instructions.
|
2010-05-19 02:39:56 +09:00
|
|
|
_m('Your OpenID URL'));
|
|
|
|
}
|
2009-01-23 17:52:04 +09:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementStart('li', array('id' => 'settings_rememberme'));
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: OpenID plugin logon form checkbox label for setting to put the OpenID information in a cookie.
|
2009-12-09 05:17:11 +09:00
|
|
|
$this->checkbox('rememberme', _m('Remember me'), false,
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: OpenID plugin logon form field instructions.
|
2009-12-09 05:17:11 +09:00
|
|
|
_m('Automatically login in the future; ' .
|
2008-12-24 04:19:07 +09:00
|
|
|
'not for shared computers!'));
|
2009-01-23 17:52:04 +09:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementEnd('ul');
|
2010-05-01 06:07:19 +09:00
|
|
|
// TRANS: OpenID plugin logon form button label to start logon with the data provided in the logon form.
|
|
|
|
$this->submit('submit', _m('BUTTON', 'Login'));
|
2009-01-23 17:52:04 +09:00
|
|
|
$this->elementEnd('fieldset');
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementEnd('form');
|
2009-01-23 08:17:08 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function showLocalNav()
|
|
|
|
{
|
|
|
|
$nav = new LoginGroupNav($this);
|
|
|
|
$nav->show();
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2011-03-10 00:11:59 +09:00
|
|
|
|
|
|
|
function showNoticeForm()
|
|
|
|
{
|
|
|
|
}
|
2008-06-17 22:35:01 +09:00
|
|
|
}
|