Bug 19319: Only fetch the record if it exists
[srvgit] / opac / opac-registration-verify.pl
index eaaf52f..9d49c04 100755 (executable)
@@ -22,7 +22,9 @@ use CGI qw ( -utf8 );
 use C4::Auth;
 use C4::Output;
 use C4::Members;
-use Koha::Borrower::Modifications;
+use C4::Form::MessagingPreferences;
+use Koha::Patrons;
+use Koha::Patron::Modifications;
 
 my $cgi = new CGI;
 my $dbh = C4::Context->dbh;
@@ -33,10 +35,10 @@ unless ( C4::Context->preference('PatronSelfRegistration') ) {
 }
 
 my $token = $cgi->param('token');
-my $m = Koha::Borrower::Modifications->new( verification_token => $token );
+my $m = Koha::Patron::Modifications->find( { verification_token => $token } );
 
 my ( $template, $borrowernumber, $cookie );
-if ( $m->Verify() ) {
+if ( $m ) {
     ( $template, $borrowernumber, $cookie ) = get_template_and_user(
         {
             template_name   => "opac-registration-confirmation.tt",
@@ -49,17 +51,18 @@ if ( $m->Verify() ) {
     $template->param(
         OpacPasswordChange => C4::Context->preference('OpacPasswordChange') );
 
-    my $borrower = Koha::Borrower::Modifications->GetModifications({ verification_token => $token });
+    my $borrower = $m->unblessed();
 
     my $password;
     ( $borrowernumber, $password ) = AddMember_Opac(%$borrower);
 
     if ($borrowernumber) {
-        Koha::Borrower::Modifications->DelModifications({ verification_token => $token });
+        $m->delete();
+        C4::Form::MessagingPreferences::handle_form_action($cgi, { borrowernumber => $borrowernumber }, $template, 1, C4::Context->preference('PatronSelfRegistrationDefaultCategory') ) if C4::Context->preference('EnhancedMessagingPreferences');
 
         $template->param( password_cleartext => $password );
-        $template->param(
-            borrower => GetMember( borrowernumber => $borrowernumber ) );
+        my $patron = Koha::Patrons->find( $borrowernumber );
+        $template->param( borrower => $patron->unblessed );
         $template->param(
             PatronSelfRegistrationAdditionalInstructions =>
               C4::Context->preference(