Online Renewal - Prevent user from re-submitting renewal after complete quipu_renewal_WORK_IN_PROGRESS
authorTerran McCanna <tmccanna@georgialibraries.org>
Thu, 1 Dec 2022 19:23:06 +0000 (14:23 -0500)
committerTerran McCanna <tmccanna@georgialibraries.org>
Thu, 1 Dec 2022 19:23:06 +0000 (14:23 -0500)
Signed-off-by: Terran McCanna <tmccanna@georgialibraries.org>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Account.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Ecard.pm

index 1a8177a..a04edf0 100644 (file)
@@ -200,7 +200,6 @@ sub load_myopac_prefs_notify {
     my $self = shift;
     my $e = $self->editor;
 
-
     my $stat = $self->_load_user_with_prefs;
     return $stat if $stat;
 
@@ -3556,6 +3555,9 @@ sub check_account_exp {
     }
 
     #determine which message to show (if any)
+    my $cache = OpenSRF::Utils::Cache->new('global');
+    $cache->put_cache('account_renew_ok','false',3600);
+
     if ($ctx->{hastemprenew} eq 1) { #user already has active temp renewal
         $ctx->{account_renew_message} = '<div style="border:2px solid green;padding:5px;">Your account
         could only be temporarily renewed because your address changed. Please visit your nearest PINES
@@ -3573,6 +3575,7 @@ sub check_account_exp {
     } else {
         $ctx->{account_renew_message} = '<span class="light_border"><a class="btn btn-sm btn-action"
         href="/eg/opac/renew-account"><i class="fas fa-user-cog"></i>Click here to renew your account</a></span>';
+        $cache->put_cache('account_renew_ok','true',3600);
     }
 
     return 1;
index 128efd9..e903e90 100644 (file)
@@ -5,6 +5,7 @@ use OpenSRF::Utils::Logger qw/$logger/;
 use OpenSRF::Utils::JSON;
 use OpenSRF::Utils qw/:datetime/;
 use OpenILS::Utils::Fieldmapper;
+use OpenSRF::Utils::Cache;
 use OpenILS::Application::AppUtils;
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Event;
@@ -101,10 +102,8 @@ sub log_params {
         $msg .= "|" if $msg; 
         $msg .= "$p=".$cgi->param($p);
     }
-    $logger->info("ECARD: Submit params: $msg");
 
-#TERRAN - dump out all incoming stuff from form
-$logger->error("TERRAN - all incoming params: $msg");
+    $logger->info("ECARD: Submit params: $msg");
 }
 
 sub handle_testmode_api {
@@ -149,7 +148,6 @@ sub handle_datamode_api {
 }
 
 sub load_ecard_submit {
-
     my $self = shift;
     my $ctx = $self->ctx;
     my $cgi = $self->cgi;
@@ -161,6 +159,16 @@ sub load_ecard_submit {
         $update_type = 'register';
     }
 
+    #If this is a renewal, double-check that they are eligible to renew
+    my $cache = OpenSRF::Utils::Cache->new('global');
+    if ($update_type eq 'renew') {
+        if ($cache->get_cache("account_renew_ok") && $cache->get_cache("account_renew_ok") eq 'true') {
+        } else {
+            $logger->error("ERENEW - User not in correct status to renew account");
+            return $self->compile_response;
+        }
+    }
+
     $self->log_params;
 
     my $testmode = $cgi->param('testmode') || '';
@@ -230,6 +238,8 @@ sub load_ecard_submit {
         } else {
             $ctx->{response}->{temp_renew} = 0;
         }
+        #set renewal flag in cache to false to prevent user from refreshing the page and submitting again
+        $cache->put_cache('account_renew_ok','false',3600);
     } else {
         $ctx->{response}->{barcode} = $ctx->{user}->card->barcode;
        }
@@ -282,9 +292,6 @@ sub compile_response {
     $ctx->{response} = OpenSRF::Utils::JSON->perl2JSON($ctx->{response});
     $logger->info("ECARD responding with " . $ctx->{response});
 
-#TERRAN TEST
-    $logger->error("TERRAN - response being sent to Quipu is: " . $ctx->{response});
-
     return Apache2::Const::OK;
 }