diff options
author | Chris Cornutt <chris.cornutt@hp.com> | 2015-01-28 10:32:51 -0600 |
---|---|---|
committer | Chris Cornutt <chris.cornutt@hp.com> | 2015-01-28 10:32:51 -0600 |
commit | 11b7357abe1a3ec906ff21cea2d8077da17570cd (patch) | |
tree | b85119a27b4d329d1357f009af8782c68c309abd | |
parent | f4fd7973c20709da190e8bb207e635714c961cd3 (diff) | |
download | gatekeeper-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.php | 20 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/Restrict/Throttle.php | 34 |
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 |