Example #1
0
 /**
  * @param \Nette\DI\ContainerBuilder $container
  * @param array $config
  */
 private function setupTemplating(ContainerBuilder $container, array $config)
 {
     $def = $container->addDefinition($this->prefix('templateFilesFormatter'))->setClass('Lohini\\Templating\\TemplateFilesFormatter')->addSetup('$skin', [$config['skin']]);
     foreach ($config['dirs'] as $dir => $priority) {
         $def->addSetup('addDir', Validators::isNumericInt($dir) ? [$priority] : [$container->expand($dir), $priority]);
     }
 }
Example #2
0
 /**
  * @param int|Nette\Database\Table\IRow $id
  * @return \stdClass
  */
 public function getItem($id)
 {
     if (isset($id->{static::ROW})) {
         $row = $id->{static::ROW};
     } else {
         if ($id instanceof Nette\Database\Table\IRow) {
             $row = $id;
         } else {
             if (isset($this->userCache[$id])) {
                 return $this->userCache[$id];
             }
             $row = $this->getTable()->where([$this->getTableCell('id') => $id])->fetch();
             if (!$row) {
                 throw new Trejjam\Authorization\User\ManagerException("User id '{$id}' not found", Trejjam\Authorization\User\ManagerException::ID_NOT_FOUND);
             }
         }
     }
     $out = (object) [static::ROW => $row];
     foreach ($this->tables['users']['items'] as $k => $v) {
         if (Nette\Utils\Validators::isNumericInt($k)) {
             $k = $v;
         }
         $out->{$k} = $row->{$v};
     }
     return $this->userCache[$out->id] = $out;
 }
Example #3
0
 static function appendSort(Nette\Database\Table\Selection &$query, $sort = NULL)
 {
     if (!is_null($sort)) {
         foreach ($sort as $k => $v) {
             if (Nette\Utils\Validators::isNumericInt($k)) {
                 $query->order($v);
             } else {
                 $query->order($k . ' ' . strtoupper($v));
             }
         }
     }
     return $query;
 }
Example #4
0
 /**
  * @param array|\stdClass|Nette\Database\Table\IRow $properties
  * @param array|NULL                                $persistProperties
  *
  * @internal
  */
 public function updateProperties($properties, array $persistProperties = NULL)
 {
     $this->properties = $properties;
     if (!is_null($persistProperties)) {
         foreach ($persistProperties as $k => $v) {
             $keyName = Nette\Utils\Validators::isNumericInt($k) ? $v : $k;
             $this->{$keyName} = is_callable($v) ? $v($properties) : $v;
         }
     } else {
         $this->id = !is_object($properties) && isset($properties['id']) ? $properties['id'] : (isset($properties->id) ? $properties->id : NULL);
         $this->parentId = !is_object($properties) && isset($properties['parent_id']) ? $properties['parent_id'] : (isset($properties->parent_id) ? $properties->parent_id : NULL);
         if (is_null($this->parentId)) {
             $this->parentId = !is_object($properties) && isset($properties['parentId']) ? $properties['parentId'] : (isset($properties->parentId) ? $properties->parentId : NULL);
         }
     }
 }
Example #5
0
 public function setAction($user, $action, $identityHash = NULL)
 {
     if (!in_array($action, [static::ACTION_NONE, static::ACTION_RELOAD, static::ACTION_LOGOUT, static::ACTION_DESTROYED])) {
         throw new Trejjam\Authorization\User\IdentityHashException("Action '{$action}' is not enabled.", Trejjam\Authorization\User\IdentityHashException::ACTION_NOT_ENABLED);
     }
     $where = [$this->tables['identityHash']['userId'] => Nette\Utils\Validators::isNumericInt($user) ? $user : $user->id];
     if (!is_null($identityHash)) {
         $where[$this->tables['identityHash']['hash']] = $identityHash;
     }
     switch ($action) {
         case static::ACTION_RELOAD:
             $where[$this->tables['identityHash']['action']] = static::ACTION_NONE;
             break;
     }
     $this->getTable()->where($where)->update([$this->tables['identityHash']['action'] => $action]);
 }
Example #6
0
 /**
  * @param int    $userId
  * @param int    $requestId
  * @param string $hash
  * @param bool   $invalidateHash
  * @return bool|string
  */
 public function getType($userId, $requestId, $hash, $invalidateHash = TRUE)
 {
     if (!isset($userId->{static::ROW}) && !Nette\Utils\Validators::isNumericInt($userId) || !Nette\Utils\Validators::isNumericInt($requestId) || empty($hash)) {
         throw new Trejjam\Authorization\User\RequestException('Invalid input parameters', Trejjam\Authorization\User\RequestException::INVALID_INPUT);
     }
     if ($row = $this->getTable()->where([$this->tables['userRequest']['userId'] => isset($userId->{static::ROW}) ? $userId->id : $userId, $this->tables['userRequest']['id'] => $requestId])->fetch()) {
         if (!Nette\Security\Passwords::verify($hash, $row->{$this->tables['userRequest']['hash']['name']})) {
             throw new Trejjam\Authorization\User\RequestException('Hash is corrupted', Trejjam\Authorization\User\RequestException::CORRUPTED_HASH);
         }
         if ($row->{$this->tables['userRequest']['used']['name']} == $this->tables['userRequest']['used']['positive']) {
             throw new Trejjam\Authorization\User\RequestException('Hash was used', Trejjam\Authorization\User\RequestException::USED_HASH);
         }
         if (!is_null($row->{$this->tables['userRequest']['timeout']['name']}) && $row->{$this->tables['userRequest']['timeout']['name']} < $this->getSqlTime()) {
             throw new Trejjam\Authorization\User\RequestException('Hash timeout', Trejjam\Authorization\User\RequestException::HASH_TIMEOUT);
         }
         if ($invalidateHash) {
             $row->update([$this->tables['userRequest']['used']['name'] => $this->tables['userRequest']['used']['positive']]);
         }
         return $row->{$this->tables['userRequest']['type']['name']};
     }
     throw new Trejjam\Authorization\User\RequestException("Permission denied to requestId '{$requestId}' for user '{$userId}'", Trejjam\Authorization\User\RequestException::PERMISSION_DENIED);
 }
Example #7
0
 /**
  * Is a control's value decimal number?
  * @return bool
  */
 public static function validateInteger(IControl $control)
 {
     if (Validators::isNumericInt($value = $control->getValue())) {
         if (!is_float($tmp = $value * 1)) {
             // bigint leave as string
             $control->setValue($tmp);
         }
         return TRUE;
     }
     return FALSE;
 }
Example #8
0
 /**
  * @param int    $userId
  * @param string $roleName
  */
 public function removeUserRole($user, $roleName)
 {
     $role = $this->getRoleByName($roleName);
     if (!is_null($role)) {
         $roleArr = [$this->tables["userRoles"]["userId"] => Nette\Utils\Validators::isNumericInt($user) ? $user : $user->id, $this->tables["userRoles"]["roleId"] => $role->getId()];
         $this->database->table($this->tables["userRoles"]["table"])->where($roleArr)->delete();
     }
 }
Example #9
0
 /**
  * Is a control's value decimal number?
  * @return bool
  * @internal
  */
 public static function validateInteger(TextBase $control)
 {
     return Validators::isNumericInt($control->getValue());
 }
Example #10
0
 /**
  * Convert string -> int, string -> float because of textual x-www-form-data
  * @param mixed $value
  * @return mixed
  */
 protected function parseNumericValue($value)
 {
     if (Validators::isNumericInt($value)) {
         return (int) $value;
     }
     if (Validators::isNumeric($value)) {
         return (double) $value;
     }
     return $value;
 }
Example #11
0
 protected function registerCookiesValidators()
 {
     $this->cookies->registerValidator('sys_shift_pattern_id', function ($id) {
         return \Nette\Utils\Validators::isNumericInt($id);
     });
 }
Example #12
0
 public static function isNumber($number)
 {
     return Validators::isNumericInt($number) && $number >= 0;
 }
Example #13
0
 function loadState(array $params)
 {
     parent::loadState($params);
     if (count($this->sort) == 0) {
         foreach ($this->defaultSort as $k => $v) {
             if (!isset($this->sort[$k])) {
                 $this->sort[$k] = $v;
             }
         }
     }
     foreach ($this->sort as $k => $v) {
         if (!in_array($k, $this->enabledSort) && !isset($this->defaultSort[$k])) {
             unset($this->sort[$k]);
             continue;
         }
         if (!in_array($v, array_keys($this->enableValues))) {
             unset($this->sort[$k]);
             continue;
         }
     }
     foreach ($this->defaultFilter as $k => $v) {
         if (!isset($this->filter[$k])) {
             $this->filter[$k] = $v;
         }
     }
     foreach ($this->filter as $k => $v) {
         if (!in_array($k, $this->enableFilter)) {
             unset($this->filter[$k]);
             continue;
         }
     }
     if (!is_null($this->countCallback)) {
         $this->count = call_user_func($this->countCallback, $this->getDbFilter());
     } else {
         throw new \LogicException('Missing count callback');
     }
     $this->limit = Nette\Utils\Validators::isNumericInt($this->limit) ? $this->limit : static::DEFAULT_LIMIT;
     $this->page = Nette\Utils\Validators::isNumericInt($this->page) && $this->page <= ceil($this->count / $this->limit) && $this->page > 0 ? $this->page : 1;
     $this->cleanSortKeys = $this->defaultSort;
     foreach ($this->enabledSort as $k => $v) {
         if (isset($this->cleanSortKeys[$k])) {
             unset($this->cleanSortKeys[$k]);
         }
     }
 }
Example #14
0
validatePattern(TextBase$control,$pattern){return(bool)Strings::match($control->getValue(),"\x01^($pattern)$\x01u");}static
function
validateInteger(TextBase$control){return
Validators::isNumericInt($control->getValue());}static
Example #15
0
 /**
  * @param \Nette\DI\ContainerBuilder $builder
  */
 private function buildAuthorizatorList(ContainerBuilder $builder)
 {
     $services = [];
     foreach ($builder->findByTag($this->prefix(self::AUTHORIZATOR_TAG)) as $name => $priority) {
         if (!Validators::isNumericInt($priority)) {
             throw new \Nette\InvalidArgumentException(sprintf('Authorizator priority for service %s has to be integer, %s given.', $name, gettype($priority)));
         }
         $services[(int) $priority][] = $name;
     }
     krsort($services);
     return iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveArrayIterator($services)), FALSE);
 }