[open-ils-commits] r16189 - branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Apr 8 23:33:00 EDT 2010


Author: dbs
Date: 2010-04-08 23:32:58 -0400 (Thu, 08 Apr 2010)
New Revision: 16189

Modified:
   branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
Implement some password request throttling


Modified: branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2010-04-09 02:16:56 UTC (rev 16188)
+++ branches/rel_1_6/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm	2010-04-09 03:32:58 UTC (rev 16189)
@@ -3409,6 +3409,10 @@
                 {
                     column => 'uuid',
                     transform => 'COUNT'
+                },
+                {
+                    column => 'request_time',
+                    transform => 'MAX'
                 }
             ]
         },
@@ -3418,8 +3422,16 @@
         }
     });
 
+    my $last_request = DateTime::Format::ISO8601->parse_datetime(clense_ISO8601($active_requests->[0]->{'request_time'}));
+    my $now = DateTime::Format::ISO8601->new();
+
     # 3. if (num_active > throttle_threshold) and (now - last_request < 1 minute)
-    #      ... delay - set cache - return event correspondingly ...
+    if (($active_requests->[0]->{'usr'} > $aupr_throttle) &&
+        ($last_request->add_duration('1 minute') > $now)) {
+        $cache->put_cache('open-ils.actor.password.throttle', DateTime::Format::ISO8601->new(), 60);
+        $e->die_event;
+        return OpenILS::Event->new('PATRON_TOO_MANY_ACTIVE_PASSWORD_RESET_REQUESTS');
+    }
 
     # TODO Check to see if the user is in a password-reset-restricted group
 
@@ -3490,6 +3502,11 @@
 
     # Check to see if password reset requests are already being throttled:
     # 0. Check cache to see if we're in throttle mode (avoid hitting database)
+    $cache ||= OpenSRF::Utils::Cache->new("global", 0);
+    my $throttle = $cache->get_cache('open-ils.actor.password.throttle') || undef;
+    if ($throttle) {
+        return OpenILS::Event->new('PATRON_NOT_AN_ACTIVE_PASSWORD_RESET_REQUEST');
+    }
 
     my $e = new_editor(xact => 1);
 



More information about the open-ils-commits mailing list