From b494601646bfa150ce681912fbe7283ba250f463 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 4 Nov 2024 02:19:35 +0000 Subject: [PATCH] Bug 25090 [WIP]: Redirect OPAC self reg verification email to the library So they can moderate and activate accounts made via OPAC self registration Sponsored-by: Mental Health Education & Resource Centre --- Koha/Patron.pm | 21 ++-- .../modules/opac-registration-email-sent.tt | 18 +++- opac/opac-memberentry.pl | 95 +++++++++++++------ 3 files changed, 92 insertions(+), 42 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index bc031f8bcf9..b69a92d9ec9 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -2796,16 +2796,19 @@ sub notify_library_of_registration { || C4::Context->preference('KohaAdminEmailAddress'); } - my $message_id = C4::Letters::EnqueueLetter( - { - letter => $letter, - borrowernumber => $self->borrowernumber, - to_address => $to_address, - message_transport_type => 'email' + unless ( C4::Context->preference("PatronSelfRegistrationVerifyByEmail") eq "library" ) { + # Only receive one of the OPAC_REG or OPAC_REG_VERIFY_LIB emails + my $message_id = C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $self->borrowernumber, + to_address => $to_address, + message_transport_type => 'email' + } + ) or warn "can't enqueue letter $letter"; + if ($message_id) { + return 1; } - ) or warn "can't enqueue letter $letter"; - if ( $message_id ) { - return 1; } } } diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-registration-email-sent.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-registration-email-sent.tt index abbd92032a3..771d91c7db1 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-registration-email-sent.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-registration-email-sent.tt @@ -29,13 +29,21 @@
[% END %]
-

Please confirm your registration

-
+ [% IF Koha.Preference('PatronSelfRegistrationVerifyByEmail') == "library" %] +

Your account is pending confirmation

+
-

A confirmation email will be sent shortly to the email address [% email | html %].

+

An email has been sent to the library to confirm the activation of your account.

+
+ [% ELSE %] +

Please confirm your registration

+
-

Your account will not be activated until you follow the link provided in the confirmation email.

-
+

A confirmation email will be sent shortly to the email address [% email | html %].

+ +

Your account will not be activated until you follow the link provided in the confirmation email.

+
+ [% END %]
diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl index b671dde7c04..b11c3abb2a9 100755 --- a/opac/opac-memberentry.pl +++ b/opac/opac-memberentry.pl @@ -177,11 +177,7 @@ if ( $op eq 'cud-create' ) { die "Branchcode not allowed"; # They hack the form } else { - if ( - C4::Context->preference( - 'PatronSelfRegistrationVerifyByEmail') - ) - { + if ( C4::Context->preference('PatronSelfRegistrationVerifyByEmail') ne "off" ) { ( $template, $borrowernumber, $cookie ) = get_template_and_user( { template_name => "opac-registration-email-sent.tt", @@ -190,38 +186,81 @@ if ( $op eq 'cud-create' ) { authnotrequired => 1, } ); - $template->param( 'email' => $borrower{'email'} ); + $template->param( 'email' => $borrower{'email'} ) + if ( C4::Context->preference('PatronSelfRegistrationVerifyByEmail') eq "patron" ); - my $verification_token = md5_hex( time().{}.rand().{}.$$ ); + my $verification_token = md5_hex( time() . {} . rand() . {} . $$ ); while ( Koha::Patron::Modifications->search( { verification_token => $verification_token } )->count() ) { - $verification_token = md5_hex( time().{}.rand().{}.$$ ); + $verification_token = md5_hex( time() . {} . rand() . {} . $$ ); } - $borrower{password} = Koha::AuthUtils::generate_password(Koha::Patron::Categories->find($borrower{categorycode})) unless $borrower{password}; + $borrower{password} = + Koha::AuthUtils::generate_password( Koha::Patron::Categories->find( $borrower{categorycode} ) ) + unless $borrower{password}; $borrower{verification_token} = $verification_token; $borrower{extended_attributes} = to_json($attributes); Koha::Patron::Modification->new( \%borrower )->store(); - #Send verification email - my $letter = C4::Letters::GetPreparedLetter( - module => 'members', - letter_code => 'OPAC_REG_VERIFY', - lang => 'default', # Patron does not have a preferred language defined yet - tables => { - borrower_modifications => $verification_token, - }, - ); - - my $message_id = C4::Letters::EnqueueLetter( - { - letter => $letter, - message_transport_type => 'email', - to_address => $borrower{'email'}, - from_address => - C4::Context->preference('KohaAdminEmailAddress'), + my $message_id; + + if ( C4::Context->preference('PatronSelfRegistrationVerifyByEmail') eq "library" ) { + + #Send verification email + my $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => 'OPAC_REG_VERIFY_LIB', + lang => 'default', # Patron does not have a preferred language defined yet + tables => { + 'borrower_modifications' => $verification_token, + }, + ); + + my $email_patron_registrations = C4::Context->preference('EmailPatronRegistrations'); + my $to_address; + if ( $email_patron_registrations eq "BranchEmailAddress" ) { + my $library = Koha::Libraries->find( $borrower{branchcode} ); + $to_address = $library->inbound_email_address; + } elsif ( $email_patron_registrations eq "KohaAdminEmailAddress" ) { + $to_address = C4::Context->preference('ReplytoDefault') + || C4::Context->preference('KohaAdminEmailAddress'); + } else { + $to_address = + C4::Context->preference('EmailAddressForPatronRegistrations') + || C4::Context->preference('ReplytoDefault') + || C4::Context->preference('KohaAdminEmailAddress'); } - ); + + $message_id = C4::Letters::EnqueueLetter( + { + letter => $letter, + message_transport_type => 'email', + to_address => $to_address, + from_address => C4::Context->preference('KohaAdminEmailAddress'), + } + ); + + } else { + + #Send verification email + my $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => 'OPAC_REG_VERIFY', + lang => 'default', # Patron does not have a preferred language defined yet + tables => { + borrower_modifications => $verification_token, + }, + ); + + $message_id = C4::Letters::EnqueueLetter( + { + letter => $letter, + message_transport_type => 'email', + to_address => $borrower{'email'}, + from_address => C4::Context->preference('KohaAdminEmailAddress'), + } + ); + } C4::Letters::SendQueuedMessages( { message_id => $message_id } ) if $message_id; } else { @@ -444,7 +483,7 @@ sub GetMandatoryFields { if ( $op eq 'cud-create' || $op eq 'new' ) { $mandatory_fields{'email'} = 1 if C4::Context->preference( - 'PatronSelfRegistrationVerifyByEmail'); + 'PatronSelfRegistrationVerifyByEmail') eq "patron"; } return \%mandatory_fields; -- 2.39.5