Commit 3bca7331 authored by Taddeus Kroes's avatar Taddeus Kroes

Added auto-login option that lasts for 2 weeks

parent 10e32f5c
......@@ -89,6 +89,9 @@ $app->hook('slim.before.router', function () use ($app, $user) {
$app->redirect(ROOT_URL . '/login');
});
// Extend maximum session lifetime to allow auto-login
$session->setExpiration($config['max_session_lifetime']);
/*
* Routes
*/
......@@ -98,5 +101,6 @@ require 'routes/register.php';
require 'routes/user.php';
require 'routes/match.php';
// Certain globals should be available in all templates
$view->replace(compact('app', 'config', 'user'));
$app->run();
......@@ -2,6 +2,7 @@
"database": {
"lazy": true
},
"max_session_lifetime": "2 weeks",
"log.enable": true,
"debug": false
}
......@@ -16,7 +16,7 @@ function login_form() {
->setRequired();
$form->addPassword('password', _('Password'))
->setRequired();
//$form->addCheckbox('remember', _('Remember me'));
$form->addCheckbox('remember', _('Remember me'));
$form->addSubmit('send', _('Login'));
return $form;
......@@ -29,7 +29,7 @@ $app->get('/login', function () use ($app, $user) {
$app->render('login', array('form' => login_form()));
});
$app->post('/login', function () use ($app, $user) {
$app->post('/login', function () use ($config, $app, $user, $session) {
$form = login_form();
$form->validate();
......@@ -38,6 +38,12 @@ $app->post('/login', function () use ($app, $user) {
try {
$user->login($values->username, $values->password);
if ($values->remember)
$user->setExpiration($config['max_session_lifetime'], false);
else
$user->setExpiration(0, true);
$app->redirect(ROOT_URL);
} catch (Nette\Security\AuthenticationException $e) {
$form->addError($e->getMessage());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment