/** * @param array $values * @return Comment * @throws ActionFailedException */ public function save(array $values) { $numberOfComments = $this->getNumberOfComments($values['page']); $repliesReferences = $this->findRepliesReferences($values['text']); try { $this->em->beginTransaction(); // no replies references found if (empty($repliesReferences)) { $comment = new Comment($values['author'], $this->texy->process($values['text']), $values['page'], $numberOfComments + 1, $this->request->getRemoteAddress()); $this->em->persist($comment)->flush(); $this->em->commit(); return $comment; } $commentsToReply = $this->findCommentsToReply($values['page'], $repliesReferences); $values['text'] = $this->replaceReplyReferencesByAuthors($values['text'], $commentsToReply); $comment = new Comment($values['author'], $this->texy->process($values['text']), $values['page'], $numberOfComments + 1); $this->em->persist($comment); /** @var Comment $comment */ foreach ($commentsToReply as $commentToReply) { $commentToReply->addReaction($comment); $this->em->persist($commentToReply); } $this->em->flush(); $this->em->commit(); } catch (\Exception $e) { $this->em->rollback(); $this->em->close(); throw new ActionFailedException(); } return $comment; }
/** * Sets the user identity. * @param Nette\Security\IIdentity $identity * @return Storage */ public function setIdentity(Nette\Security\IIdentity $identity = NULL) { if (!is_null($identity)) { $identity->browser = $this->browser->getName(); $identity->browserVersion = $this->browser->getVersion(); $identity->hash = $this->identityHash->createIdentityHash($identity->getId(), $this->request->getRemoteAddress()); } return parent::setIdentity($identity); }
protected function startup() { parent::startup(); $devIPs = array('10.107.91.237'); if (!in_array($this->request->getRemoteAddress(), $devIPs) && $this->maintenance) { if ($this->getPresenter()->name != "Homepage" || $this->getAction() != "maintenance") { $this->redirect("Homepage:maintenance"); } } $nonLoginPresenters = array('Sign', 'Homepage', 'Api'); $presenterName = $this->getPresenter()->name; if (!in_array($presenterName, $nonLoginPresenters) && $this->user->isLoggedIn() != true) { $this->flashMessage("Pro vstup do systému se přihlašte, prosím."); $this->redirect("Sign:in"); } }
/** * @param string $language * @param Basket $basket * @throws AbortException */ public function createOrder($language, Basket $basket) { $customer = array('firstname' => $basket->getName(), 'lastname' => $basket->getSurname(), 'telephone' => $basket->getPhone(), 'email' => $basket->getEmail(), 'address' => $basket->getStreet(), 'city' => $basket->getCity(), 'postcode' => $basket->getPostcode(), 'comment' => $basket->getNote(), 'ip' => $this->request->getRemoteAddress(), 'user_agent' => $this->request->getHeader('User-Agent'), 'accept_language' => ''); $products = array(); foreach ($basket->getItems() as $item) { /** @var $item BasketItem */ $products[$item->getItemId()] = array('id' => $item->getItemId(), 'quantity' => $item->getQuantity()); } $order = array('language' => $language, 'products' => $products, 'customer' => $customer); //$response = $this->caller->call(Caller::GET, 'Fake', 'delay', array('seconds' => 2)); sleep(2); /* if ($response['status'] != "ok") { throw new AbortException; } */ }
public function saveData($searchString) { // get IP and actual Date $ip = $this->request->getRemoteAddress(); // get datetime $date = new \DateTime(); // new gneral entity $search = new Search(); $search->setSearch($searchString); $search->setDate($date); $search->setIp($ip); $this->em->persist($search); return $search; }
public function onLoggedIn(User $service) { // Only for real users (no PSK, etc...s) try { if (!$service->isInRole('user')) { return; } // If role does not exist } catch (Nette\InvalidStateException $e) { return; } $remoteAddr = $this->httpRequest->getRemoteAddress(); $uid = $service->getId(); // Sanity check if ($uid == NULL) { return; } $this->db->query('INSERT INTO %n', $this->tableName, '([userId], [time], [ip], [time2], [ip2]) VALUES(' . '%i', $uid, ', NOW(), %s', $remoteAddr, ', NULL, NULL) ' . 'ON DUPLICATE KEY UPDATE [time2] = [time], [ip2] = [ip], [time] = NOW(), [ip] = %s', $remoteAddr); }
/** * @param string $message * @param string $event * @param int|null $userID * @throws \Exception */ public function saveLog($message, $event, $userID = null) { $eventLog = $this->getEventLog($event); if ($eventLog === null) { return; // todo monolog log } if (!$this->isEventLoggable($eventLog)) { return; } try { $user = null; if (isset($userID)) { $user = $this->em->getReference(User::class, $userID); } $newLog = new Log($message, $this->em->getReference(EventLog::class, $eventLog->getId()), $this->request->getRemoteAddress(), $user); $this->em->persist($newLog)->flush(); } catch (ForeignKeyConstraintViolationException $e) { // todo if user doesn't exist $this->cache->remove(self::getEventLogCacheKey($event)); } }
/** * @param Nette\Http\Request $request * @return array Http parametry hlasujiciho uzivatele */ protected function getRequestInfo($request) { $result = ['ip' => $request->getRemoteAddress(), 'agent' => $request->getHeader('user-agent'), 'cookie' => $request->getCookie('nette-browser')]; return $result; }
/** * @param \Nette\Http\Request */ public function log(\Nette\Http\Request $req) { $this->server->send('access', array('ua' => $req->getHeader('User-Agent'), 'ip' => $req->getRemoteAddress(), 'host' => $req->getRemoteHost(), 'method' => $req->getMethod(), 'url' => (string) $req->getUrl(), 'memory' => function_exists('memory_get_peak_usage') ? number_format(memory_get_peak_usage() / 1000000, 2, '.', ' ') : 'n/a', 'time' => number_format((microtime(TRUE) - \Nette\Diagnostics\Debugger::$time) * 1000, 1, '.', ' '), 'referer' => (string) $req->getHeader('Referer'))); }
public function get() { return $this->format($this->user->isLoggedIn() ? $this->user->id : $this->request->getRemoteAddress()); }
public function getRemoteAddress() { return $this->request->getRemoteAddress(); }
public function l($akce, $detail = NULL) { $userID = $this->userService->isLoggedIn() ? $this->userService->id : NULL; $ip = $this->request->getRemoteAddress(); $this->insert(array('cas' => time(), 'ip' => $ip, 'akce' => $akce, 'detail' => $detail, 'uzivatel_id' => $userID)); }