From 6cca171d53147b487cecc82bce2e192bc1545706 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Wed, 15 Oct 2025 11:05:45 +0200 Subject: [PATCH] Bug 37512: Add a function to reset login attempts When using system preference 'FailedLoginAttempts', a patron's account is blocked after X many failed login attempts on the OPAC. This patch adds, like for "Patron's card has expired" message : * a link to reset login attempts to 0 Link is only displayed if libarian has permission to edit patrons. Reset login attempts to 0 feature uses members/setstatus.pl with resetloginattempts=y like reregistration=y for an expired patron To test: 1. Apply BZ25947 2. Change system preference 'FailedLoginAttempts' to a small number, like 2 3. Go to a patron's account and copy their username (while you're there, change the password and add some fines, too) 4. In the OPAC, try to log in with the username and a wrong password 3 times (you might want to use private browsing) 5. Go back to the patron's account details in the staff interface 6. Note that there is a message : "Patron's account has been locked (due to 3 failed login attempts)" 7. Click on the button to reset the login attempts. 8. There is a modal, click on confirm 9. Notice you have been redirected to the account details page. 10. Notice there is no message anymore, notice you can log in again. 11. Repeat 4-9 using the checkout page, notice you are redirected to the checkout page --- circ/circulation.pl | 4 +++- .../prog/en/includes/patron_messages.inc | 23 +++++++++++++++++++ .../prog/en/modules/circ/circulation.tt | 2 ++ .../intranet-tmpl/prog/en/modules/pos/pay.tt | 1 - members/setstatus.pl | 15 ++++++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/circ/circulation.pl b/circ/circulation.pl index dddd2a1f5f9..c2f10554797 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -776,7 +776,8 @@ if ( $restoreduedatespec || $stickyduedate ) { $template->param( borrowernumber => $borrowernumber, branch => $branch, - was_renewed => scalar $query->param('was_renewed') ? 1 : 0, + was_renewed => scalar $query->param('was_renewed') ? 1 : 0, + was_resetted => scalar $query->param('was_resetted') ? 1 : 0, barcodes => $barcodes, stickyduedate => $stickyduedate, duedatespec => $duedatespec, @@ -814,6 +815,7 @@ $template->param( override_high_holds => $override_high_holds, nopermission => scalar $query->param('nopermission'), noguarantor => scalar $query->param('noguarantor'), + noresetnoguarantor => scalar $query->param('noresetnoguarantor'), autoswitched => $autoswitched, logged_in_user => $logged_in_user, ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc index 25e05462e93..f92906fb430 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/patron_messages.inc @@ -67,6 +67,7 @@ Change password + or [% END %] @@ -435,3 +436,25 @@ [% END %] [% END # /IF patron_messages %] + + diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt index 92e438c86e2..66444e4f6f2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/circulation.tt @@ -127,6 +127,8 @@ [% IF ( noguarantor ) %]
This patron could not be renewed: they need a guarantor.
+ [% ELSIF ( noresetnoguarantor ) %] +
No operation can be performed on this patron while no guarantor has been defined
[% END %] [% IF is_anonymous %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt index ee7251f9c6f..5eb0ebaa4d8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/pos/pay.tt @@ -351,7 +351,6 @@ } }, { "targets": [-5], - "className": "editable", }, { "targets": [-4], "className": "editable_int", diff --git a/members/setstatus.pl b/members/setstatus.pl index 7db0e4f5903..4574ac36547 100755 --- a/members/setstatus.pl +++ b/members/setstatus.pl @@ -39,6 +39,7 @@ my $destination = $input->param("destination") || ''; my $borrowernumber = $input->param('borrowernumber'); my $status = $input->param('status'); my $reregistration = $input->param('reregistration') || ''; +my $op = $input->param('op'); my $dbh = C4::Context->dbh; my $dateexpiry; @@ -47,6 +48,7 @@ my $logged_in_user = Koha::Patrons->find( { userid => $loggedinuserid } ); my $patron = Koha::Patrons->find($borrowernumber); my $cannot_renew = '0'; +my $cannot_reset = '0'; # Ideally we should display a warning on the interface if the logged in user is # not allowed to modify this patron. @@ -64,6 +66,17 @@ if ( $logged_in_user->can_see_patron_infos($patron) ) { $_->rethrow(); } } + } elsif ( $op == "cud-reset_login_attempts" ) { + try { + $patron->login_attempts(0)->store; + $dateexpiry = $patron->renew_account; + } catch { + if ( ref($_) eq 'Koha::Exceptions::Patron::Relationship::NoGuarantor' ) { + $cannot_reset = '1'; + } else { + $_->rethrow(); + } + } } else { my $sth = $dbh->prepare("UPDATE borrowers SET debarred = ?, debarredcomment = '' WHERE borrowernumber = ?"); $sth->execute( $status, $borrowernumber ); @@ -74,6 +87,8 @@ if ( $logged_in_user->can_see_patron_infos($patron) ) { if ( $destination eq "circ" ) { if ($cannot_renew) { print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber&noguarantor=1"); + } elsif ($cannot_reset) { + print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber&noresetnoguarantor=1"); } elsif ($dateexpiry) { print $input->redirect("/cgi-bin/koha/circ/circulation.pl?borrowernumber=$borrowernumber&was_renewed=1"); } else { -- 2.43.0