Added warning when form token is about to expire

This commit is contained in:
Hillel Coren 2015-09-28 23:37:32 +03:00
parent 69034c6d71
commit f8b449a471
10 changed files with 58 additions and 48 deletions

View File

@ -98,6 +98,6 @@ class HomeController extends BaseController
public function keepAlive()
{
return Auth::check() ? RESULT_SUCCESS : RESULT_FAILURE;
return RESULT_SUCCESS;
}
}

View File

@ -1,6 +1,5 @@
<?php namespace App\Http\Controllers;
use App;
use Auth;
use Session;
use Utils;
@ -81,7 +80,7 @@ class InvoiceController extends BaseController
{
$invitationKey = Session::get('invitation_key');
if (!$invitationKey) {
return Redirect::to('/setup');
app()->abort(404);
}
$invitation = Invitation::with('account')->where('invitation_key', '=', $invitationKey)->first();
@ -109,7 +108,6 @@ class InvoiceController extends BaseController
public function getClientDatatable()
{
//$accountId = Auth::user()->account_id;
$search = Input::get('sSearch');
$invitationKey = Session::get('invitation_key');
$invitation = Invitation::where('invitation_key', '=', $invitationKey)->first();
@ -177,13 +175,13 @@ class InvoiceController extends BaseController
$invitation = Invitation::where('invitation_key', '=', $invitationKey)->first();
if (!$invitation) {
App::abort(404, trans('texts.invoice_not_found'));
app()->abort(404, trans('texts.invoice_not_found'));
}
$invoice = $invitation->invoice;
if (!$invoice || $invoice->is_deleted) {
App::abort(404, trans('texts.invoice_not_found'));
app()->abort(404, trans('texts.invoice_not_found'));
}
$invoice->load('user', 'invoice_items', 'invoice_design', 'account.country', 'client.contacts', 'client.country');
@ -191,7 +189,7 @@ class InvoiceController extends BaseController
$account = $client->account;
if (!$client || $client->is_deleted) {
App::abort(404, trans('texts.invoice_not_found'));
app()->abort(404, trans('texts.invoice_not_found'));
}
if ($account->subdomain) {

View File

@ -51,7 +51,7 @@ class PaymentController extends BaseController
{
$invitationKey = Session::get('invitation_key');
if (!$invitationKey) {
return Redirect::to('/setup');
app()->abort(404);
}
$invitation = Invitation::with('account')->where('invitation_key', '=', $invitationKey)->first();

View File

@ -71,7 +71,7 @@ class QuoteController extends BaseController
{
$invitationKey = Session::get('invitation_key');
if (!$invitationKey) {
return Redirect::to('/setup');
app()->abort(404);
}
$invitation = Invitation::with('account')->where('invitation_key', '=', $invitationKey)->first();

View File

@ -169,6 +169,7 @@ class ContactMailer extends Mailer
'$client' => $data['client']->getDisplayName(),
'$account' => $data['account']->getDisplayName(),
'$contact' => $data['invitation']->contact->getDisplayName(),
'$firstName' => $data['invitation']->contact->first_name,
'$amount' => Utils::formatMoney($data['amount'], $data['client']->getCurrencyId()),
'$invoice' => $data['invitation']->invoice->invoice_number,
'$quote' => $data['invitation']->invoice->invoice_number,

View File

@ -145,6 +145,7 @@
'amount',
'link',
'contact',
'firstName',
'invoice',
'quote'
];
@ -156,6 +157,7 @@
formatMoney(100),
"{{ Auth::user()->account->getSiteUrl() . '...' }}",
"Contact Name",
"First Name",
"0001",
"0001"
];

View File

@ -235,36 +235,7 @@
@endif
}
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
function keepAlive() {
clearTimeout(redirectTimer);
$('#keepAliveDiv').fadeOut();
$.get('{{ URL::to('/keep_alive') }}');
startWarnSessionTimeout();
}
$(function() {
startWarnSessionTimeout();
window.setTimeout(function() {
$(".alert-hide").fadeOut();
}, 3000);
@ -495,14 +466,10 @@
</div>
</nav>
<br/>
<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>
@include('partials.warn_session', ['redirectTo' => '/dashboard'])
@if (Session::has('warning'))
<div class="alert alert-warning">{!! Session::get('warning') !!}</div>

View File

@ -113,6 +113,7 @@
<script type="text/javascript">
NINJA.formIsChanged = {{ isset($formIsChanged) && $formIsChanged ? 'true' : 'false' }};
$(function() {
$('form.warn-on-exit input, form.warn-on-exit textarea, form.warn-on-exit select').change(function() {
NINJA.formIsChanged = true;

View File

@ -0,0 +1,39 @@
<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>
</div>
<script type="text/javascript">
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($redirectTo) }}';
}, 1000 * 60);
}
// keep the token cookie valid to prevent token mismatch errors
function keepAlive() {
clearTimeout(redirectTimer);
$('#keepAliveDiv').fadeOut();
$.get('{{ URL::to('/keep_alive') }}');
startWarnSessionTimeout();
}
$(function() {
if ($('form.warn-on-exit').length > 0) {
startWarnSessionTimeout();
}
});
</script>

View File

@ -199,8 +199,10 @@ table.table thead .sorting_desc_disabled:after { content: '' !important }
</div>
</nav>
<div class="container">
@include('partials.warn_session', ['redirectTo' => '/'])
@if (Session::has('warning'))
<div class="alert alert-warning">{!! Session::get('warning') !!}</div>
@endif