summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Cornutt <chris.cornutt@hp.com>2015-01-28 10:32:51 -0600
committerChris Cornutt <chris.cornutt@hp.com>2015-01-28 10:32:51 -0600
commit11b7357abe1a3ec906ff21cea2d8077da17570cd (patch)
treeb85119a27b4d329d1357f009af8782c68c309abd
parentf4fd7973c20709da190e8bb207e635714c961cd3 (diff)
downloadgatekeeper-11b7357abe1a3ec906ff21cea2d8077da17570cd.zip
gatekeeper-11b7357abe1a3ec906ff21cea2d8077da17570cd.tar.gz
gatekeeper-11b7357abe1a3ec906ff21cea2d8077da17570cd.tar.bz2
converting the throttle checking over to a Restriction, adding the restriction class for it too
-rw-r--r--src/Psecio/Gatekeeper/Gatekeeper.php20
-rw-r--r--src/Psecio/Gatekeeper/Restrict/Throttle.php34
2 files changed, 38 insertions, 16 deletions
diff --git a/src/Psecio/Gatekeeper/Gatekeeper.php b/src/Psecio/Gatekeeper/Gatekeeper.php
index 201ff6f..36ffde1 100644
--- a/src/Psecio/Gatekeeper/Gatekeeper.php
+++ b/src/Psecio/Gatekeeper/Gatekeeper.php
@@ -177,21 +177,9 @@ class Gatekeeper
// Handle some throttle logic, if it's turned on
if (self::$throttleStatus === true) {
- $throttle = self::getUserThrottle($user->id);
- $throttle->updateAttempts();
-
- // See if they're blocked
- if ($throttle->status === ThrottleModel::STATUS_BLOCKED) {
- $result = $throttle->checkTimeout();
- if ($result === false) {
- return false;
- }
- } else {
- $result = $throttle->checkAttempts();
- if ($result === false) {
- return false;
- }
- }
+ // Set up our default throttle restriction
+ $instance = new \Psecio\Gatekeeper\Restrict\Throttle(array('userId' => $user->id));
+ self::$restrictions[] = $instance;
}
// Check any restrictions
@@ -207,7 +195,7 @@ class Gatekeeper
$result = password_verify($credentials['password'], $user->password);
if (self::$throttleStatus === true && $result === true) {
- $throttle->allow();
+ $instance->model->allow();
}
return $result;
diff --git a/src/Psecio/Gatekeeper/Restrict/Throttle.php b/src/Psecio/Gatekeeper/Restrict/Throttle.php
new file mode 100644
index 0000000..d49ef31
--- /dev/null
+++ b/src/Psecio/Gatekeeper/Restrict/Throttle.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Psecio\Gatekeeper\Restrict;
+
+class Throttle extends \Psecio\Gatekeeper\Restriction
+{
+ public $model;
+
+ /**
+ * Execute the evaluation for the restriction
+ *
+ * @return boolean Success/fail of evaluation
+ */
+ public function evaluate()
+ {
+ $config = $this->getConfig();
+ $throttle = \Psecio\Gatekeeper\Gatekeeper::getUserThrottle($config['userId']);
+ $throttle->updateAttempts();
+ $this->model = $throttle;
+
+ // See if they're blocked
+ if ($throttle->status === \Psecio\Gatekeeper\ThrottleModel::STATUS_BLOCKED) {
+ $result = $throttle->checkTimeout();
+ if ($result === false) {
+ return false;
+ }
+ } else {
+ $result = $throttle->checkAttempts();
+ if ($result === false) {
+ return false;
+ }
+ }
+ }
+} \ No newline at end of file