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