Bugzilla – Attachment 180872 Details for
Bug 36197
Allow unauthenticated ILL requests in the OPAC
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36197: (QA follow-up): Add public form captcha
Bug-36197-QA-follow-up-Add-public-form-captcha.patch (text/plain), 5.97 KB, created by
Pedro Amorim
on 2025-04-11 14:24:05 UTC
(
hide
)
Description:
Bug 36197: (QA follow-up): Add public form captcha
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2025-04-11 14:24:05 UTC
Size:
5.97 KB
patch
obsolete
>From e5769ff2747c5f2e07d1d1ace4a1f3fcd1108b41 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@openfifth.co.uk> >Date: Fri, 11 Apr 2025 10:32:36 +0000 >Subject: [PATCH] Bug 36197: (QA follow-up): Add public form captcha > >Feedback provided by David Cook + Matthias Meusburger at KohaCon24 >--- > Koha/ILL/Backend/Standard.pm | 6 ++++-- > Koha/ILL/Backend/opac-includes/create.inc | 18 ++++++++++++++++++ > Koha/ILL/Request.pm | 18 ++++++++++-------- > opac/opac-illrequests.pl | 21 +++++++++++++++++++-- > 4 files changed, 51 insertions(+), 12 deletions(-) > >diff --git a/Koha/ILL/Backend/Standard.pm b/Koha/ILL/Backend/Standard.pm >index 36d4ea79408..47ae66f6809 100644 >--- a/Koha/ILL/Backend/Standard.pm >+++ b/Koha/ILL/Backend/Standard.pm >@@ -296,8 +296,10 @@ sub create { > C4::Context->preference("ILLOpacUnauthenticatedRequest") && !$other->{'cardnumber'}; > if ($unauthenticated_request) { > ( $failed, $result ) = _validate_form_params( $other, $result, $params ); >- if ( !Koha::ILL::Request::unauth_request_data_check($other) ) { >- $result->{status} = "missing_unauth_data"; >+ return $result if $failed; >+ my $unauth_request_error = Koha::ILL::Request::unauth_request_data_error($other); >+ if ($unauth_request_error) { >+ $result->{status} = $unauth_request_error; > $result->{value} = $params; > $failed = 1; > } >diff --git a/Koha/ILL/Backend/opac-includes/create.inc b/Koha/ILL/Backend/opac-includes/create.inc >index fa2bad04236..b4d5e2c2e58 100644 >--- a/Koha/ILL/Backend/opac-includes/create.inc >+++ b/Koha/ILL/Backend/opac-includes/create.inc >@@ -27,6 +27,8 @@ > <div class="alert alert-warning"> > <strong>Please note:</strong> The library you chose is invalid. > </div> >+[% ELSIF whole.status == 'failed_captcha' %] >+ <div class="alert alert-warning">You typed in the wrong characters in the box before submitting. Please try again.</div> > [% ELSE %] > <p>Unhandled error</p> > [% END %] >@@ -119,6 +121,22 @@ > [% INCLUDE "${cwd}/shared-includes/forms/${type}.inc" %] > [% END %] > [% INCLUDE "${cwd}/shared-includes/custom_fields.inc" %] >+ [% IF whole.value.other.type && unauthenticated_ill && !logged_in_user%] >+ <fieldset class="rows" id="illrequest_captcha"> >+ <legend>Verification</legend> >+ <ol> >+ <li> >+ <label for="captcha" class="required">Verification:</label> >+ >+ <input type="text" name="captcha" id="captcha" class="form-control input-fluid" style="text-transform: uppercase;" /> >+ <div class="required_label required">Required</div> >+ <input type="hidden" name="captcha_digest" value="[% captcha_digest | html %]" /> >+ >+ <span class="hint">Please type the following characters into the preceding box: <strong>[% captcha | html %]</strong></span> >+ </li> >+ </ol> >+ </fieldset> >+ [% END %] > <fieldset class="action"> > <input id="ill-submit" class="btn btn-primary" type="submit" value="Create"/> > <a class="cancel" href="/cgi-bin/koha/opac-illrequests.pl">Cancel</a> >diff --git a/Koha/ILL/Request.pm b/Koha/ILL/Request.pm >index 70fbe9f49bf..265c2b8f876 100644 >--- a/Koha/ILL/Request.pm >+++ b/Koha/ILL/Request.pm >@@ -1968,23 +1968,25 @@ sub add_unauthenticated_data { > ); > } > >-=head3 unauth_request_data_check >+=head3 unauth_request_data_error > >- unauth_request_data_check($metadata); >+ unauth_request_data_error($metadata); > >-Checks if unauthenticated request data is present >+Checks if unauthenticated request data errored, returns error_code if so, else 0 > > =cut > >-sub unauth_request_data_check { >+sub unauth_request_data_error { > my ($metadata) = @_; > >- return 1 unless C4::Context->preference("ILLOpacUnauthenticatedRequest"); >- >- return >- $metadata->{unauthenticated_first_name} >+ return 0 unless C4::Context->preference("ILLOpacUnauthenticatedRequest"); >+ return 'missing_unauth_data' >+ unless $metadata->{unauthenticated_first_name} > && $metadata->{unauthenticated_last_name} > && $metadata->{unauthenticated_email}; >+ >+ return 'failed_captcha' if $metadata->{failed_captcha}; >+ return 0; > } > > =head3 append_to_note >diff --git a/opac/opac-illrequests.pl b/opac/opac-illrequests.pl >index ad7ef34c8f3..6db3c3ab7d4 100755 >--- a/opac/opac-illrequests.pl >+++ b/opac/opac-illrequests.pl >@@ -24,8 +24,10 @@ use JSON qw( encode_json ); > use CGI qw ( -utf8 ); > use C4::Auth qw( get_template_and_user ); > use C4::Koha; >-use C4::Output qw( output_html_with_http_headers ); >-use POSIX qw( strftime ); >+use C4::Output qw( output_html_with_http_headers ); >+use Digest::MD5 qw( md5_base64 ); >+use POSIX qw( strftime ); >+use String::Random qw( random_string ); > > use Koha::ILL::Request::Config; > use Koha::ILL::Requests; >@@ -119,6 +121,15 @@ if ( $op eq 'list' ) { > my $req = Koha::ILL::Request->new; > $template->param( backends => $backends ); > } else { >+ >+ if ( C4::Context->preference('ILLOpacUnauthenticatedRequest') && !$patron ) { >+ my $captcha = random_string("CCCCC"); >+ $template->param( >+ captcha => $captcha, >+ captcha_digest => md5_base64($captcha), >+ ); >+ } >+ > $params->{backend} = 'Standard' if $params->{backend} eq 'FreeForm'; > my $request = Koha::ILL::Request->new->load_backend( $params->{backend} ); > >@@ -155,6 +166,12 @@ if ( $op eq 'list' ) { > exit; > } > >+ if ( $request->_backend_capability( 'can_create_request', $params ) ) { >+ if ( md5_base64( uc( $params->{captcha} ) ) ne $params->{captcha_digest} ) { >+ $params->{failed_captcha} = 1; >+ } >+ } >+ > $params->{cardnumber} = $patron->cardnumber if $patron; > $params->{branchcode} = $patron->branchcode if $patron; > $params->{opac} = 1; >-- >2.39.5
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 36197
:
171358
|
171359
|
171360
|
171361
|
171362
|
171363
|
171364
|
171365
|
171366
|
171367
|
171368
|
171369
|
171370
|
171371
|
174495
|
174496
|
174497
|
174498
|
174499
|
174500
|
174501
|
174502
|
174503
|
174504
|
174505
|
174506
|
174507
|
174508
|
176564
|
176565
|
176680
|
176723
|
176724
|
176726
|
176727
|
179764
|
179765
|
179766
|
179767
|
179769
|
179770
|
179771
|
179772
|
179773
|
179774
|
179775
|
179776
|
179777
|
179778
|
179779
|
179780
|
179781
|
179782
|
179783
|
179784
|
179785
|
180850
|
180851
|
180852
|
180853
|
180854
|
180855
|
180856
|
180857
|
180858
|
180859
|
180860
|
180861
|
180862
|
180863
|
180864
|
180865
|
180866
|
180867
|
180868
|
180869
|
180870
|
180871
|
180872
|
180873
|
181073
|
181074
|
181075
|
181076
|
181077
|
181078
|
181079
|
181080
|
181081
|
181082
|
181083
|
181084
|
181085
|
181086
|
181087
|
181088
|
181089
|
181090
|
181091
|
181092
|
181093
|
181094
|
181095
|
181096
|
181097
|
181098
|
181592