Example #1
0
 /**
  * Attempts Constructor
  *
  * @param   string  user login
  * @param   string  ip address
  * @return  Sentry_Attempts
  * @throws  SentryAttemptsException
  */
 public function __construct($login_id = null, $ip_address = null)
 {
     $_db_instance = trim(Config::get('sentry::sentry.db_instance'));
     // db_instance check
     if (!empty($_db_instance)) {
         static::$db_instance = $_db_instance;
     }
     static::$table_suspend = Config::get('sentry::sentry.table.users_suspended');
     static::$limit = array('enabled' => Config::get('sentry::sentry.limit.enabled'), 'attempts' => Config::get('sentry::sentry.limit.attempts'), 'time' => Config::get('sentry::sentry.limit.time'));
     $this->login_id = $login_id;
     $this->ip_address = $ip_address;
     // limit checks
     if (static::$limit['enabled'] === true) {
         if (!is_int(static::$limit['attempts']) or static::$limit['attempts'] <= 0) {
             throw new SentryConfigException(__('sentry::sentry.invalid_limit_attempts'));
         }
         if (!is_int(static::$limit['time']) or static::$limit['time'] <= 0) {
             throw new SentryConfigException(__('sentry::sentry.invalid_limit_time'));
         }
     }
     $query = DB::connection(static::$db_instance)->table(static::$table_suspend);
     if ($this->login_id) {
         $query = $query->where('login_id', '=', $this->login_id);
     }
     if ($this->ip_address) {
         $query = $query->where('ip', '=', $this->ip_address);
     }
     $result = $query->get();
     foreach ($result as &$row) {
         $row = get_object_vars($row);
         $time = new \DateTime($row['last_attempt_at']);
         $time = $time->modify('+' . static::$limit['time'] . ' minutes')->getTimestamp();
         // check unsuspended time and clear if time is > than it
         if ($row['unsuspend_at'] != '0000-00-00 00:00:00' and $row['unsuspend_at'] <= static::sql_timestamp()) {
             $this->clear($row['login_id'], $row['ip']);
             $row['attempts'] = 0;
         }
     }
     if (count($result) > 1) {
         $this->attempts = count($result);
     } elseif ($result) {
         $attempts = $result[0]['attempts'];
         if ($attempts === 0) {
             if ($result[0]['unsuspend_at'] != '0000-00-00 00:00:00' and $result[0]['unsuspend_at'] > static::sql_timestamp()) {
                 $attempts = static::$limit['attempts'];
             }
         }
         $this->attempts = $attempts;
     } else {
         $this->attempts = 0;
     }
 }
Example #2
0
 /**
  * Attempts Constructor
  *
  * @param   string  user login
  * @param   string  ip address
  * @return  Sentry_Attempts
  * @throws  SentryAttemptsException
  */
 public function __construct($login_id = null, $ip_address = null)
 {
     \Config::load('sentry', true);
     $_db_instance = trim(\Config::get('sentry.db_instance'));
     // db_instance check
     if (!empty($_db_instance)) {
         static::$db_instance = $_db_instance;
     }
     static::$table_suspend = \Config::get('sentry.table.users_suspended');
     static::$limit = array('enabled' => \Config::get('sentry.limit.enabled'), 'attempts' => \Config::get('sentry.limit.attempts'), 'time' => \Config::get('sentry.limit.time'));
     $this->login_id = $login_id;
     $this->ip_address = $ip_address;
     // limit checks
     if (static::$limit['enabled'] === true) {
         if (!is_int(static::$limit['attempts']) or static::$limit['attempts'] <= 0) {
             throw new \SentryAuthConfigException(__('sentry.invalid_limit_attempts'));
         }
         if (!is_int(static::$limit['time']) or static::$limit['time'] <= 0) {
             throw new \SentryAuthConfigException(__('sentry.invalid_limit_time'));
         }
     }
     $query = \DB::select()->from(static::$table_suspend);
     if ($this->login_id) {
         $query = $query->where('login_id', $this->login_id);
     }
     if ($this->ip_address) {
         $query = $query->where('ip', $this->ip_address);
     }
     $result = $query->execute(static::$db_instance)->as_array();
     foreach ($result as &$row) {
         // check if last attempt was more than 15 min ago - if so reset counter
         if ($row['last_attempt_at'] and $row['last_attempt_at'] + static::$limit['time'] * 60 <= time()) {
             $this->clear($row['login_id'], $row['ip']);
             $row['attempts'] = 0;
         }
         // check unsuspended time and clear if time is > than it
         if ($row['unsuspend_at'] and $row['unsuspend_at'] <= time()) {
             $this->clear($row['login_id'], $row['ip']);
             $row['attempts'] = 0;
         }
     }
     if (count($result) > 1) {
         $this->attempts = $result;
     } elseif ($result) {
         $this->attempts = $result[0]['attempts'];
     } else {
         $this->attempts = 0;
     }
 }
Example #3
0
 /**
  * Возвращает коллекцию в виде пагинации
  *
  * @param int $page
  * @param int $limit
  */
 public function pagination($page, $limit = 10)
 {
     /**
      * @var \Illuminate\Support\Collection $data
      */
     $countTotal = $this->_query->count();
     $this->_query->skip($limit * $page - $limit);
     $this->_query->limit($limit);
     $data = collect();
     foreach ($this->_query->get() as $key => $instance) {
         $_listRow = [];
         foreach ($this->columns->getColumns() as $column) {
             $_listRow[$column->getKey()] = $column->getValues($instance);
         }
         $buttons = $this->filterAction($instance);
         if (count($buttons)) {
             $_listRow = array_merge($_listRow, [GridColumn::ACTION_NAME => implode('', $buttons)]);
         }
         $data->offsetSet($key, $_listRow);
     }
     return new \Illuminate\Pagination\LengthAwarePaginator($data, $countTotal, $limit, $page, ['path' => \Illuminate\Pagination\Paginator::resolveCurrentPath(), 'pageName' => 'page']);
 }
Example #4
0
File: Base.php Project: nblight/mvc
 private static function reset()
 {
     static::$select = '*';
     static::$where = '';
     static::$orderby = '';
     static::$limit = '';
 }
 /**
  * Reset collection variables
  */
 private function reset()
 {
     static::$header = static::$total;
     static::$limit = 100;
     static::$total = false;
 }