51 lines
1.2 KiB
PHP
Raw Normal View History

<?php
use PicoFarad\Router;
use PicoFarad\Response;
use PicoFarad\Request;
use PicoFarad\Session;
2014-03-16 21:56:43 -04:00
use PicoFarad\Template;
// Logout and destroy session
Router\get_action('logout', function() {
2015-01-17 18:53:40 -05:00
Model\User\logout();
Response\redirect('?action=login');
});
// Display form login
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');
}
Response\html(Template\load('login', array(
'errors' => array(),
2014-11-07 21:44:20 -05:00
'values' => array(
'csrf' => Model\Config\generate_csrf(),
),
'databases' => Model\Database\get_list(),
'current_database' => Model\Database\select()
)));
});
// Check credentials and redirect to unread items
Router\post_action('login', function() {
$values = Request\values();
2014-11-07 21:44:20 -05:00
Model\Config\check_csrf_values($values);
list($valid, $errors) = Model\User\validate_login($values);
2014-05-26 20:47:40 -04:00
if ($valid) {
Response\redirect('?action=unread');
}
Response\html(Template\load('login', array(
'errors' => $errors,
2014-11-07 21:44:20 -05:00
'values' => $values + array('csrf' => Model\Config\generate_csrf()),
'databases' => Model\Database\get_list(),
'current_database' => Model\Database\select()
)));
});