2013-12-23 02:55:53 +01:00
|
|
|
<?php
|
|
|
|
|
2016-12-26 15:44:53 +01:00
|
|
|
namespace Miniflux\Controller;
|
|
|
|
|
|
|
|
use Miniflux\Session\SessionManager;
|
|
|
|
use Miniflux\Session\SessionStorage;
|
2016-08-24 04:03:45 +02:00
|
|
|
use Miniflux\Validator;
|
2016-08-25 03:17:58 +02:00
|
|
|
use Miniflux\Router;
|
|
|
|
use Miniflux\Response;
|
2016-12-26 15:44:53 +01:00
|
|
|
use Miniflux\Model\RememberMe;
|
2016-08-25 03:17:58 +02:00
|
|
|
use Miniflux\Request;
|
|
|
|
use Miniflux\Template;
|
|
|
|
use Miniflux\Helper;
|
|
|
|
use Miniflux\Model;
|
2016-08-24 04:03:45 +02:00
|
|
|
|
2013-12-23 02:55:53 +01:00
|
|
|
// Logout and destroy session
|
2016-04-18 01:44:45 +02:00
|
|
|
Router\get_action('logout', function () {
|
2016-12-26 15:44:53 +01:00
|
|
|
SessionStorage::getInstance()->flush();
|
|
|
|
SessionManager::close();
|
|
|
|
RememberMe\destroy();
|
2013-12-23 02:55:53 +01:00
|
|
|
Response\redirect('?action=login');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display form login
|
2016-04-18 01:44:45 +02:00
|
|
|
Router\get_action('login', function () {
|
2016-12-26 15:44:53 +01:00
|
|
|
if (SessionStorage::getInstance()->isLogged()) {
|
2014-05-27 02:47:40 +02:00
|
|
|
Response\redirect('?action=unread');
|
|
|
|
}
|
2013-12-23 02:55:53 +01:00
|
|
|
|
2017-01-21 20:40:24 +01:00
|
|
|
Response\html(Template\load('auth/login', array(
|
2013-12-23 02:55:53 +01:00
|
|
|
'errors' => array(),
|
2014-11-08 03:44:20 +01:00
|
|
|
'values' => array(
|
2016-08-18 04:05:11 +02:00
|
|
|
'csrf' => Helper\generate_csrf(),
|
2014-11-08 03:44:20 +01:00
|
|
|
),
|
2013-12-23 02:55:53 +01:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check credentials and redirect to unread items
|
2016-04-18 01:44:45 +02:00
|
|
|
Router\post_action('login', function () {
|
2013-12-23 02:55:53 +01:00
|
|
|
$values = Request\values();
|
2016-08-18 04:05:11 +02:00
|
|
|
Helper\check_csrf_values($values);
|
2016-08-24 04:03:45 +02:00
|
|
|
list($valid, $errors) = Validator\User\validate_login($values);
|
2013-12-23 02:55:53 +01:00
|
|
|
|
2014-05-27 02:47:40 +02:00
|
|
|
if ($valid) {
|
|
|
|
Response\redirect('?action=unread');
|
|
|
|
}
|
2013-12-23 02:55:53 +01:00
|
|
|
|
2017-01-21 20:40:24 +01:00
|
|
|
Response\html(Template\load('auth/login', array(
|
2013-12-23 02:55:53 +01:00
|
|
|
'errors' => $errors,
|
2016-08-18 04:05:11 +02:00
|
|
|
'values' => $values + array('csrf' => Helper\generate_csrf()),
|
2013-12-23 02:55:53 +01:00
|
|
|
)));
|
|
|
|
});
|