/** * @return Nette\Application\IResponse */ public function run(Nette\Application\Request $request) { // Save the application request $this->appRequest = $request; // Setup authorization attempt logger $this->attemptLogger->setEvent(self::ATTEMPT_IP_TOKEN, 200, '1 hour', FALSE); // Convert trigger_error -> ErrorException (for error payload) set_error_handler(function ($severity, $message, $file, $line, $context) { if (($severity & error_reporting()) === $severity) { throw new \ErrorException($message, 0, $severity, $file, $line); } }); // Process the request with option to abort with another response try { $this->response = $this->process($request); } catch (AbortException $e) { // Do nothing } catch (\Exception $e) { // If there is no need to reformat error to the payload // I will just throw it right back if ($this->outputContentType == 'text/html' && !$this->isInProductionMode()) { throw $e; } Nette\Diagnostics\Debugger::log($e, 'error'); $payload = new \StdClass(); $payload->error = self::ERROR_INTERNAL; $payload->error_description = 'Error occured while processing your request. Error has been automatically reported. Please try again later.'; $payload->error_report_id = md5(preg_replace('~(Resource id #)\\d+~', '$1', $e)); $this->httpResponse->setCode(Nette\Http\IResponse::S500_INTERNAL_SERVER_ERROR); $this->response = $this->createResponse($payload); } return $this->response; }
public function __construct(DatabaseAttemptLogger $logger, Nette\Http\IRequest $httpRequest) { $this->logger = $logger; $this->httpRequest = $httpRequest; /// @todo configurable events $logger->setEvent(self::EVENT_IP_LOGIN_ATTEMPT, 80, '2 hours', FALSE); $logger->setEvent(self::EVENT_USER_LOGIN_ATTEMPT, 80, '1 hour', TRUE); }