/** * Performs an authentication. * @param array $credentials * @return Identity * @throws AuthenticationException */ public function authenticate(array $credentials) { list($username, $password) = $credentials; $row = $this->db->select('*')->from(self::TABLE_NAME)->where(self::COLUMN_NAME . ' = %s', $username)->fetch(); if (!$row) { throw new AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND); } elseif (!Passwords::verify($password, $row[self::COLUMN_PASSWORD_HASH])) { throw new AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL); } elseif (Passwords::needsRehash($row[self::COLUMN_PASSWORD_HASH])) { $row[self::COLUMN_PASSWORD_HASH] = Passwords::hash($password); } $arr = $row->toArray(); unset($arr[self::COLUMN_PASSWORD_HASH]); return new Identity($row[self::COLUMN_ID], $row[self::COLUMN_ROLE], $arr); }
/** * It generates basic Dibi\Fluent SQL for getting one node. * @return Dibi\Fluent */ public function selectNodeSqlFactory($selectId = False) { $DF = new Fluent($this->connection); if ($selectId) { $DF = $this->connection->select("`" . $this->table->getAlias() . "`.`{$this->id}`"); } else { $DF = $this->connection->select(False); } return $DF->from('`' . $this->table->getName() . '` AS `' . $this->table->getAlias() . '`'); }
/** * @param $name * @param $params */ public function saveContent($name, $params) { $names = $this->decodeNames($name); $locale = isset($params->locale) ? $params->locale : ''; $rowId = $this->connection->select('id')->from(self::TABLE)->where(['namespace' => $names->namespace, 'name' => $names->name, 'locale' => $locale])->fetchSingle(); $content = isset($params->content) ? $params->content : ''; if ($rowId) { // update $this->connection->update(self::TABLE, ['content' => $content])->where(['id' => $rowId])->execute(); } else { // new $this->connection->insert(self::TABLE, ['namespace' => $names->namespace, 'name' => $names->name, 'locale' => $locale, 'content' => $content])->execute(); } $this->findContentAndFillCache($names->namespace, '', ''); }
public function getCurrentVersion() { $version = $this->connection->select('%n', 'version')->from('%n', $this->table)->orderBy('%n DESC', 'version')->fetchSingle(); return $version ? (int) $version : 0; }
/** * @param $cond * @return \Dibi\Fluent */ public function getAllWhereOr($cond) { return $this->db->select('*')->from($this->tableName)->where('%or', $cond); }
public function getMapData($xMax, $xMin, $yMax, $yMin) { return $this->database->select('*')->from($this->table)->where('x <= %i', $xMax)->where('x >= %i', $xMin)->where('y <= %i', $yMax)->where('y >= %i', $yMin)->fetchAll(); }