2013-12-22 20:55:53 -05:00
|
|
|
<?php
|
|
|
|
|
2016-08-23 22:03:45 -04:00
|
|
|
use Miniflux\Validator;
|
2016-08-24 21:17:58 -04:00
|
|
|
use Miniflux\Router;
|
|
|
|
use Miniflux\Response;
|
|
|
|
use Miniflux\Request;
|
|
|
|
use Miniflux\Template;
|
|
|
|
use Miniflux\Helper;
|
|
|
|
use Miniflux\Model;
|
2016-08-23 22:03:45 -04:00
|
|
|
|
2013-12-22 20:55:53 -05:00
|
|
|
// Logout and destroy session
|
2016-04-17 19:44:45 -04:00
|
|
|
Router\get_action('logout', function () {
|
2015-01-17 18:53:40 -05:00
|
|
|
Model\User\logout();
|
2013-12-22 20:55:53 -05:00
|
|
|
Response\redirect('?action=login');
|
|
|
|
});
|
|
|
|
|
|
|
|
// Display form login
|
2016-04-17 19:44:45 -04:00
|
|
|
Router\get_action('login', function () {
|
2015-01-17 18:53:40 -05:00
|
|
|
if (Model\User\is_loggedin()) {
|
2014-05-26 20:47:40 -04:00
|
|
|
Response\redirect('?action=unread');
|
|
|
|
}
|
2013-12-22 20:55:53 -05:00
|
|
|
|
|
|
|
Response\html(Template\load('login', array(
|
|
|
|
'errors' => array(),
|
2014-11-07 21:44:20 -05:00
|
|
|
'values' => array(
|
2016-08-17 22:05:11 -04:00
|
|
|
'csrf' => Helper\generate_csrf(),
|
2014-11-07 21:44:20 -05:00
|
|
|
),
|
2014-04-05 20:24:13 -04:00
|
|
|
'databases' => Model\Database\get_list(),
|
|
|
|
'current_database' => Model\Database\select()
|
2013-12-22 20:55:53 -05:00
|
|
|
)));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Check credentials and redirect to unread items
|
2016-04-17 19:44:45 -04:00
|
|
|
Router\post_action('login', function () {
|
2013-12-22 20:55:53 -05:00
|
|
|
$values = Request\values();
|
2016-08-17 22:05:11 -04:00
|
|
|
Helper\check_csrf_values($values);
|
2016-08-23 22:03:45 -04:00
|
|
|
list($valid, $errors) = Validator\User\validate_login($values);
|
2013-12-22 20:55:53 -05:00
|
|
|
|
2014-05-26 20:47:40 -04:00
|
|
|
if ($valid) {
|
|
|
|
Response\redirect('?action=unread');
|
|
|
|
}
|
2013-12-22 20:55:53 -05:00
|
|
|
|
|
|
|
Response\html(Template\load('login', array(
|
|
|
|
'errors' => $errors,
|
2016-08-17 22:05:11 -04:00
|
|
|
'values' => $values + array('csrf' => Helper\generate_csrf()),
|
2014-04-05 20:24:13 -04:00
|
|
|
'databases' => Model\Database\get_list(),
|
|
|
|
'current_database' => Model\Database\select()
|
2013-12-22 20:55:53 -05:00
|
|
|
)));
|
|
|
|
});
|