2008-06-17 22:35:01 +09: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 23:51:40 +09:00
|
|
|
require_once(INSTALLDIR.'/lib/openid.php');
|
|
|
|
|
2008-06-17 22:35:01 +09:00
|
|
|
class OpenidloginAction extends Action {
|
2008-06-17 23:49:42 +09:00
|
|
|
|
2008-06-17 22:35:01 +09:00
|
|
|
function handle($args) {
|
|
|
|
parent::handle($args);
|
|
|
|
if (common_logged_in()) {
|
2008-07-08 18:45:31 +09:00
|
|
|
common_user_error(_('Already logged in.'));
|
2008-06-17 22:35:01 +09:00
|
|
|
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
2008-08-29 13:09:25 +09:00
|
|
|
$openid_url = $this->trimmed('openid_url');
|
|
|
|
|
2008-08-29 12:59:34 +09:00
|
|
|
# CSRF protection
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
if (!$token || $token != common_session_token()) {
|
2008-08-29 13:09:25 +09:00
|
|
|
$this->show_form(_('There was a problem with your session token. Try again, please.'), $openid_url);
|
2008-08-29 12:59:34 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-19 22:47:10 +09:00
|
|
|
$result = oid_authenticate($openid_url,
|
2008-06-19 00:05:57 +09:00
|
|
|
'finishopenidlogin');
|
2008-06-18 22:32:51 +09:00
|
|
|
if (is_string($result)) { # error message
|
2008-06-19 22:47:10 +09:00
|
|
|
$this->show_form($result, $openid_url);
|
2008-06-18 22:32:51 +09:00
|
|
|
}
|
2008-06-17 22:35:01 +09:00
|
|
|
} else {
|
2008-06-19 22:47:10 +09:00
|
|
|
$openid_url = oid_get_last();
|
|
|
|
$this->show_form(NULL, $openid_url);
|
2008-06-17 22:35:01 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-02 02:24:29 +09:00
|
|
|
function get_instructions() {
|
2008-07-08 18:45:31 +09:00
|
|
|
return _('Login with an [OpenID](%%doc.openid%%) account.');
|
2008-07-02 02:24:29 +09:00
|
|
|
}
|
|
|
|
|
2008-06-19 04:02:02 +09:00
|
|
|
function show_top($error=NULL) {
|
2008-06-17 22:35:01 +09:00
|
|
|
if ($error) {
|
|
|
|
common_element('div', array('class' => 'error'), $error);
|
|
|
|
} else {
|
2008-07-02 02:24:29 +09:00
|
|
|
$instr = $this->get_instructions();
|
|
|
|
$output = common_markup_to_html($instr);
|
|
|
|
common_element_start('div', 'instructions');
|
|
|
|
common_raw($output);
|
|
|
|
common_element_end('div');
|
2008-06-17 22:35:01 +09:00
|
|
|
}
|
2008-06-19 04:02:02 +09:00
|
|
|
}
|
2008-07-02 02:24:29 +09:00
|
|
|
|
2008-06-19 22:47:10 +09:00
|
|
|
function show_form($error=NULL, $openid_url) {
|
2008-07-08 18:45:31 +09:00
|
|
|
common_show_header(_('OpenID Login'), NULL, $error, array($this, 'show_top'));
|
2008-06-19 00:05:57 +09:00
|
|
|
$formaction = common_local_url('openidlogin');
|
2008-07-02 22:15:07 +09:00
|
|
|
common_element_start('form', array('method' => 'post',
|
2008-06-17 22:35:01 +09:00
|
|
|
'id' => 'openidlogin',
|
2008-06-19 00:05:57 +09:00
|
|
|
'action' => $formaction));
|
2008-08-29 12:59:34 +09:00
|
|
|
common_hidden('token', common_session_token());
|
2008-07-08 18:45:31 +09:00
|
|
|
common_input('openid_url', _('OpenID URL'),
|
2008-06-19 22:47:10 +09:00
|
|
|
$openid_url,
|
2008-07-08 18:45:31 +09:00
|
|
|
_('Your OpenID URL'));
|
|
|
|
common_submit('submit', _('Login'));
|
2008-06-17 22:35:01 +09:00
|
|
|
common_element_end('form');
|
|
|
|
common_show_footer();
|
|
|
|
}
|
|
|
|
}
|