From 5766519acc44da8bdf7d5b22d91195e0bcc7e0aa Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 4 Nov 2024 02:19:35 +0000 Subject: [PATCH] Bug 25090: Redirect OPAC self reg verification email to the library This enhancement changes the PatronSelfRegistrationVerifyByEmail system preference to have the following options: * don't require (same as 0 previously) * patron verifies (same as 1 previously) * library verifies, based on the EmailPatronRegistrations syspref setting If the syspref is set to "based on the EmailPatronRegistrations" setting, this allows the library to redirect the verification email so that they can essentially moderate accounts that self-register via the OPAC. This enhancement also introduces a new notice OPAC_REG_VERIFY_LIB which includes the new account's details and the verification link. To test: 1. Apply patches, install database updates, and restart services (if using ktd, do `koha-upgrade-schema kohadev` then `restart_all`) 2. Go to the staff interface, Koha administration, system preferences. Go to the OPAC tab and find the self-registration and modification section. 3. By default, the PatronSelfRegistrationVerifyByEmail is set to "not required". Change this to "must verify themselves via email". 4. Change EmailPatronRegistrations to anything other than "none" (we're not specifically testing this functionality). 5. Confirm that PatronSelfRegistration is set to "Allow", as are other required preferences (these should be set by default in ktd). 6. Go to the OPAC in another window. You may be automatically logged in, if so, log out. 7. On the homepage, click the "Create an account" link under the login section. 8. Fill in the required fields and submit. 9. In your commandline, go to the database and view the results from the message_queue table (`koha-mysql kohadev` then `select * from message_queue\G`) 10. Confirm there is a queued message to the new account holder with a verification link. Open the verification link in your browser (you may need to swap out the OPACBaseURL if that isn't set correctly) 11. Confirm the account's registration. 12. Repeat step 9. Confirm there is a queued message to whoever you set EmailPatronRegistrations to, confirming a new account was created. 13. Go to your staff interface tab (you may need to log in again). 14. Go to the staff interface, Koha administration, system preferences. Go to the OPAC tab and find the self-registration and modification section. 15. Change PatronSelfRegistrationVerifyByEmail to "must be verified via email sent to EmailPatronRegistrations" 16. Repeat steps 6-9. 17. Confirm there is a queued message to the EmailPatronRegistrations setting with a verification link. Open the verification link in your browser (you may need to swap out the OPACBaseURL if that isn't set correctly) 18. Confirm the account's registration. 19. Confirm the wording on the screen better reflects that you've confirmed someone else's account and provides the login credentials to send them. Sponsored-by: Mental Health Education & Resource Centre --- Koha/Patron.pm | 21 ++-- .../modules/opac-registration-confirmation.tt | 32 +++++-- .../modules/opac-registration-email-sent.tt | 18 +++- opac/opac-memberentry.pl | 95 +++++++++++++------ 4 files changed, 114 insertions(+), 52 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-confirmation.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-registration-confirmation.tt index 6fef58e72a1..a743e6644fc 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-registration-confirmation.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-registration-confirmation.tt @@ -61,9 +61,18 @@

Registration complete!

-

You have successfully registered your new account.

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

You have successfully registered this new account.

+ [% ELSE %] +

You have successfully registered your new account.

+ [% END %] + [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') %] -

To log in, use the following credentials:

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

Please securely provide the following credentials to the account holder so they can log in:

+ [% ELSE %] +

To log in, use the following credentials:

+ [% END %]

Username: @@ -81,13 +90,16 @@

[% END %] -

- [% IF borrower.category.effective_change_password %] - For your convenience, the login box on this page has been pre-filled with this data. Please log in and change your password. - [% ELSE %] - For your convenience, the login box on this page has been pre-filled with this data. Please log in. + [% UNLESS Koha.Preference('PatronSelfRegistrationVerifyByEmail') == "library" %] +

+ [% IF borrower.category.effective_change_password %] + For your convenience, the login box on this page has been pre-filled with this data. Please log in and change your password. + [% ELSE %] + For your convenience, the login box on this page has been pre-filled with this data. Please log in. + [% END %] +

[% END %] -

+ [% END %] [% IF ( PatronSelfRegistrationAdditionalInstructions ) %] @@ -110,13 +122,13 @@
Log in to your account: - [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') %] + [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') && Koha.Preference('PatronSelfRegistrationVerifyByEmail') != "library" %] [% ELSE %] [% END %] - [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') %] + [% IF Koha.Preference('PatronSelfRegistrationPrefillForm') && Koha.Preference('PatronSelfRegistrationVerifyByEmail') != "library" %] [% ELSE %] 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