public static getUserThrottle ( integer $userId ) : Psecio\Gatekeeper\ThrottleModel | ||
$userId | integer | User ID |
return | Psecio\Gatekeeper\ThrottleModel | instance |
public static function getUserThrottle($userId)
{
$throttle = Gatekeeper::findThrottleByUserId($userId);
if ($throttle === false) {
$data = array('user_id' => $userId, 'attempts' => 1, 'status' => ThrottleModel::STATUS_ALLOWED, 'last_attempt' => date('Y-m-d H:i:s'), 'status_change' => date('Y-m-d H:i:s'));
$throttle = Gatekeeper::modelFactory('ThrottleModel', $data);
}
return $throttle;
}
/** * 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; } } return true; }