コード例 #1
0
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $quiet = (bool) $options['quiet'];
     if (!$quiet) {
         echo "Removing files...";
     }
     AuthFailureTable::getInstance()->cleanUpOldFailures();
     if (!$quiet) {
         echo "\n";
     }
 }
コード例 #2
0
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
     $quiet = (bool) $options['quiet'];
     if (!$quiet) {
         echo "Removing old authorization failures...";
     }
     AuthFailureTable::getInstance()->cleanUpOldFailures();
     if (!$quiet) {
         echo "\nRemoving expired API user authorization tokens...";
     }
     sfGuardUserAuthKeyTable::getInstance()->cleanUpTokens();
     if (!$quiet) {
         echo "\n";
     }
 }
コード例 #3
0
 /**
  * Request a new xAuth key for a user.
  *
  * @param string $email_address Email address of the user.
  * @param string $password      Password of the user.
  * @param int    $expires_in    How long the auth key should last. Max 1 year.
  * @return string|boolean       The auth key for this API.  False upon failure.
  */
 public function requestAuthKey($email_address, $password, $expires_in = 7200)
 {
     if (!$this->getIsActive()) {
         throw new sfException('API is inactive!');
     }
     // Attempt to find user by email address
     $user = sfGuardUserTable::getInstance()->findOneByEmailAddress($email_address);
     /* @var $user sfGuardUser */
     if (!$user) {
         throw new sfException('Email address or password is incorrect.');
     }
     // Find out how many failures in the past two minutes - max of five
     $failures = AuthFailureTable::getInstance()->countFailuresMadeInRecentSeconds($this->getIncremented(), $user->getIncremented(), 120);
     if ($failures >= 6) {
         throw new sfException('Too many failures. Please wait a few minutes and try again.');
     }
     if ($user && $user->checkPassword($password) && $user->getIsAuthorized() && $user->getIsActive()) {
         $year = 31536000;
         $expires_in = $expires_in >= $year ? $year : $expires_in;
         $user_auth = new sfGuardUserAuthKey();
         $user_auth->setSfGuardUser($user);
         $user_auth->setApiKey($this);
         $user_auth->setExpiresAt(date('Y-m-d H:i:s', time() + $expires_in));
         $auth_key = sha1(rand(0, 10000) . time());
         $user_auth->setAuthKey($auth_key);
         $user_auth->save();
         return $auth_key;
     }
     $failure = new AuthFailure();
     $failure->setSfGuardUser($user);
     $failure->setApiKey($this);
     $failure->save();
     if (!$user) {
         throw new sfException('Email address or password is incorrect.');
     } elseif (!$user->getIsActive()) {
         throw new sfException('Email address or password is incorrect.');
     } elseif (!$user->getIsAuthorized()) {
         throw new sfException('User has not validated their email address yet');
     } elseif (!$user->checkPassword($password)) {
         throw new sfException('Email address or password is incorrect.');
     } else {
         throw new sfException('An unexpected error occured.');
     }
 }
コード例 #4
0
 /**
  * Tests for success at creating the object.
  */
 public function testCreate()
 {
     $t = AuthFailureTable::getInstance();
     $this->assertTrue($t instanceof Doctrine_Table);
 }