예제 #1
0
	/**
	 * Finds a throttling interface by the given user login.
	 *
	 * @param  string  $login
	 * @param  string  $ipAddress
	 * @return \Cartalyst\Sentry\Throttling\ThrottleInterface
	 */
	public function findByUserLogin($login, $ipAddress = null)
	{
		$user  = $this->userProvider->findByLogin($login);
		$model = $this->createModel();
		$query = $model->where('user_id', '=', ($userId = $user->getId()));

		if ($ipAddress)
		{
			$query->where(function($query) use ($ipAddress) {
				$query->where('ip_address', '=', $ipAddress);
				$query->orWhere('ip_address', '=', NULL);
			});
		}

		if ( ! $throttle = $query->first())
		{
			$throttle = $this->createModel();
			$throttle->user_id = $userId;
			if ($ipAddress) $throttle->ip_address = $ipAddress;
			$throttle->save();
		}

		return $throttle;
	}
예제 #2
0
 /**
  * Finds a throttling interface by the given user login.
  *
  * @param  string  $login
  * @param  string  $ipAddress
  * @return \Cartalyst\Sentry\Throttling\ThrottleInterface
  */
 public function findByUserLogin($login, $ipAddress = null)
 {
     return $this->findByUser($this->userProvider->findByLogin($login), $ipAddress);
 }