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/>.
|
|
|
|
*/
|
|
|
|
|
2010-10-08 19:23:53 +01:00
|
|
|
if (!defined('STATUSNET')) {
|
|
|
|
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
|
|
|
|
{
|
2016-06-01 03:05:11 +01:00
|
|
|
function handle()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2016-06-01 03:05:11 +01:00
|
|
|
parent::handle();
|
2009-08-21 21:38:39 +01:00
|
|
|
if (common_is_real_login()) {
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: Client error message trying to log on with OpenID while already logged on.
|
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') {
|
2010-05-18 18:39:56 +01:00
|
|
|
$provider = common_config('openid', 'trusted_provider');
|
|
|
|
if ($provider) {
|
|
|
|
$openid_url = $provider;
|
2010-05-29 00:52:17 +01:00
|
|
|
if (common_config('openid', 'append_username')) {
|
|
|
|
$openid_url .= $this->trimmed('openid_username');
|
|
|
|
}
|
2010-05-18 18:39:56 +01:00
|
|
|
} else {
|
|
|
|
$openid_url = $this->trimmed('openid_url');
|
|
|
|
}
|
2008-08-29 05:09:25 +01:00
|
|
|
|
2010-03-25 20:58:05 +00:00
|
|
|
oid_assert_allowed($openid_url);
|
|
|
|
|
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)
|
2010-04-30 22:07:19 +01: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-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 {
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: OpenID plugin message.
|
|
|
|
// TRANS: "OpenID" is the display text for a link with URL "(%%doc.openid%%)".
|
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();
|
2010-05-29 00:52:17 +01: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-03 20:42:50 +01:00
|
|
|
}
|
|
|
|
|
2009-01-22 23:17:08 +00:00
|
|
|
function title()
|
2008-12-23 19:33:23 +00:00
|
|
|
{
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: OpenID plugin message. Title.
|
2011-04-27 19:37:44 +01:00
|
|
|
return _m('TITLE','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');
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: OpenID plugin logon form legend.
|
2011-04-27 19:37:44 +01:00
|
|
|
$this->element('legend', null, _m('LEGEND','OpenID login'));
|
2009-01-23 08:52:04 +00:00
|
|
|
|
|
|
|
$this->elementStart('ul', 'form_data');
|
|
|
|
$this->elementStart('li');
|
2010-05-18 18:39:56 +01:00
|
|
|
$provider = common_config('openid', 'trusted_provider');
|
2010-05-29 00:52:17 +01:00
|
|
|
$appendUsername = common_config('openid', 'append_username');
|
2010-05-18 18:39:56 +01:00
|
|
|
if ($provider) {
|
2011-06-05 18:30:04 +01:00
|
|
|
// TRANS: Field label.
|
2019-05-06 23:58:45 +01:00
|
|
|
$this->element('label', [], _m('LABEL','OpenID provider'));
|
|
|
|
$this->element('span', [], $provider);
|
2010-05-29 00:52:17 +01:00
|
|
|
if ($appendUsername) {
|
|
|
|
$this->element('input', array('id' => 'openid_username',
|
|
|
|
'name' => 'openid_username',
|
|
|
|
'style' => 'float: none'));
|
|
|
|
}
|
2010-05-18 18:39:56 +01:00
|
|
|
$this->element('p', 'form_guide',
|
2011-04-27 19:37:44 +01:00
|
|
|
// TRANS: Form guide.
|
2010-05-29 00:52:17 +01:00
|
|
|
($appendUsername ? _m('Enter your username.') . ' ' : '') .
|
2011-04-27 19:37:44 +01:00
|
|
|
// TRANS: Form guide.
|
2010-05-18 18:39:56 +01:00
|
|
|
_m('You will be sent to the provider\'s site for authentication.'));
|
|
|
|
$this->hidden('openid_url', $provider);
|
|
|
|
} else {
|
2010-05-19 20:51:25 +01:00
|
|
|
// TRANS: OpenID plugin logon form field label.
|
2010-05-18 18:39:56 +01:00
|
|
|
$this->input('openid_url', _m('OpenID URL'),
|
|
|
|
$this->openid_url,
|
2011-04-27 19:37:44 +01:00
|
|
|
// TRANS: OpenID plugin logon form field title.
|
|
|
|
_m('Your OpenID URL.'));
|
2010-05-18 18:39:56 +01:00
|
|
|
}
|
2009-01-23 08:52:04 +00:00
|
|
|
$this->elementEnd('li');
|
|
|
|
$this->elementStart('li', array('id' => 'settings_rememberme'));
|
2010-04-30 22:07:19 +01:00
|
|
|
// TRANS: OpenID plugin logon form checkbox label for setting to put the OpenID information in a cookie.
|
2009-12-08 20:17:11 +00:00
|
|
|
$this->checkbox('rememberme', _m('Remember me'), false,
|
2011-04-27 19:37:44 +01:00
|
|
|
// TRANS: OpenID plugin logon form field title.
|
2009-12-08 20:17:11 +00:00
|
|
|
_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');
|
2010-04-30 22:07:19 +01: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 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
|
|
|
}
|
2011-03-09 15:11:59 +00:00
|
|
|
|
|
|
|
function showNoticeForm()
|
|
|
|
{
|
|
|
|
}
|
2011-03-16 14:05:07 +00:00
|
|
|
|
|
|
|
function showProfileBlock()
|
|
|
|
{
|
|
|
|
}
|
2008-06-17 14:35:01 +01:00
|
|
|
}
|