protected function render($code, $x, $y, $method) { $file = $this->items->where('code', $code)->fetch(); $this->sourcepath = FILESTORAGE_DIR . '/' . $file->filepath; $this->cachepath = TEMP_DIR . '/imagecache/' . $file->id; $this->imagepath = $this->cachepath . '/' . $method . "-" . $x . "x" . $y . '.' . $file->filename; $expires = 60 * 60 * 24 * 31; $etag = '"' . md5($this->imagepath) . '"'; if (!empty($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $etag) { header('HTTP/1.1 304 Not Modified'); header('Content-Length: 0'); exit; } header('ETag: ' . $etag); header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT'); header("Pragma: public"); // required header("Cache-Control: maxage=" . $expires); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT'); header("Cache-Control: cache"); header("Cache-Control: private", false); // required for certain browsers header("Content-Transfer-Encoding: binary"); if (!file_exists($this->imagepath) || $file->changed > $file->created) { try { if (file_exists($this->sourcepath)) { $image = Image::fromFile($this->sourcepath); } else { $image = Image::fromBlank($x, $y, array('red' => 240, 'green' => 240, 'blue' => 240)); } @$image->resize($x, $y, $method); $image->sharpen(); if ($method == 5) { $image->crop(0, 0, $x, $y); } if (!file_exists($this->cachepath)) { mkdir($this->cachepath, 0777, true); chmod($this->cachepath, 0777); } if (file_exists($this->sourcepath)) { $image->save($this->imagepath, 66, Image::JPEG); } else { $image->string(2, 5, $y / 2 - 7, 'No image found', 1); } $image->send(); } catch (Exception $e) { } } else { header('Content-Disposition: inline; filename="' . $this->imagepath . '"'); header("Content-Type: image/jpeg"); header("Content-Length: " . @filesize($this->imagepath)); readfile($this->imagepath); } }
/** * Performs an authentication * @param array * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { list($username, $password) = $credentials; $row = $this->curators->where('username', $username)->fetch(); if (!$row) { throw new NS\AuthenticationException("Uživatel '{$username}' nebyl nalezen.", self::IDENTITY_NOT_FOUND); } if ($row->password !== $this->calculateHash($password)) { throw new NS\AuthenticationException("Špatné heslo.", self::INVALID_CREDENTIAL); } return new NS\Identity($row->username, NULL, $row->toArray()); }
/** * Performs an authentication * @param array * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { list($username, $password) = $credentials; $row = $this->users->where('username', $username)->fetch(); if (!$row) { throw new NS\AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND); } if ($row->password !== $this->calculateHash($password)) { throw new NS\AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL); } unset($row->password); return new NS\Identity($row->id, $row->role, $row->toArray()); }
/** * Performs an authentication * @param array * @return Nette\Security\Identity * @throws Nette\Security\AuthenticationException */ public function authenticate(array $credentials) { $user = $this->users->where('email', $credentials['email'])->fetch(); if (!$user) { $data = array("username" => $credentials['username'], "email" => $credentials['email'], "name" => $credentials['first_name'], "surname" => $credentials['last_name'], "sex" => strtoupper((string) $credentials['gender'][0]), "facebook_id" => $credentials['id'], "role" => "member", "password" => hash("sha512", strftime('%a%b%y') . str_repeat('mooow', 10)), "generated_password" => 1, "active" => 1); $user = $this->users->insert($data); } else { if ($user->facebook_id !== $credentials['id']) { $this->users->update(array('facebook_id' => $credentials['id'])); } } $this->users->update(array('last_login' => new DibiDateTime(), 'last_ip' => $_SERVER['REMOTE_ADDR'])); return new NS\Identity($user->id, $user->role, $user->toArray()); }
public function actionDetail($code) { $this->template->item = $this->item = $this->items->where('code', $code)->fetch(); if (!$this->template->item) { throw new \Nette\Application\BadRequestException('Dané místo nebylo nalezeno.', 404); } if (!$this->user->isLoggedIn() && ($this->item->visible == 0 || $this->item->deleted == 1 || $this->item->approved == 0)) { throw new \Nette\Application\BadRequestException('Toto místo není přístupné.', 404); } }