Bug 32426: Changes for opac-memberentry
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Thu, 15 Dec 2022 15:03:47 +0000 (16:03 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 27 Mar 2023 10:49:52 +0000 (12:49 +0200)
Test plan:
Enable self registration, pick a default category too for it.
The changes will be tested later with a plugin, but now change
Koha/Patron.pm as follows:
 sub _generate_userid_legacy { # as we always did
     my ($self) = @_;
+return $self;
So, add the return $self line only.
Restart all. Try to register an account on OPAC.
You should see an alert about problems processing your registration.
Undo the change in Patron.pm and restart all.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt
opac/opac-memberentry.pl

index b051a14..f9eb612 100644 (file)
                     </div>
                 [% END %]
 
+                [% IF error_type OR error_info %]
+                    <div class="alert alert-error"><li>
+                        <p>There were problems processing your registration. Please contact your library for help.</p>
+                        [% IF error_type == 'Koha::Exceptions::Patron::InvalidUserid' %]
+                            <p>Error: Userid is not valid</p>
+                        [% ELSE %]
+                            <p>Error [% error_type %]: [% error_info %]</p>
+                        [% END %]
+                    </li></div>
+                [% END %]
+
                 [% IF failed_captcha %]
                     <div class="alert alert-warning">You typed in the wrong characters in the box before submitting. Please try again.</div>
                 [% END %]
index 0115d78..a09bcb8 100755 (executable)
@@ -22,6 +22,7 @@ use Digest::MD5 qw( md5_base64 md5_hex );
 use JSON qw( to_json );
 use List::MoreUtils qw( any each_array uniq );
 use String::Random qw( random_string );
+use Try::Tiny;
 
 use C4::Auth qw( get_template_and_user );
 use C4::Output qw( output_html_with_http_headers );
@@ -213,6 +214,19 @@ if ( $action eq 'create' ) {
             C4::Letters::SendQueuedMessages({ message_id => $message_id });
         }
         else {
+            $borrower{password}         ||= Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode}));
+            my $consent_dt = delete $borrower{gdpr_proc_consent};
+            my $patron;
+            try {
+                $patron = Koha::Patron->new( \%borrower )->store;
+                Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $patron && $consent_dt;
+            } catch {
+                my $type = ref($_);
+                my $info = "$_";
+                $template->param( error_type => $type, error_info => $info );
+                $template->param( borrower => \%borrower );
+            };
+
             ( $template, $borrowernumber, $cookie ) = get_template_and_user(
                 {
                     template_name   => "opac-registration-confirmation.tt",
@@ -220,12 +234,8 @@ if ( $action eq 'create' ) {
                     query           => $cgi,
                     authnotrequired => 1,
                 }
-            );
+            ) if $patron;
 
-            $borrower{password}         ||= Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode}));
-            my $consent_dt = delete $borrower{gdpr_proc_consent};
-            my $patron = Koha::Patron->new( \%borrower )->store;
-            Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $consent_dt;
             if ( $patron ) {
                 $patron->extended_attributes->filter_by_branch_limitations->delete;
                 $patron->extended_attributes($attributes);
@@ -280,8 +290,6 @@ if ( $action eq 'create' ) {
                     $patron->notify_library_of_registration($notify_library);
                 }
 
-            } else {
-                # FIXME Handle possible errors here
             }
             $template->param(
                 PatronSelfRegistrationAdditionalInstructions =>