2008-05-08 01:48:07 +09:00
|
|
|
<?php
|
2008-05-21 04:14:12 +09:00
|
|
|
/*
|
2008-05-15 04:26:48 +09:00
|
|
|
* Laconica - a distributed open-source microblogging tool
|
|
|
|
* Copyright (C) 2008, Controlez-Vous, Inc.
|
2008-05-21 04:14:12 +09:00
|
|
|
*
|
2008-05-15 04:26:48 +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.
|
2008-05-21 04:14:12 +09:00
|
|
|
*
|
2008-05-15 04:26:48 +09:00
|
|
|
* 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.
|
2008-05-21 04:14:12 +09:00
|
|
|
*
|
2008-05-15 04:26:48 +09:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-18 00:47:01 +09:00
|
|
|
if (!defined('LACONICA')) { exit(1); }
|
2008-05-08 01:48:07 +09:00
|
|
|
|
2008-12-24 04:49:23 +09:00
|
|
|
class LoginAction extends Action
|
|
|
|
{
|
2009-01-16 08:17:04 +09:00
|
|
|
var $error = null;
|
|
|
|
|
2009-01-16 08:09:16 +09:00
|
|
|
function isReadOnly()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
return true;
|
|
|
|
}
|
2008-07-23 06:20:56 +09:00
|
|
|
|
2008-12-24 04:33:23 +09:00
|
|
|
function handle($args)
|
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
parent::handle($args);
|
|
|
|
if (common_is_real_login()) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('Already logged in.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
2009-01-16 08:09:16 +09:00
|
|
|
$this->checkLogin();
|
2008-12-24 04:19:07 +09:00
|
|
|
} else {
|
2009-01-16 08:09:16 +09:00
|
|
|
$this->showForm();
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
|
|
|
}
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2009-01-16 08:09:16 +09:00
|
|
|
function checkLogin()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2008-12-24 04:19:07 +09:00
|
|
|
# XXX: login throttle
|
2008-11-11 11:23:30 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
# CSRF protection - token set in common_notice_form()
|
|
|
|
$token = $this->trimmed('token');
|
|
|
|
if (!$token || $token != common_session_token()) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->clientError(_('There was a problem with your session token. Try again, please.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
2008-11-11 11:23:30 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
$nickname = common_canonical_nickname($this->trimmed('nickname'));
|
|
|
|
$password = $this->arg('password');
|
|
|
|
if (common_check_user($nickname, $password)) {
|
|
|
|
# success!
|
|
|
|
if (!common_set_user($nickname)) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->serverError(_('Error setting user.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
common_real_login(true);
|
|
|
|
if ($this->boolean('rememberme')) {
|
|
|
|
common_debug('Adding rememberme cookie for ' . $nickname);
|
|
|
|
common_rememberme();
|
|
|
|
}
|
|
|
|
# success!
|
|
|
|
$url = common_get_returnto();
|
|
|
|
if ($url) {
|
|
|
|
# We don't have to return to it again
|
2008-12-24 04:21:29 +09:00
|
|
|
common_set_returnto(null);
|
2008-12-24 04:19:07 +09:00
|
|
|
} else {
|
|
|
|
$url = common_local_url('all',
|
|
|
|
array('nickname' =>
|
|
|
|
$nickname));
|
|
|
|
}
|
|
|
|
common_redirect($url);
|
|
|
|
} else {
|
2009-01-16 08:09:16 +09:00
|
|
|
$this->showForm(_('Incorrect username or password.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
# success!
|
|
|
|
if (!common_set_user($user)) {
|
2009-01-16 08:03:38 +09:00
|
|
|
$this->serverError(_('Error setting user.'));
|
2008-12-24 04:19:07 +09:00
|
|
|
return;
|
|
|
|
}
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
common_real_login(true);
|
2008-07-10 07:46:30 +09:00
|
|
|
|
2008-12-24 04:19:07 +09:00
|
|
|
if ($this->boolean('rememberme')) {
|
|
|
|
common_debug('Adding rememberme cookie for ' . $nickname);
|
|
|
|
common_rememberme($user);
|
|
|
|
}
|
|
|
|
# success!
|
|
|
|
$url = common_get_returnto();
|
|
|
|
if ($url) {
|
|
|
|
# We don't have to return to it again
|
2008-12-24 04:21:29 +09:00
|
|
|
common_set_returnto(null);
|
2008-12-24 04:19:07 +09:00
|
|
|
} else {
|
|
|
|
$url = common_local_url('all',
|
|
|
|
array('nickname' =>
|
|
|
|
$nickname));
|
|
|
|
}
|
|
|
|
common_redirect($url);
|
|
|
|
}
|
2008-05-21 04:14:12 +09:00
|
|
|
|
2009-01-16 08:09:16 +09:00
|
|
|
function showForm($error=null)
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->error = $error;
|
|
|
|
$this->showPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
function title()
|
|
|
|
{
|
|
|
|
return _('Login');
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPageNotice()
|
|
|
|
{
|
|
|
|
if ($this->error) {
|
|
|
|
$this->element('p', 'error', $this->error);
|
|
|
|
} else {
|
2009-01-16 08:09:16 +09:00
|
|
|
$instr = $this->getInstructions();
|
2009-01-16 07:57:15 +09:00
|
|
|
$output = common_markup_to_html($instr);
|
|
|
|
$this->raw($output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showContent()
|
|
|
|
{
|
|
|
|
$this->elementStart('form', array('method' => 'post',
|
2008-12-24 04:19:07 +09:00
|
|
|
'id' => 'login',
|
|
|
|
'action' => common_local_url('login')));
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->input('nickname', _('Nickname'));
|
|
|
|
$this->password('password', _('Password'));
|
|
|
|
$this->checkbox('rememberme', _('Remember me'), false,
|
2008-12-24 04:19:07 +09:00
|
|
|
_('Automatically login in the future; ' .
|
|
|
|
'not for shared computers!'));
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->submit('submit', _('Login'));
|
|
|
|
$this->hidden('token', common_session_token());
|
|
|
|
$this->elementEnd('form');
|
|
|
|
$this->elementStart('p');
|
|
|
|
$this->element('a', array('href' => common_local_url('recoverpassword')),
|
2008-12-24 04:19:07 +09:00
|
|
|
_('Lost or forgotten password?'));
|
2009-01-16 07:57:15 +09:00
|
|
|
$this->elementEnd('p');
|
2008-12-24 04:19:07 +09:00
|
|
|
}
|
2008-06-24 13:05:48 +09:00
|
|
|
|
2009-01-16 08:09:16 +09:00
|
|
|
function getInstructions()
|
2008-12-24 04:33:23 +09:00
|
|
|
{
|
2008-12-24 04:19:07 +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)
|
|
|
|
return _('For security reasons, please re-enter your ' .
|
|
|
|
'user name and password ' .
|
|
|
|
'before changing your settings.');
|
|
|
|
} else {
|
|
|
|
return _('Login with your username and password. ' .
|
|
|
|
'Don\'t have a username yet? ' .
|
|
|
|
'[Register](%%action.register%%) a new account, or ' .
|
|
|
|
'try [OpenID](%%action.openidlogin%%). ');
|
|
|
|
}
|
|
|
|
}
|
2008-05-08 01:48:07 +09:00
|
|
|
}
|