public function testGettingLoginAttemptsResetsIfSuspensionTimeHasPassedSinceLastAttempt()
 {
     $throttle = m::mock('Cartalyst\\Sentry\\Throttling\\Eloquent\\Throttle[save]');
     $this->addMockConnection($throttle);
     $throttle->getConnection()->getQueryGrammar()->shouldReceive('getDateFormat')->andReturn('Y-m-d H:i:s');
     // Let's simulate that the suspension time
     // is 11 minutes however the last attempt was
     // 10 minutes ago, we'll not reset the attempts
     Throttle::setSuspensionTime(11);
     $lastAttemptAt = new DateTime();
     $lastAttemptAt->modify('-10 minutes');
     $throttle->last_attempt_at = $lastAttemptAt->format('Y-m-d H:i:s');
     $throttle->attempts = 3;
     $this->assertEquals(3, $throttle->getLoginAttempts());
     // Suspension time is 9 minutes now,
     // our attempts shall be reset
     $throttle->shouldReceive('save')->once();
     Throttle::setSuspensionTime(9);
     $this->assertEquals(0, $throttle->getLoginAttempts());
 }
Example #2
0
 /**
  * Suspend the user associated with the throttle.
  *
  * @return void
  */
 public function suspend()
 {
     RevisionRepository::create(['revisionable_type' => Config::get('sentry.users.model'), 'revisionable_id' => $this['user_id'], 'key' => 'suspended_at', 'old_value' => $this['suspended_at'], 'new_value' => new DateTime(), 'user_id' => null]);
     parent::suspend();
 }
Example #3
0
 /**
  * Create a new Eloquent model instance.
  *
  * @param  array  $attributes
  * @return void
  */
 public function __construct(array $attributes = array())
 {
     $this->{$this->getKeyName()} = (string) $this->generateNewId();
     parent::__construct($attributes);
 }