2016-09-01 23:13:23 +02:00
|
|
|
<?php
|
|
|
|
/*****************************************************************************
|
|
|
|
* Login.php
|
|
|
|
* Contains the controller for logging the user in.
|
|
|
|
*
|
|
|
|
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
class Login extends HTMLController
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
// No need to log in twice, dear heart!
|
|
|
|
if (Registry::get('user')->isLoggedIn())
|
|
|
|
{
|
2016-09-02 11:16:01 +02:00
|
|
|
header('Location: ' . BASEURL . '/');
|
2016-09-01 23:13:23 +02:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
$login_error = false;
|
|
|
|
if (isset($_POST['emailaddress'], $_POST['password']))
|
|
|
|
{
|
|
|
|
if (Authentication::checkPassword($_POST['emailaddress'], $_POST['password']))
|
|
|
|
{
|
|
|
|
parent::__construct('Login');
|
|
|
|
$_SESSION['user_id'] = Authentication::getUserId($_POST['emailaddress']);
|
|
|
|
|
|
|
|
if (isset($_POST['redirect_url']))
|
|
|
|
header('Location: ' . base64_decode($_POST['redirect_url']));
|
|
|
|
elseif (isset($_SESSION['login_url']))
|
|
|
|
header('Location: ' . $_SESSION['redirect_url']);
|
|
|
|
else
|
|
|
|
header('Location: ' . BASEURL . '/admin/');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
$login_error = true;
|
|
|
|
}
|
|
|
|
|
2016-09-02 11:16:01 +02:00
|
|
|
parent::__construct('Log in - ' . SITE_TITLE);
|
2016-09-01 23:13:23 +02:00
|
|
|
$this->page->appendStylesheet(BASEURL . '/css/admin.css');
|
|
|
|
$form = new LogInForm('Log in');
|
|
|
|
if ($login_error)
|
|
|
|
$form->setErrorMessage('Invalid email address or password.');
|
|
|
|
|
|
|
|
// Tried anything? Be helpful, at least.
|
|
|
|
if (isset($_POST['emailaddress']))
|
|
|
|
$form->setEmail($_POST['emailaddress']);
|
|
|
|
|
|
|
|
$this->page->adopt($form);
|
|
|
|
}
|
|
|
|
}
|