/** * Performs an authentication. * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { list($username, $password) = $credentials; $row = $this->database->table('users')->where('username', $username)->fetch(); if (!$row) { throw new Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND); } if ($row->password !== $this->calculateHash($password, $row->password)) { throw new Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL); } unset($row->password); return new Security\Identity($row->id, $row->role, $row->toArray()); }
/** * Performs an authentication. * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { list($username, $password) = $credentials; $row = $this->database->table(self::TABLE_NAME)->where(self::COLUMN_NAME, $username)->fetch(); if (!$row) { throw new Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND); } if ($row[self::COLUMN_PASSWORD] !== $this->calculateHash($password, $row[self::COLUMN_PASSWORD])) { throw new Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL); } $arr = $row->toArray(); unset($arr[self::COLUMN_PASSWORD]); return new Nette\Security\Identity($row[self::COLUMN_ID], $row[self::COLUMN_ROLE], $arr); }
public function getBySources(array $urls) { // get articles $sql = ' SELECT a.*, ia.place_id, p.lat, p.lng, s.url AS source FROM article AS a JOIN source AS s ON a.source_id = s.id JOIN is_about AS ia ON ia.article_id = a.id JOIN place AS p ON ia.place_id = p.id WHERE s.url IN (?) '; $pm = array(); $articles = $this->db->query($sql, $urls)->fetchAll(); // get tags $places = array(); foreach ($articles as $article) { $places[] = $article->place_id; } $sql = ' SELECT t.*, ht.place_id FROM tag AS t JOIN has_tag AS ht ON ht.tag_id = t.id WHERE ht.place_id IN (?) '; $tags = array(); foreach ($this->db->query($sql, $places) as $tag) { if (isset($tags[$tag->place_id])) { $tags[$tag->place_id][] = $tag; } else { $tags[$tag->place_id] = array($tag); } } // prepare placemarks foreach ($articles as $article) { $pm[] = (object) array('name' => $article->title, 'url' => $article->url, 'photo' => $article->photo_url, 'tags' => isset($tags[$article->place_id]) ? $tags[$article->place_id] : array(), 'lat' => $article->lat, 'lng' => $article->lng, 'icon' => Nette\Utils\Strings::webalize(self::$icons[$article->source]), 'source' => $article->source); } return $pm; }
<?php /** * Test: Nette\Database test boostap. * * @author Jakub Vrana * @author Jan Skrasek * @package Nette\Database */ require __DIR__ . '/../bootstrap.php'; if (!is_file(__DIR__ . '/databases.ini')) { Tester\Helpers::skip(); } $options = Tester\DataProvider::load('databases.ini', isset($query) ? $query : NULL); $options = isset($_SERVER['argv'][1]) ? $options[$_SERVER['argv'][1]] : reset($options); try { $connection = new Nette\Database\Connection($options['dsn'], $options['user'], $options['password']); } catch (PDOException $e) { Tester\Helpers::skip("Connection to '{$options['dsn']}' failed. Reason: " . $e->getMessage()); } Tester\Helpers::lock($options['dsn'], dirname(TEMP_DIR)); $driverName = $connection->getAttribute(PDO::ATTR_DRIVER_NAME);
/** * @return Nette\Database\Connection */ public function createServiceNette__database__default() { $service = new Nette\Database\Connection('mysql:host=127.0.0.1;dbname=pixwarecz27;port=8889', 'root', 'root', array('lazy' => TRUE)); $service->setContext(new Nette\Database\Context($service, new Nette\Database\Reflection\DiscoveredReflection($service, $this->getService('cacheStorage')), $this->getService('cacheStorage'))); Nette\Diagnostics\Debugger::getBlueScreen()->addPanel('Nette\\Database\\Diagnostics\\ConnectionPanel::renderException'); Nette\Database\Helpers::createDebugPanel($service, TRUE, 'default'); return $service; }
public function countAllWithSlug($slug) { return $this->database->table('pages')->where("slug", $slug)->count(); }
public function createAuthenticatorService() { return new Authenticator($this->database->table('users')); }
<?php if (@(!(include __DIR__ . '/vendor/autoload.php'))) { echo 'Install Nette using `composer install`'; exit(1); } $useCache = TRUE; date_default_timezone_set('Europe/Prague'); $connection = new Nette\Database\Connection('mysql:dbname=blog', 'root', ''); $cacheStorage = new Nette\Caching\Storages\FileStorage(__DIR__ . '/temp'); $connection->setCacheStorage($useCache ? $cacheStorage : NULL); $connection->setDatabaseReflection(new Nette\Database\Reflection\DiscoveredReflection($useCache ? $cacheStorage : NULL)); $dao = $connection; $time = -microtime(TRUE); ob_start(); foreach ($dao->table('user') as $user) { echo "{$user->name}:\n"; foreach ($user->related('article')->order('created')->limit(20) as $article) { echo "\t", $article->title, ' in ', $article->category->name, ' (', $article->related('comment')->count(), ")\n"; } } ob_end_clean(); echo 'Time: ', sprintf('%0.3f', $time + microtime(TRUE)), ' s | ', 'Memory: ', memory_get_peak_usage() >> 20, ' MB | ', 'PHP: ', PHP_VERSION, ' | ', 'Nette: ', Nette\Framework::VERSION;
/** * Získá tabulku číselníků * @return Nette\Database\Table\Selection */ public function getReference($referenceName) { return $this->database->table($referenceName)->order('ordering'); }
/** * @return Nette\Database\Connection */ protected function createServiceNette__database__default() { $service = new Nette\Database\Connection('mysql:host=87.197.23.74;dbname=atlasMineralov', 'cujan', 'cujan', NULL); $service->setCacheStorage($this->getService('cacheStorage')); Nette\Diagnostics\Debugger::$blueScreen->addPanel('Nette\\Database\\Diagnostics\\ConnectionPanel::renderException'); $service->setDatabaseReflection(new Nette\Database\Reflection\DiscoveredReflection($this->getService('cacheStorage'))); $service->onQuery[] = array($this->getService('nette.database.defaultConnectionPanel'), 'logQuery'); return $service; }