From c907eec11bcef47f66148753a0334f082cdaa899 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Thu, 15 Dec 2022 16:03:47 +0100 Subject: [PATCH] Bug 32426: Changes for opac-memberentry Content-Type: text/plain; charset=utf-8 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 --- .../bootstrap/en/modules/opac-memberentry.tt | 11 ++++++++++ opac/opac-memberentry.pl | 22 +++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt index 04c8c3e655..0183280125 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-memberentry.tt @@ -125,6 +125,17 @@ [% END %] + [% IF error_type OR error_info %] +
  • +

    There were problems processing your registration. Please contact your library for help.

    + [% IF error_type == 'Koha::Exceptions::Patron::InvalidUserid' %] +

    Error: Userid is not valid

    + [% ELSE %] +

    Error [% error_type %]: [% error_info %]

    + [% END %] +
  • + [% END %] + [% IF failed_captcha %]
    You typed in the wrong characters in the box before submitting. Please try again.
    [% END %] diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index 0115d78f98..a09bcb8bc1 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -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 => -- 2.30.2