Can be done on the throttle provider (global) level or on a throttle instance itself.

    Example

    Enables the throttling feature.

    Can be done on the throttle provider (global) level or on a throttle instance itself.

    Example

    1. $throttleProvider = Sentry::getThrottleProvider();
    2. // Enable the Throttling Feature
    3. $throttleProvider->enable();

    Checks to see if the throttling feature is enabled or disabled.

    Example

    1. // Get the Throttle Provider
    2. $provider = Sentry::getThrottleProvider();
    3. // Check if the Throttling feature is enabled or disabled
    4. if($provider->isEnabled())
    5. {
    6. // The Throttling Feature is Enabled
    7. }
    8. else
    9. {
    10. // The Throttling Feature is Disabled
    11. }

    Ban user(s)

    Bans the user associated with the throttle.

    1. try
    2. {
    3. // Find the user using the user id
    4. $throttle = Sentry::findThrottlerByUserId(1);
    5. // Ban the user
    6. $throttle->ban();
    7. }
    8. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    9. {
    10. echo 'User was not found.';
    11. }

    Unban user(s)

    Unbans the user associated with the throttle.

    1. try
    2. {
    3. // Find the user using the user id
    4. $throttle = Sentry::findThrottlerByUserId(1);
    5. // Unban the user
    6. $throttle->unBan();
    7. }
    8. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    9. {
    10. echo 'User was not found.';
    11. }

    Check if a User is Banned

    1. {
    2. $throttle = Sentry::findThrottlerByUserId(1);
    3. if($banned = $throttle->isBanned())
    4. {
    5. // User is Banned
    6. }
    7. else
    8. {
    9. // User is not Banned
    10. }
    11. }
    12. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    13. {
    14. echo 'User was not found.';
    15. }

    Suspend user(s)

    Suspends a user temporarily. Length of the suspension is set by the driver or setSuspensionTime($minutes).

    Unsuspend user(s)

    Unsuspends a login. This also clears all previous attempts by the specified login if they were suspended.

    1. try
    2. // Find the user using the user id
    3. $throttle = Sentry::findThrottlerByUserId(1);
    4. // Unsuspend the user
    5. $throttle->unsuspend();
    6. }
    7. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    8. {
    9. echo 'User was not found.';
    10. }

    Check if a User is Suspended

    Checks to see if the user is suspended.

    1. try
    2. {
    3. $throttle = Sentry::findThrottlerByUserId(1);
    4. if($suspended = $throttle->isSuspended())
    5. {
    6. // User is Suspended
    7. }
    8. else
    9. {
    10. // User is not Suspended
    11. }
    12. }
    13. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    14. {
    15. echo 'User was not found.';
    16. }

    Set the User Suspension Time

    Sets the length of the suspension.

    1. try
    2. {
    3. $throttle = Sentry::findThrottlerByUserId(1);
    4. $throttle->setSuspensionTime(10);
    5. }
    6. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    7. {
    8. echo 'User was not found.';
    9. }

    Get the User Suspension Time

    Retrieves the length of the suspension time set by the throttling driver.

    1. try
    2. {
    3. $throttle = Sentry::findThrottlerByUserId(1);
    4. $suspensionTime = $throttle->getSuspensionTime();
    5. }
    6. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    7. {
    8. echo 'User was not found.';
    9. }

    Add a Login Attempt

    Adds an attempt to the throttle object.

    1. try
    2. {
    3. $throttle->addLoginAttempt();
    4. }
    5. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    6. {
    7. echo 'User was not found.';
    8. }

    Get Login Attempts

    Clear Login Attempts

    Clears all login attempts, it also unsuspends them. This does not unban a login.

    1. try
    2. $throttle = Sentry::findThrottlerByUserId(1);
    3. $throttle->clearLoginAttempts();
    4. }
    5. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    6. {
    7. echo 'User was not found.';
    8. }

    Check the User Throttle Status

    Checks the login throttle status and throws a number of Exceptions upon failure.

    1. try
    2. {
    3. $throttle = Sentry::findThrottlerByUserId(1);
    4. if ($throttle->check())
    5. {
    6. echo 'Good to go.';
    7. }
    8. }
    9. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    10. {
    11. echo 'User was not found.';
    12. }
    13. catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e)
    14. {
    15. $time = $throttle->getSuspensionTime();
    16. echo "User is suspended for [$time] minutes.";
    17. }
    18. catch (Cartalyst\Sentry\Throttling\UserBannedException $e)
    19. {
    20. ehco 'User is banned.';
    21. }

    Set Attempt Limit

    Sets the number of attempts allowed before suspension.

    1. try
    2. {
    3. $throttle = Sentry::findThrottlerByUserId(1);
    4. $throttle->setAttemptLimit(3);
    5. }
    6. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    7. {
    8. echo 'User was not found.';
    9. }

    Get Attempt Limit

    Retrieves the number of attempts allowed by the throttle object.

    1. try
    2. {
    3. $throttle = Sentry::findThrottlerByUserId(1);
    4. $attemptLimit = $throttle->getAttemptLimit();
    5. }
    6. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    7. {
    8. echo 'User was not found.';
    9. }

    Exceptions

    Below is a list of exceptions that the methods can throw.

    Find a User by their Id

    Retrieves a throttle object based on the user ID provided. Will always retrieve a throttle object.

    1. try
    2. {
    3. $throttle = Sentry::findThrottlerByUserId(1);
    4. }
    5. catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    6. {
    7. echo 'User was not found.';

    Find a User by their Login

    Exceptions

    Below is a list of exceptions that the methods can throw.

    Exception Description
    Cartalyst\Sentry\Users\UserNotFoundException If the provided user was not found, this exception will be thrown.