Bugzilla – Attachment 182023 Details for
Bug 36586
Self-checkouts will get CSRF errors if left inactive for 8 hours
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36586: Define self-checkin timer using Javascript class
Bug-36586-Define-self-checkin-timer-using-Javascri.patch (text/plain), 12.73 KB, created by
Jonathan Druart
on 2025-05-07 13:09:41 UTC
(
hide
)
Description:
Bug 36586: Define self-checkin timer using Javascript class
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2025-05-07 13:09:41 UTC
Size:
12.73 KB
patch
obsolete
>From 99f6a4ee6971413238f40a5c4920efde20dd90ad Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Wed, 4 Dec 2024 21:10:55 +0000 >Subject: [PATCH] Bug 36586: Define self-checkin timer using Javascript class > >This patch rewrites the self-checkin timer code to be defined in a >Javascript class which is then instantiated in once in sci-main.pl >depending on certain conditions (ie a barcode has been entered, or >an item has been checked in by barcode). > >To test: >1 - Set SelfCheckinTimeout to a small value like 5 >2 - Go to the self checkin: > http://localhost:8080/cgi-bin/koha/sci/sci-main.pl >3 - Sign in as the SCI user >4 - Watch the page, it should refresh every 5 seconds >5 - Confirm that moving the mouse/typing prevents the reset >6 - Check in an item >7 - Wait and confirm reload of main page happens when idle >8 - Confirm mouse/typing prevents refresh >9 - Sign off! > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> > >Bug 36586: Add sc-timer to sco > >This patch implements the timer form the last patch on the sco > >To test: >1 - Set SelfCheckTimout to 5 or something low for testing >2 - Go to the self checkout module >3 - Either sign in or confirm you have AutoSelfCheck user setup >4 - Observe the page reloads every 5 seocnds (or as you set above) >5 - Sign in as a patron >6 - Confirm on idle you are logged out to home page >7 - Sign off! > >Signed-off-by: David Nind <david@davidnind.com> >Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> > >Bug 36586: Fix tidy >--- > .../bootstrap/en/modules/sci/sci-main.tt | 43 ++++++++----------- > .../bootstrap/en/modules/sco/sco-main.tt | 32 +++++++++----- > koha-tmpl/opac-tmpl/bootstrap/js/timeout.js | 39 +++++++++++++++++ > opac/sci/sci-main.pl | 4 -- > opac/sco/sco-main.pl | 7 --- > 5 files changed, 79 insertions(+), 46 deletions(-) > create mode 100644 koha-tmpl/opac-tmpl/bootstrap/js/timeout.js > >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt >index 7bfa4dd8c31..1a6330580ad 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt >@@ -189,7 +189,7 @@ > </div> > <!-- / .main --> > >-[%# Help modal %] >+[% # Help modal %] > <div id="helpModal" class="modal" tabindex="-1" role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true"> > <div class="modal-dialog"> > <div class="modal-content"> >@@ -222,6 +222,7 @@ > > [% INCLUDE 'opac-bottom.inc' %] > [% BLOCK jsinclude %] >+ [% Asset.js('js/timeout.js') | $raw %] > <script> > function mungeHistory() { > // prevent back button from allowing form resubmission >@@ -272,6 +273,7 @@ > $("#sci_barcodes_table").show(); > $('#sci_checkin_button').show(); > $('#sci_refresh_button').show(); >+ login_timeout(); > > // Add barcode to the array > barcodes.push(barcode); >@@ -291,31 +293,24 @@ > dofocus(); > }); > >- >- var idleTime = 0; >- $(document).ready(function () { >- //Increment the idle time counter every second >- var idleInterval = setInterval(timerIncrement, 1000); >- >- //Zero the idle timer on mouse movement. >- $(this).mousemove(function (e) { >- idleTime = 0; >- }); >- $(this).keypress(function (e) { >- idleTime = 0; >+ document.addEventListener("DOMContentLoaded",function(){ >+ if ( document.querySelector('#sci_finish_button,#sci_append_button') ){ >+ login_timeout(); >+ } >+ }); >+ function login_timeout(){ >+ //NOTE: There can only be 1 sci_login_timer at a time >+ if ( ! window.sci_login_timer ){ >+ const idleTimeout = "[% Koha.Preference('SelfCheckInTimeOut') || 120 | html %]"; >+ const home_href = "/cgi-bin/koha/sci/sci-main.pl"; >+ const sci_timer = new sc_timer({ >+ "idle_timeout": idleTimeout, >+ "redirect_url": home_href > }); >- }); >- >- function timerIncrement() { >- if ( $("#sci_finish_button").is(":visible") || $("#sci_refresh_button").is(":visible") ) { >- idleTime = idleTime + 1; >- idleTimeout = [% refresh_timeout | html %]; >- if (idleTime >= idleTimeout ) { >- location.href = '/cgi-bin/koha/sci/sci-main.pl'; >- } >- } >+ window.sci_login_timer = sci_timer; >+ sci_timer.start_timer(); > } >- >+ } > > function checkBarcodeInput() { > var inputField = document.getElementById("barcode_input"); >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt >index d2d87448b2f..84c20c616be 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt >@@ -55,6 +55,7 @@ > [% END %] > [% Asset.js('js/Gettext.js') | $raw %] > [% Asset.js('js/i18n.js') | $raw %] >+[% Asset.js('js/timeout.js') | $raw %] > </head> > <body id="sco_main" class="sco"> > <div id="wrapper"> >@@ -328,7 +329,7 @@ > <input type="password" id="patronpw" class="form-control" size="20" name="patronpw" autocomplete="off" /> > </div> > <div class="col-md-12"> >- <button type="submit" class="btn btn-primary">Log in</button> >+ <button id="sco_patron_login" type="submit" class="btn btn-primary">Log in</button> > </div> > </div> > <!-- /.row --> >@@ -341,7 +342,7 @@ > <input type="text" id="patronid" class="form-control focus" size="20" name="patronid" autocomplete="off" /> > </div> > <div class="col-md-12"> >- <button type="submit" class="btn btn-primary">Submit</button> >+ <button id="sco_patron_login" type="submit" class="btn btn-primary">Submit</button> > </div> > </div> > <!-- /.row --> >@@ -401,11 +402,23 @@ > history.replaceState(null, document.title, window.location.href); > } > } >- var mainTimeout; >- function sco_init() { >- mainTimeout = setTimeout(function() { >- location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; >- }, [% SelfCheckTimeout | html %]); >+ document.addEventListener("DOMContentLoaded",function(){ >+ if ( document.querySelector('#sco_patron_login,#logout_form') ){ >+ login_timeout(); >+ } >+ }); >+ function login_timeout(){ >+ //NOTE: There can only be 1 sco_login_timer at a time >+ if ( ! window.sco_login_timer ){ >+ const idleTimeout = "[% Koha.Preference('SelfCheckTimeout') || 120 | html %]"; >+ const home_href = "/cgi-bin/koha/sco/sco-main.pl?op=logout"; >+ const sco_timer = new sc_timer({ >+ "idle_timeout": idleTimeout, >+ "redirect_url": home_href >+ }); >+ window.sco_login_timer = sco_timer; >+ sco_timer.start_timer(); >+ } > } > function dofocus() { // named function req'd for body onload event by some FF and IE7 security models > // alert("dofocus called"); >@@ -458,7 +471,6 @@ > > $(document).ready(function() { > dofocus(); >- [% IF ( patronid ) %]sco_init();[% END %] > > var dTables = $("#loanTable, #holdst, #finestable"); > dTables.each(function(){ >@@ -490,18 +502,16 @@ > > $("#logout_form").on("click", function(e){ > e.preventDefault(e); >- clearTimeout(mainTimeout); > [% IF Koha.Preference('SelfCheckReceiptPrompt') %] > var confirmStart = Date.now(); > confirmModal("", _("Would you like to print a receipt?"), _("Print receipt and end session"), _("End session"), function(result) { >- if ( result && (Date.now() - confirmStart) < [% SelfCheckTimeout | html %] ) { >+ if ( result && (Date.now() - confirmStart) < [% Koha.Preference('SelfCheckTimeout') | html %] ) { > var win = window.open("/cgi-bin/koha/sco/printslip.pl?print=qslip"); > location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; > } else { > location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; > } > }) >- sco_init(); > [% ELSE %] > location.href = '/cgi-bin/koha/sco/sco-main.pl?op=logout'; > [% END %] >diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js b/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js >new file mode 100644 >index 00000000000..6c508d14c07 >--- /dev/null >+++ b/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js >@@ -0,0 +1,39 @@ >+class sc_timer { >+ constructor(args) { >+ const idle_timeout = args["idle_timeout"]; >+ const redirect_url = args["redirect_url"]; >+ if (idle_timeout) { >+ this.idle_timeout = idle_timeout; >+ } >+ if (redirect_url) { >+ this.redirect_url = redirect_url; >+ } >+ this.idle_time = 0; >+ } >+ >+ start_timer() { >+ const self = this; >+ //Increment the idle time counter every 1 second >+ const idle_interval = setInterval(function () { >+ self._timer_increment(); >+ }, 1000); >+ >+ document.addEventListener("mousemove", function () { >+ self.reset_timer(); >+ }); >+ document.addEventListener("keypress", function () { >+ self.reset_timer(); >+ }); >+ } >+ >+ reset_timer() { >+ this.idle_time = 0; >+ } >+ >+ _timer_increment() { >+ this.idle_time++; >+ if (this.idle_time >= this.idle_timeout) { >+ location.href = this.redirect_url; >+ } >+ } >+} >diff --git a/opac/sci/sci-main.pl b/opac/sci/sci-main.pl >index 34d433a53fc..d254347b5be 100755 >--- a/opac/sci/sci-main.pl >+++ b/opac/sci/sci-main.pl >@@ -102,8 +102,4 @@ if ( $op eq 'cud-check_in' ) { > $template->param( success => \@success, errors => \@errors, checkins => 1 ); > } > >-# Make sure timeout has a reasonable value >-my $timeout = C4::Context->preference('SelfCheckInTimeout') || 120; >-$template->param( refresh_timeout => $timeout ); >- > output_html_with_http_headers $cgi, $cookie, $template->output, undef, { force_no_caching => 1 }; >diff --git a/opac/sco/sco-main.pl b/opac/sco/sco-main.pl >index 9ecae7c76c4..e1cc93d8026 100755 >--- a/opac/sco/sco-main.pl >+++ b/opac/sco/sco-main.pl >@@ -74,13 +74,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > } > ); > >-# Get the self checkout timeout preference, or use 120 seconds as a default >-my $selfchecktimeout = 120000; >-if ( C4::Context->preference('SelfCheckTimeout') ) { >- $selfchecktimeout = C4::Context->preference('SelfCheckTimeout') * 1000; >-} >-$template->param( SelfCheckTimeout => $selfchecktimeout ); >- > # Checks policy laid out by SCOAllowCheckin, defaults to 'on' if preference is undefined > my $allowselfcheckreturns = 1; > if ( defined C4::Context->preference('SCOAllowCheckin') ) { >-- >2.34.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 36586
:
175210
|
175239
|
175919
|
181645
|
181646
|
181694
|
181695
|
181874
|
181875
|
182022
| 182023