Working on session warning

This commit is contained in:
Hillel Coren 2015-09-27 00:08:59 +03:00
parent 902f8948b0
commit 8337bc9669
4 changed files with 36 additions and 14 deletions

View File

@ -1,7 +1,6 @@
<?php namespace App\Http\Controllers; <?php namespace App\Http\Controllers;
use Response; use Response;
use Request;
use Redirect; use Redirect;
use Auth; use Auth;
use View; use View;
@ -99,6 +98,6 @@ class HomeController extends BaseController
public function keepAlive() public function keepAlive()
{ {
return RESULT_SUCCESS; return Auth::check() ? RESULT_SUCCESS : RESULT_FAILURE;
} }
} }

View File

@ -29,7 +29,7 @@ return [
| |
*/ */
'lifetime' => env('SESSION_LIFETIME', 1), 'lifetime' => env('SESSION_LIFETIME', 120),
'expire_on_close' => false, 'expire_on_close' => false,

View File

@ -791,5 +791,7 @@ return array(
'referral_code' => 'Referral Code', 'referral_code' => 'Referral Code',
'last_sent_on' => 'Last sent on :date', 'last_sent_on' => 'Last sent on :date',
'page_expire' => 'This page will expire soon, :click_here to keep working',
); );

View File

@ -236,20 +236,37 @@
} }
var redirectTimer = null;
function startWarnSessionTimeout() {
var oneMinute = 1000 * 60;
var twoMinutes = oneMinute * 2;
var twoHours = oneMinute * 120;
setTimeout(function() {
warnSessionExpring();
}, (twoHours - twoMinutes));
}
function warnSessionExpring() {
$("#keepAliveDiv").fadeIn();
redirectTimer = setTimeout(function() {
NINJA.formIsChanged = false;
window.location = '{{ URL::to('/dashboard') }}';
}, 1000 * 60);
}
// keep the token cookie valid to prevent token mismatch errors // keep the token cookie valid to prevent token mismatch errors
function keepAlive() { function keepAlive() {
window.setTimeout(function() { clearTimeout(redirectTimer);
$.get('{{ URL::to('/keep_alive') }}', function(data) { $('#keepAliveDiv').fadeOut();
keepAlive(); $.get('{{ URL::to('/keep_alive') }}');
}) startWarnSessionTimeout();
}, 1000 * 60 * 60); }
}
$(function() { $(function() {
keepAlive(); startWarnSessionTimeout();
window.setTimeout(function() { window.setTimeout(function() {
$(".alert-hide").fadeOut(500); $(".alert-hide").fadeOut();
}, 3000); }, 3000);
$('#search').blur(function(){ $('#search').blur(function(){
@ -483,6 +500,10 @@
<br/> <br/>
<div class="container"> <div class="container">
<div class="alert alert-warning" id="keepAliveDiv" style="display:none">
{!! trans('texts.page_expire', ['click_here' => link_to('#', trans('texts.click_here'), ['onclick' => 'keepAlive()'])]) !!}
</div>
@if (Session::has('warning')) @if (Session::has('warning'))
<div class="alert alert-warning">{!! Session::get('warning') !!}</div> <div class="alert alert-warning">{!! Session::get('warning') !!}</div>
@endif @endif
@ -499,11 +520,11 @@
@endif @endif
@if (Session::has('error')) @if (Session::has('error'))
<div class="alert alert-danger">{!! Session::get('error') !!}</div> <div class="alert alert-danger">{!! Session::get('error') !!}</div>
@endif @endif
@if (!isset($showBreadcrumbs) || $showBreadcrumbs) @if (!isset($showBreadcrumbs) || $showBreadcrumbs)
{!! HTML::breadcrumbs() !!} {!! HTML::breadcrumbs() !!}
@endif @endif
@yield('content') @yield('content')