From f8b449a471b7611b2ce96455c6c6521aef724786 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 28 Sep 2015 23:37:32 +0300 Subject: [PATCH] Added warning when form token is about to expire --- app/Http/Controllers/HomeController.php | 2 +- app/Http/Controllers/InvoiceController.php | 10 ++--- app/Http/Controllers/PaymentController.php | 2 +- app/Http/Controllers/QuoteController.php | 2 +- app/Ninja/Mailers/ContactMailer.php | 1 + .../templates_and_reminders.blade.php | 2 + resources/views/header.blade.php | 39 ++----------------- resources/views/master.blade.php | 5 ++- .../views/partials/warn_session.blade.php | 39 +++++++++++++++++++ resources/views/public/header.blade.php | 4 +- 10 files changed, 58 insertions(+), 48 deletions(-) create mode 100644 resources/views/partials/warn_session.blade.php diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 616b26302ab4..571ac731938c 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -98,6 +98,6 @@ class HomeController extends BaseController public function keepAlive() { - return Auth::check() ? RESULT_SUCCESS : RESULT_FAILURE; + return RESULT_SUCCESS; } } diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index 3545b548f611..7e7b659f850a 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -1,6 +1,5 @@ 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) { diff --git a/app/Http/Controllers/PaymentController.php b/app/Http/Controllers/PaymentController.php index 530a1b5bc5cc..0c64ef15b6dd 100644 --- a/app/Http/Controllers/PaymentController.php +++ b/app/Http/Controllers/PaymentController.php @@ -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(); diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index d6a9e31ce05c..07acaa7eb0b0 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -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(); diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 3dc5305c4861..35af63248360 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -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, diff --git a/resources/views/accounts/templates_and_reminders.blade.php b/resources/views/accounts/templates_and_reminders.blade.php index 5af32b5efb61..347a0c81b435 100644 --- a/resources/views/accounts/templates_and_reminders.blade.php +++ b/resources/views/accounts/templates_and_reminders.blade.php @@ -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" ]; diff --git a/resources/views/header.blade.php b/resources/views/header.blade.php index 2b41dc21431d..8098a95808c4 100644 --- a/resources/views/header.blade.php +++ b/resources/views/header.blade.php @@ -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 @@ - -
-
- - +
+ + @include('partials.warn_session', ['redirectTo' => '/dashboard']) @if (Session::has('warning'))
{!! Session::get('warning') !!}
diff --git a/resources/views/master.blade.php b/resources/views/master.blade.php index 8bbd0cb641c7..93fc0963553e 100644 --- a/resources/views/master.blade.php +++ b/resources/views/master.blade.php @@ -108,12 +108,13 @@ function trackEvent(category, action) {} @endif - + @yield('body') \ No newline at end of file diff --git a/resources/views/public/header.blade.php b/resources/views/public/header.blade.php index 1063e6cb83da..36752c2fd4d5 100644 --- a/resources/views/public/header.blade.php +++ b/resources/views/public/header.blade.php @@ -199,8 +199,10 @@ table.table thead .sorting_desc_disabled:after { content: '' !important }
-
+ + @include('partials.warn_session', ['redirectTo' => '/']) + @if (Session::has('warning'))
{!! Session::get('warning') !!}
@endif