Esempio n. 1
0
File: DB.php Progetto: jasny/Q
 /**
  * Fetch user.
  *
  * @param string $field  Criteria field
  * @param mixed  $value  Criteria value
  * @return Auth_User
  */
 protected function doFetchUser($field, $value)
 {
     if (!$this->queryInit || !$this->query instanceof DB_Statement) {
         $this->initStatement();
     }
     $this->query->addCriteria($field, $value);
     $result = $this->query->execute();
     $this->query->reset();
     if (!$result->countRows()) {
         return null;
     }
     $info = array_combine(array('id', 'fullname', 'username', 'host', 'password', 'groups', 'active', 'expire') + $result->getFieldNames(), $result->fetchOrdered());
     $info['host'] = HTTP::getClientIP();
     return new Auth_User($info);
 }
Esempio n. 2
0
File: Auth.php Progetto: jasny/Q
 /**
  * Check if host is blocked.
  * Returns 0 if unblockable.
  * 
  * @param string  $host
  * @param boolean $attempt  Increment attempts (bool) or attempt (int)
  * @return boolean
  */
 public function isBlocked($host = null, $attempt = false)
 {
     if (empty($this->loginAttempts)) {
         return 0;
     }
     if (!isset($host)) {
         $host = HTTP::getClientIP(HTTP::CONNECTED_CLIENT);
     }
     if (empty($host) || in_array($host, $this->unblockableHosts, true)) {
         return 0;
     }
     if (!isset($this->storeAttemps)) {
         if (!Cache::hasInstance()) {
             return 0;
         }
         $this->storeAttemps = Cache::i();
     } elseif (!$this->storeAttemps instanceof Cache) {
         $this->storeAttemps = Cache::with($this->storeAttemps, array('overwrite' => true));
     }
     if (is_bool($attempt)) {
         $attempt = (int) $this->storeAttemps->get("AUTH-login_attempts:{$host}") + 1;
     }
     if ($attempt) {
         $this->storeAttemps->save("AUTH-login_attempts:{$host}", $attempt);
     } else {
         $this->storeAttemps->remove("AUTH-login_attempts:{$host}");
     }
     return $this->loginAttempts - $attempt < 0;
 }