@@ -, +, @@ ---------- 1a) Patron submits OPAC self reg form 1b) Patron account created immediately 2a) Patron submits OPAC self reg form 2b) Koha sends notice to library to review registration 2c) Library approves reg by clicking verification link in notice 2d) Patron account is created 2e) Password reset link emailed to patron 3a) Patron submits OPAC self reg form 3b) Koha sends verification email to patron 3c) Patron clicks verification link in notice 3d) Patron account is created 4a) Patron submits OPAC self reg form 4b) Koha sends verification email to patron to verify email 4c) Patron clicks verification link in notice 4d) Koha sends notice to library to review registration 4e) Library approves reg by clicking verification link in notice 4f) Patron account created 4g) Password reset link emailed to patron ----------- PatronSelfRegistrationVerifyByEmailToLibrary to "None" - You'll see 1 new OPAC_REG_VERIFY notice sent to the patrons inputted email - You'll see no new STAFF_VER_OPAC_REG notice generated (because - Returns 0 as patron account not added to borrowers table yet - Returns 1 as patron account is in borrower_modifications table - You'll see 1 new PATRON_AND_LIB_VER notice sent to the patrons inputted - You'll see no new OPAC_REG_VERIFY notice as when library & patron - You'll see no new STAFF_VER_OPAC_REG notice generated (it is generated - Returns 0 as patron account not added to borrowers table yet - Returns 1 as patron account is in borrower_modifications table - Returns no new OPAC_REG_VERIFY notice - This returns a row result. Note it contains patron details for librarians - This returns 0 as library still hasn't verified patron account can be - This returns a row result as patron account still in - This returns a row result as patron account created - This returns a row result with the to_address being the patrons email. --- opac/opac-memberentry.pl | 80 +++++++++++++++++++----- opac/opac-password-recovery.pl | 8 ++- opac/opac-registration-verify.pl | 131 ++++++++++++++++++++++++++++++++------- 3 files changed, 180 insertions(+), 39 deletions(-) --- a/opac/opac-memberentry.pl +++ a/opac/opac-memberentry.pl @@ -157,9 +157,11 @@ if ( $action eq 'create' ) { $template->param( patron_attribute_classes => GeneratePatronAttributesForm( undef, $attributes ) ); } else { + my $patronverification = C4::Context->boolean_preference('PatronSelfRegistrationVerifyByEmailToPatron'); + my $libraryverification = C4::Context->preference('PatronSelfRegistrationVerifyByEmailToLibrary'); if ( - C4::Context->boolean_preference( - 'PatronSelfRegistrationVerifyByEmail') + $patronverification + || $libraryverification ) { ( $template, $borrowernumber, $cookie ) = get_template_and_user( @@ -182,28 +184,78 @@ if ( $action eq 'create' ) { 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 $letter_code; + my $action; + my $toaddress; + my $letter; + if ($patronverification && !$libraryverification) { + $action = 'patrontoverify'; + } elsif ($patronverification && $libraryverification) { + $action = 'patronandlibrarytoverify'; + } else { + $action = 'librarytoverify'; + } + $template->param( action => $action ); + + if ($action eq 'patrontoverify') { + # Send verification email to patron + $letter_code = 'OPAC_REG_VERIFY'; + $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => $letter_code, + lang => 'default', # Patron does not have a preferred language defined yet + tables => { + borrower_modifications => $verification_token, + }, + ); + $toaddress = $borrower{'email'}; + } elsif ($action eq 'patronandlibrarytoverify') { + $letter_code = 'PATRON_AND_LIB_VER'; + $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => $letter_code, + lang => 'default', + tables => { + borrower_modifications => $verification_token, + }, + ); + $toaddress = $borrower{'email'}; + } else { + # Send verification email to library + $letter_code = 'STAFF_VER_OPAC_REG'; + $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => $letter_code, + lang => 'default', # Patron does not have a preferred language defined yet + tables => { + borrower_modifications => $verification_token, + }, + ); + if ($libraryverification eq "BranchEmailAddress") { + my $library = Koha::Libraries->find( $borrower{branchcode} ); + $toaddress = $library->branchreplyto + || $library->branchemail + || C4::Context->preference('ReplytoDefault') + || C4::Context->preference('KohaAdminEmailAddress') + } elsif ($libraryverification eq "KohaAdminEmailAddress") { + $toaddress = C4::Context->preference('ReplytoDefault') + || C4::Context->preference('KohaAdminEmailAddress'); + } + } C4::Letters::EnqueueLetter( { letter => $letter, message_transport_type => 'email', - to_address => $borrower{'email'}, + to_address => $toaddress, from_address => C4::Context->preference('KohaAdminEmailAddress'), } ); + my $num_letters_attempted = C4::Letters::SendQueuedMessages( { - letter_code => 'OPAC_REG_VERIFY' - } ); + letter_code => $letter_code + } ); } else { ( $template, $borrowernumber, $cookie ) = get_template_and_user( --- a/opac/opac-password-recovery.pl +++ a/opac/opac-password-recovery.pl @@ -34,6 +34,8 @@ my $uniqueKey = $query->param('uniqueKey'); my $username = $query->param('username') // q{}; my $borrower_number; +$borrower_number = $query->param('borrowernumber') if ($query->param('borrowernumber')); + #errors my $hasError; @@ -208,7 +210,11 @@ elsif ($uniqueKey) { #reset password form ); } else { #password recovery form (to send email) - $template->param( password_recovery => 1 ); + my $borrower = Koha::Patrons->find($borrower_number); + $template->param( email => $borrower->email, username => $borrower->userid ) if $borrower; + $template->param( + password_recovery => 1, + ); } output_html_with_http_headers $query, $cookie, $template->output; --- a/opac/opac-registration-verify.pl +++ a/opac/opac-registration-verify.pl @@ -58,33 +58,116 @@ if ( } ); - my $patron_attrs = $m->unblessed; - $patron_attrs->{password} ||= Koha::AuthUtils::generate_password; - my $consent_dt = delete $patron_attrs->{gdpr_proc_consent}; - $patron_attrs->{categorycode} ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory'); - delete $patron_attrs->{timestamp}; - delete $patron_attrs->{verification_token}; - delete $patron_attrs->{changed_fields}; - my $patron = Koha::Patron->new( $patron_attrs )->store; - - Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $consent_dt; - - if ($patron) { - $m->delete(); - C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $patron->borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences'); - - $template->param( password_cleartext => $patron->plain_text_password ); - $template->param( borrower => $patron ); - $template->param( - PatronSelfRegistrationAdditionalInstructions => - C4::Context->preference( - 'PatronSelfRegistrationAdditionalInstructions') + my $libraryhasverified = $cgi->param('approved'); + my $needlibraryverification = C4::Context->preference('PatronSelfRegistrationVerifyByEmailToLibrary'); + + my $action; + if ( $libraryhasverified && $needlibraryverification ) { + $action = 'libraryhasverified'; + } elsif ( !$libraryhasverified && $needlibraryverification ) { + $action = 'librarytoverify'; + } else { + $action = 'nolibraryverification'; + } + + $template->param( action => $action ); + + if ($action eq 'nolibraryverification' || $action eq 'libraryhasverified') { + + # Create account as library verification not required or already done + my $patron_attrs = $m->unblessed; + $patron_attrs->{password} ||= Koha::AuthUtils::generate_password; + my $consent_dt = delete $patron_attrs->{gdpr_proc_consent}; + $patron_attrs->{categorycode} ||= C4::Context->preference('PatronSelfRegistrationDefaultCategory'); + delete $patron_attrs->{timestamp}; + delete $patron_attrs->{verification_token}; + delete $patron_attrs->{changed_fields}; + my $patron = Koha::Patron->new( $patron_attrs )->store; + + # If library verification required then send password reset email directly to patron + if ($needlibraryverification) { + my $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => 'SELF_REG_APPROVED', + lang => 'default', # Patron does not have a preferred language defined yet + tables => { + borrowers => $patron->borrowernumber, + }, + ); + + C4::Letters::EnqueueLetter( + { + letter => $letter, + message_transport_type => 'email', + to_address => $patron->email, + from_address => C4::Context->preference('KohaAdminEmailAddress'), + } + ); + + my $num_letters_attempted = C4::Letters::SendQueuedMessages( { + letter_code => 'SELF_REG_APPROVED' + } ); + } + + Koha::Patron::Consent->new({ borrowernumber => $patron->borrowernumber, type => 'GDPR_PROCESSING', given_on => $consent_dt })->store if $consent_dt; + + if ($patron) { + $m->delete(); + C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $patron->borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences'); + + $template->param( password_cleartext => $patron->plain_text_password ); + $template->param( borrower => $patron ); + $template->param( + PatronSelfRegistrationAdditionalInstructions => + C4::Context->preference( + 'PatronSelfRegistrationAdditionalInstructions') + ); + + my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Context->config('opachtdocs'),'opac-registration-confirmation.tt','opac',$cgi); + $template->param( news_lang => $news_lang ); + } + + } else { + + # Send verification email to library to approve + my $toaddress; + if ($needlibraryverification eq "BranchEmailAddress" ) { + my $library = Koha::Libraries->find( $m->branchcode ); + $toaddress = $library->branchreplyto + || $library->branchemail + || C4::Context->preferences('ReplytoDefault') + || C4::Context->preferences('KohaAdminEmailAddress') + } + elsif ( $needlibraryverification eq "KohaAdminEmailAddress" ) { + $toaddress = C4::Context->preference('ReplytoDefault') + || C4::Context->preference('KohaAdminEmailAddress'); + } + + my $patron_attrs = $m->unblessed; + my $letter; + # Send verification email to library + $letter = C4::Letters::GetPreparedLetter( + module => 'members', + letter_code => 'STAFF_VER_OPAC_REG', + lang => 'default', # Patron does not have a preferred language defined yet + tables => { + borrower_modifications => $patron_attrs->{verification_token}, + }, ); - my ($theme, $news_lang, $availablethemes) = C4::Templates::themelanguage(C4::Context->config('opachtdocs'),'opac-registration-confirmation.tt','opac',$cgi); - $template->param( news_lang => $news_lang ); + C4::Letters::EnqueueLetter( + { + letter => $letter, + message_transport_type => 'email', + to_address => $toaddress, + from_address => + C4::Context->preference('KohaAdminEmailAddress'), + } + ); + my $num_letters_attempted = C4::Letters::SendQueuedMessages( { + letter_code => 'STAFF_VER_OPAC_REG' + } ); } - } else { ( $template, $borrowernumber, $cookie ) = get_template_and_user( --