Skip to content

Commit

Permalink
[Backoffice] Add heartbeat ticker to extend sessions before they expi…
Browse files Browse the repository at this point in the history
…re. Fixes #101
  • Loading branch information
NoUseFreak committed Oct 23, 2015
1 parent 1f7d597 commit 7f01c92
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/config/parameters.yml.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# This file is auto-generated during the composer install
parameters:
database_driver: pdo_mysql
database_host: 192.168.0.184
database_port: null
database_name: clastic
database_user: clastic
database_password: clastic
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: ThisTokenIsNotSoSecretChangeIt
debug_toolbar: true
debug_redirects: false
use_assetic_controller: true
1 change: 1 addition & 0 deletions app/config/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ security:
- { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: _heartbeat$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
33 changes: 33 additions & 0 deletions src/Clastic/BackofficeBundle/Controller/HeartbeatController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/**
* This file is part of the Clastic package.
*
* (c) Dries De Peuter <dries@nousefreak.be>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Clastic\BackofficeBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;

/**
* HeartBeatController.
*
* @author Dries De Peuter <dries@nousefreak.be>
*/
class HeartbeatController extends Controller
{
/**
* @return Response
*/
public function tickAction()
{
$maxlifetime = ini_get('session.gc_maxlifetime');

return new JsonResponse([
'lifetime' => $maxlifetime,
]);
}
}
4 changes: 4 additions & 0 deletions src/Clastic/BackofficeBundle/Resources/config/routing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="clastic_backoffice_heartbeat" path="/_heartbeat">
<default key="_controller">ClasticBackofficeBundle:Heartbeat:tick</default>
</route>

<import resource="@ClasticUserBundle/Resources/config/routing_backoffice.xml"/>
<import resource="@ClasticNodeBundle/Resources/config/routing_backoffice.xml"/>

Expand Down
17 changes: 17 additions & 0 deletions src/Clastic/BackofficeBundle/Resources/public/scripts/heartbeat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

(function(){
var tickUrl = '/admin/_heartbeat';

$.ajax(tickUrl, {
success: function (data) {
setupHeartbeat(data.lifetime);
}
});

var setupHeartbeat = function (timeout) {
window.setInterval(function() {
$.ajax(tickUrl);
}, timeout * 900);
};
})();

0 comments on commit 7f01c92

Please sign in to comment.