/**
  * Add the RateLimit to the response cookies.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Illuminate\Http\Response $response
  * @return \Illuminate\Http\Response
  */
 protected function addRateLimitToResponse($request, $response, $limit)
 {
     $throttle = $this->throttle->get($request);
     $response->header('x-rate-limit-limit', $limit);
     $response->header('x-rate-limit-remaining', $limit - $throttle->count());
     return $response;
 }
 public function handle($request, Closure $next)
 {
     $response = new Response();
     if (Auth::check() === false) {
         $request->request->set('roleId', $this->retrieveRoleIdByName('Customer'));
         return $next($request);
     }
     $user = Auth::user();
     if ($user === null) {
         $response->header(Constants::RESPONSE_HEADER, "Failed to retrieve authenticated user.");
         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
         return $response;
     }
     $role = Roles::where('id', $user->role_id)->firstOrFail();
     if ($role->name !== "Administrator") {
         $response->header(Constants::RESPONSE_HEADER, "Permission are required for performing registration operation.");
         $response->setStatusCode(Response::HTTP_FORBIDDEN);
         return $response;
     }
     try {
         $roleName = $request->get('roleName');
         if ($roleName === null) {
             $request->request->set('roleId', $this->retrieveRoleIdByName('Customer'));
         } else {
             $request->request->set('roleId', $this->retrieveRoleIdByName($roleName));
         }
     } catch (Exception $exception) {
         $response->header(Constants::RESPONSE_HEADER, $exception->getMessage());
         $response->setStatusCode(Response::HTTP_BAD_REQUEST);
         return $response;
     }
     return $next($request);
 }
Example #3
0
 public function getResource(Request $request, Log $logger, $path)
 {
     // Get date metadata and calculate ETag
     $timestamp = $this->fs->getTimestamp($path);
     $ETag = md5($path . $timestamp);
     $date = new DateTime("@{$timestamp}");
     $response = new Response();
     $response->setLastModified($date)->setEtag($ETag, true)->setPublic();
     // Check modified date and Etag before attempting to retrieve actual content
     if ($response->isNotModified($request)) {
         return $response;
     }
     $content = $this->fs->read($path);
     if (!$content) {
         // We had a false positive from the cache!!
         $this->deleteFromCache($path);
         $logger->warning('File not found (cache false positive)', array('path' => $path));
         abort(404);
     }
     $contentType = $this->fs->getMimetype($path);
     if (env('EXAMPLE_DIR') && starts_with($path, env('EXAMPLE_DIR'))) {
         // Path is within our "examples" directory, force the file to be downloaded
         $disposition = $response->headers->makeDisposition(HeaderBag::DISPOSITION_ATTACHMENT, basename($path));
         $response->header('Content-Disposition', $disposition);
     }
     return $response->header('Content-Type', $contentType)->setContent($content);
 }
Example #4
0
 public function getImage($id, $hash, Request $request)
 {
     $entry = StorageEntry::findOrFail($id);
     if ($hash != $entry->hash) {
         abort(404);
     }
     $response = new Response($this->makeImage($entry, $request->has('w') ? $request->input('w') : null, $request->has('h') ? $request->input('h') : null), 200);
     $response->header('Content-Type', $entry->mime);
     $response->header('Cache-Control', 'max-age=86400');
     return $response;
 }
 public function createUser(Request $request, Response $response)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $response->header(Constants::RESPONSE_HEADER, "Validation failed with the following error messages: [" . $validator->errors() . "].");
         $response->setStatusCode(Response::HTTP_BAD_REQUEST);
         return $response;
     }
     $user = User::create(['email' => $request->input('email'), 'password' => bcrypt($request->input('password')), 'first_name' => $request->input('firstname'), 'last_name' => $request->input('lastname'), 'role_id' => $request->input('roleId'), 'object_name' => $request->input('objectName')]);
     if ($user === null) {
         $response->header(Constants::RESPONSE_HEADER, "Failed to create user.");
         $response->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
         return $response;
     }
     return $user;
 }
 /**
  * New thread (not the create thread page)
  * @param Request $request
  * @return string
  */
 public function newThread(Request $request)
 {
     // Validate input
     $this->validate($request, ['title' => 'required|max:255', 'forum' => 'required|numeric', 'body' => 'required|max:30000']);
     // Verify forum is a valid forum that can be posted in
     $forum = null;
     try {
         $forum = Forum::findOrFail($request->input('forum'));
     } catch (ModelNotFoundException $e) {
         abort(400);
         // 400 Bad Request - invalid forum id
     }
     if ($forum->type != 0) {
         abort(400);
         // 400 Bad Request - not correct forum type
     }
     // Create thread
     $thread = Thread::newThread($request->input('title'), $request->input('forum'));
     // Create opening post
     $post = post::newPost($request->input('body'), $thread->id);
     // Generate response
     $resp = new Response(json_encode(['status' => true, 'link' => $thread->getUserFriendlyURL()]), 200);
     $resp->header('Content-Type', 'application/json');
     return $resp;
 }
 public function retrieveUserData(Request $request, Response $response)
 {
     if (Auth::check() === false) {
         $response->header(Constants::RESPONSE_HEADER, "There is no authenticated user.");
         $response->setStatusCode(Response::HTTP_NO_CONTENT);
         return $response;
     }
     $user = Auth::user();
     if ($user === null) {
         $response->header(Constants::RESPONSE_HEADER, "There is no authenticated user.");
         $response->setStatusCode(Response::HTTP_NO_CONTENT);
         return $response;
     }
     Log::debug("Retrieved user data: [" . json_encode($user) . "]");
     return $user;
 }
 public function postRegister(Request $request)
 {
     $errors = [];
     // Validate all fields have been received.
     $validator = \Validator::make($request->all(), array('email' => 'required|email|max:128|unique:users,email', 'username' => 'required|min:1|max:20|unique:users,name', 'password' => 'required|min:6|max:255', 'g-recaptcha-response' => 'recaptcha'));
     if ($validator->fails()) {
         // Validator detected some problems.
         foreach ($validator->errors()->getMessages() as $error) {
             $errors[] = $error;
         }
     }
     if (count($errors) > 0) {
         // Errors detected, generate response
         $response = new Response(json_encode(['status' => false, 'errors' => $errors]), 200);
         $response->header('Content-Type', 'application/json');
         return $response;
     }
     // Get input
     $email = $request->input('email');
     $username = $request->input('username');
     $password = $request->input('password');
     // Register user
     $user = User::register($email, $username, $password);
     // Login
     Auth::login($user);
     // Generate response
     $response = new Response(json_encode(['status' => true]), 200);
     $response->header('Content-Type', 'application/json');
     return $response;
 }
Example #9
0
 public function getQr(Request $req)
 {
     $qrCode = new QrCode();
     $qrCode->setText("http://10.0.20.55:8001/index/wel#/sys/activities/one")->setSize(300)->setPadding(10)->setErrorCorrection('high')->setForegroundColor(array('r' => 0, 'g' => 0, 'b' => 0, 'a' => 0))->setBackgroundColor(array('r' => 255, 'g' => 255, 'b' => 255, 'a' => 0));
     $response = new Response($qrCode->get(), 200);
     $response->header('content-type', 'image/png');
     return $response;
 }
 public function get_captcha_image()
 {
     $fname = Input::get('fname');
     $content = file_get_contents($fname);
     $response = new Response($content, 200);
     $response->header('Content-Type', "image/png");
     return $response;
 }
Example #11
0
 /**
  * Attempt to create local response type from guzzle response
  *
  * @param  GuzzleResponse $guzzleResponse
  *
  * @return Response
  */
 protected static function createLocalResponse(GuzzleResponse $guzzleResponse)
 {
     $response = new Response($guzzleResponse->getBody(), $guzzleResponse->getStatusCode());
     $headers = $guzzleResponse->getHeaders();
     array_walk($headers, function ($values, $name) use($response) {
         $response->header($name, implode(', ', $values), true);
     });
     return $response;
 }
 public function findUserById(Request $request, Response $response)
 {
     $validator = Validator::make($request->all(), ['id' => 'required|numeric']);
     if ($validator->fails()) {
         $response->header(Constants::RESPONSE_HEADER, "\"id\" query parameter is required and must contain number as value.");
         $response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY);
         return $response;
     }
     $id = $request->input("id");
     $product = User::with('role')->find($id);
     if ($product === null) {
         $response->header(Constants::RESPONSE_HEADER, "User not found.");
         $response->setStatusCode(Response::HTTP_NO_CONTENT);
         return $response;
     }
     $response->header(Constants::RESPONSE_HEADER, "Successfully retrieved data.");
     return $product;
 }
Example #13
0
 protected function notFoundResponse()
 {
     if ($this->config['handler_404'] == 'default') {
         abort(404);
     } else {
         $image = base64_decode('iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAYAAAAeP4ixAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAP6UlEQVRoga06aVAc15lf9/QMAww3w31K3CBAIARCSDaSbGVjWyvbK6esxPFRqWxtVZLarUp5t1zZrP1jq3az+ZHKUZtUee1kfcmWrSO2bCeKRUwkWZaAcAqQkEAMMDADczADc/a8/d7r7qGHGVgk+VGP7vf6ve++Xvdw8BW1vuuXiudNtg7bkmuXZ9VbGxSDhSGR5AOQJLaA4+w8xy8IWn42Pj5+KC3d0Jefk3mhsbF99qvAf1+M9I9fzr913fy8xWI75vcH6u8Fhk6nHczKSj25vTT/9fth6p4YufrXS43XBydedDrdxwghAgGCgHiQrmsg6VhCQTZETtg/AqitYGp60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Cehw6+rqEs59/OkndrvjkDJHGdjTUQcHHm7GI7EWNjh4bwCSRA85FdXhE6b00Ovxw/lPr8K1K2PhUoQ2ozH9T89865lHamujvyduWB+MjHQZXn31oz8su9zt6lheVVMCjxzpQKBpIIXU6LN9NAP//1sX2ZLBbLbCubMX6XcQVXFKIDU1+fILzz9/GJmI+elt00KHMvM/r310xul0H1TPp6YlwYOdu6G5pQ4dOB42bZu9cVGOh9hWVjxw5XI//OXzHnC5VlWLCGRkpJ1/9ttfe6K2tvPuP4YqbWRkRHfixIn/mjNbfhCxEZNFbm4m7Nm7C+obqiE1JTnijcpmTbEsWm07HMvQ3z8MX1zuA8uCTc7aCveYAgrzf7N///7vdXZ2BjeDueXS81e/+sU3+gdHfomVcWYEAIRAf9lQWVUOdXXViBhLG2RKq9Wy0KyYnfJhk36qszscMHVnGoYHR2BiYir6+zown3Tsaq75zne/+/0PtkLfXdXkXV0fZp775NJP7Tb7M8ByUKTdUI3o9XpITjLQww5jkP7qgTav1wvLyy7UgIO+r2UMkdgntBD63xuPPdr54t69hy1bpe1eDhfw5puv1VzrHX7Z7VqhHyWF2KvkWouoAtLmzh9MSTGcbGtt+slTT32z/25puidGlPbeh+/lD1wdet66sHRMDIn39DMnrCQGs3OMJ5sbK3939OjTJrjHdl+MqNs7Z94pnB6fPGBdcjSuuD0NwWAwHwtDI2ohjSHiOBd2s1YrzBoSEwaysow9pdW5F5985Jt37h87wP8BN8/KqbSj3wkAAAAASUVORK5CYII=');
         $response = new Response($image, 404);
         return $response->header('Content-Type', 'image/png');
     }
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $response = $next($request);
     // This step is only needed if you are returning
     // a view in your Controller or elsewhere, because
     // when returning a view `$next($request)` returns
     // a View object, not a Response object, so we need
     // to wrap the View back in a Response.
     if (!$response instanceof SymfonyResponse) {
         $response = new Response($response);
     }
     /**
      * @var  $headers  \Symfony\Component\HttpFoundation\HeaderBag
      */
     $response->header('Pragma', 'no-cache');
     $response->header('Expires', 'Fri, 01 Jan 1990 00:00:00 GMT');
     $response->header('Cache-Control', 'no-cache, must-revalidate, no-store, max-age=0, private');
     return $response;
 }
 /**
  * @param Response $response
  * @param string $mimeType
  */
 protected function sendResponse(Response $response, $mimeType)
 {
     if (empty($mimeType)) {
         $mimeType = 'text/html';
     }
     $response->header('Content-type', $mimeType);
     $response->setStatusCode(404);
     $response->send();
     exit;
 }
Example #16
0
 private function response($status, $arguments)
 {
     $content = isset($arguments[0]) ? $arguments[0] : '';
     $headers = isset($arguments[1]) ? $arguments[1] : [];
     $response = new IlluminateResponse($content, $status);
     foreach ($headers as $key => $value) {
         $response->header($key, $value, true);
     }
     return $response;
 }
 public function persistOrder(Request $request, Response $response, $requestBody, $user)
 {
     DB::transaction(function () use(&$response, &$requestBody, &$user) {
         $deliveryInfo = new \stdClass();
         $deliveryInfo->email = $requestBody->email;
         $deliveryInfo->phone = $requestBody->phone;
         $deliveryInfo->address = $requestBody->address;
         $baseOrderEntry = null;
         foreach ($requestBody->products as $product) {
             $createdEntry = Orders::create(["user_id" => $user->id, "product_id" => $product->id, "order_date" => date("Y-m-d H:i:s"), "delivery_date" => date("Y-m-d H:i:s"), "is_payed" => 0, "delivery_info" => json_encode($deliveryInfo, JSON_UNESCAPED_UNICODE), "in_order_with" => $baseOrderEntry !== null ? $baseOrderEntry->id : 0, "order_count" => $product->quantity]);
             if ($baseOrderEntry === null) {
                 $baseOrderEntry = $createdEntry;
             }
         }
         $response->header("Content-Type", "application/json");
         $response->header(Constants::RESPONSE_HEADER, "Successfully persisted entity.");
         $response->setStatusCode(Response::HTTP_CREATED);
     });
     return $response;
 }
Example #18
0
 public function render($data, $serializerGroups = array())
 {
     $result = is_array($data) ? array('data' => array('items' => $data)) : array('data' => $data);
     $response = new Response();
     $context = SerializationContext::create()->enableMaxDepthChecks();
     if ($serializerGroups) {
         $context->setGroups($serializerGroups);
     }
     $content = Serializer::serialize($result, 'json', $context);
     $response->setContent($content);
     $response->header('Content-Type', 'application/json', true);
     return $response;
 }
 /**
  * TODO: добавить кеширование вывода
  * 
  * @param FrontendPage $frontPage
  * @return \Illuminate\View\View|null
  * @throws LayoutNotFoundException
  */
 protected function render(FrontendPage $frontPage)
 {
     event('frontend.found', [$frontPage]);
     app()->singleton('frontpage', function () use($frontPage) {
         return $frontPage;
     });
     $layout = $frontPage->getLayoutView();
     if (is_null($layout)) {
         throw new LayoutNotFoundException();
     }
     $widgetCollection = new PageWidgetCollection($frontPage);
     $html = (string) $frontPage->getLayoutView();
     if (auth()->check() and auth()->user()->hasRole(['administrator', 'developer'])) {
         $injectHTML = (string) view('cms::app.partials.toolbar');
         // Insert system HTML before closed tag body
         $matches = preg_split('/(<\\/body>)/i', $html, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
         if (count($matches) > 1) {
             /* assemble the HTML output back with the iframe code in it */
             $html = $matches[0] . $injectHTML . $matches[1] . $matches[2];
         }
     }
     $response = new Response();
     $response->header('Content-Type', $frontPage->getMime());
     if (config('cms.show_response_sign', TRUE)) {
         $response->header('X-Powered-CMS', \CMS::NAME . '/' . \CMS::VERSION);
     }
     $response->setContent($html);
     // Set the ETag header
     $response->setEtag(sha1($html));
     $response->setLastModified($frontPage->getCreatedAt());
     // mark the response as either public or private
     $response->setPublic();
     // Check that the Response is not modified for the given Request
     if ($response->isNotModified($this->request)) {
         // return the 304 Response immediately
         return $response;
     }
     return $response;
 }
Example #20
0
 /**
  * Receive and process an incoming Twilio request.
  *
  * @param Request $request
  * @return Response|null
  */
 public function receive(Request $request)
 {
     // dispatch job
     $response = $this->dispatch(new RespondToIncomingText($request->all()));
     // if there was a response, return a Twmiml object
     if (!is_null($response)) {
         $response = $this->twimlFormatter->format($response['message'], $response['toPhone']);
         $response = new Response($response, 200);
         $response->header('Content-Type', 'text/xml');
         return $response;
     }
     // if NULL response, return NULL to Twilio request
     return NULL;
 }
 /**
  * @param View   $layout
  * @param string $mime
  *
  * @return \Illuminate\View\View|null
  * @throws LayoutNotFoundException
  */
 protected function render(View $layout = null, $mime = 'text\\html')
 {
     if (is_null($layout)) {
         throw new LayoutNotFoundException(trans('pages::core.messages.layout_not_set'));
     }
     $html = $layout->render();
     $response = new Response();
     $response->header('Content-Type', $mime);
     if (config('cms.show_response_sign', true)) {
         $response->header('X-Powered-CMS', CMS::getFullName());
     }
     $response->setContent($html);
     // Set the ETag header
     $response->setEtag(md5($html));
     // mark the response as either public or private
     $response->setPublic();
     // Check that the Response is not modified for the given Request
     if ($response->isNotModified($this->request)) {
         // return the 304 Response immediately
         return $response;
     }
     return $response;
 }
Example #22
0
 public function makeResponse()
 {
     $content = $this->renderToString();
     if ($this->redirect !== null) {
         $url = '' . $this->redirect;
         return new RedirectResponse($url);
     }
     $response = new Response();
     // Headers are also calculated in render to string
     if ($this->isJsonResponse()) {
         $response->header("Content-type", "application/json;");
     }
     $response->setContent($content);
     return $response;
 }
Example #23
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     $nice_token = $request->input('_token');
     $config_token = Config('nice-artisan.token');
     if (!$config_token || $nice_token != $config_token) {
         if (!$this->checkUser($request)) {
             if ($request->ajax()) {
                 $response = new Response('Access denied', 403);
                 $response->header('Content-Type', 'text/plain');
                 return $response;
             } else {
                 return redirect()->to('/')->with('error', 'Acces denied!');
             }
         }
     }
     return $next($request);
 }
 public function newPost(Request $request)
 {
     // Ensure
     // Collect input
     $threadid = $request->input('thread', 0);
     $content = $request->input('body', '');
     if ($content == '' || $threadid == 0) {
         abort(400);
         // 400 Bad Request
     }
     // Run post through filters
     $content = PostProcessor::preProcess($content);
     // Create new post
     $post = Post::newPost($content, $threadid);
     // Generate response
     $resp = new Response(json_encode(['status' => true, 'html' => $post->getPostView()->render()]), 200);
     $resp->header('Content-Type', 'application/json');
     return $resp;
 }
 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     $app = $this->app;
     // Generate sitemap.xml route
     if ($app['config']->get('seotools::sitemap.enabled')) {
         $this->app['router']->get('sitemap.xml', function () use($app) {
             if ($app['config']->get('seotools::sitemap.cache')) {
                 $sitemap = $app['cache']->remember('seotools::sitemap.xml', $app['config']->get('seotools::sitemap.cachetime'), function () use($app) {
                     $app['vinicius73.seotools.generators.sitemap.run']->run();
                     return $app['vinicius73.seotools.generators.sitemap']->generate();
                 });
             } else {
                 $sitemap = $app['vinicius73.seotools.generators.sitemap.run']->run();
             }
             $response = new Response($sitemap, 200);
             $response->header('Content-Type', 'text/xml');
             return $response;
         });
     }
 }
Example #26
0
 /**
  * Generate default routes for /sitemap.xml and /robots.txt
  *
  * @return void
  */
 public function generateDefaultRoutes()
 {
     $app = $this->app;
     // Create the default robots.txt content
     $app['calotype.seo.generators.robots']->addUserAgent('*');
     $app['calotype.seo.generators.robots']->addDisallow('');
     $app['calotype.seo.generators.robots']->addSpacer();
     $app['calotype.seo.generators.robots']->addSitemap($app['request']->root() . '/sitemap.xml');
     // Generate sitemap.xml route
     $app['router']->get('sitemap.xml', function () use($app) {
         $response = new Response($app['calotype.seo.generators.sitemap']->generate(), 200);
         $response->header('Content-Type', 'application/xml');
         return $response;
     });
     // Generate robots.txt route
     $app['router']->get('robots.txt', function () use($app) {
         $response = new Response($app['calotype.seo.generators.robots']->generate(), 200);
         $response->header('Content-Type', 'text/plain');
         return $response;
     });
 }
Example #27
0
 /**
  * @param string $data
  * @param $status
  * @return mixed
  **/
 protected function generateResponse($data, $status)
 {
     $headers = ['Content-type' => $this->responseFormatter->getContentType()];
     if (config('transfugio.http.enableCORS')) {
         $headers['Access-Control-Allow-Origin'] = '*';
     }
     if ($this->options['format'] === 'html') {
         $response = new WebView($data, $status);
         $response->setModelName($this->options['modelName']);
         if (isset($this->options['paginationCode']) && strlen($this->options['paginationCode']) > 0) {
             $response->setIsCollection = true;
             $response->setPaginationCode($this->options['paginationCode']);
         }
         $response->setIsError(200 <= $status && $status <= 299);
         $response->render();
     } else {
         $response = new Response($data, $status);
     }
     foreach ($headers as $name => $value) {
         $response->header($name, $value);
     }
     return $response;
 }
Example #28
0
 /**
  * Set the PJAX-URL header to the current uri.
  *
  * @param Response $response
  * @param Request  $request
  */
 protected function setUriHeader(Response $response, Request $request)
 {
     $response->header('X-PJAX-URL', $request->getRequestUri());
 }
Example #29
0
 /**
  * Prepare the headers for the response.
  */
 protected function prepareHeaders()
 {
     $contentType = $this->getContentType();
     $header = $contentType . '; charset=' . $this->charset;
     $this->response->header('Content-Type', $header);
 }
Example #30
0
 public function getDashboardTSV(Request $request)
 {
     $date = carbonCheckorNow($request->input('date'));
     //echo $date->month.' - '. $date->daysInMonth .'<br>';
     $bb = $this->bb->with('branch')->all();
     echo "date\t";
     foreach ($bb as $b) {
         echo $b->branch->code . "\t";
     }
     echo PHP_EOL;
     //echo '<br>';
     for ($i = 1; $i <= $date->daysInMonth; $i++) {
         $day = Carbon::parse($date->year . '-' . $date->month . '-' . $i);
         echo $day->format('Ymd') . "\t";
         foreach ($bb as $b) {
             $ds = $this->repo->findWhere(['date' => $day->format('Y-m-d'), 'branchid' => $b->branchid])->first();
             echo is_null($ds) ? 0 : $ds->sales;
             echo "\t";
         }
         echo PHP_EOL;
         //echo '<br>';
     }
     $response = new Response();
     $response->header('Content-Type', 'plain/text');
     $response->header('Content-Disposition', 'attachment; filename="data.tsv"');
     return $response;
 }