Extract referral code from GET-variable or cookie and save it into registry.

@param \Magento\Framework\App\FrontControllerInterface $subject
@param \Magento\Framework\App\RequestInterface $request
555283
public function beforeDispatch(
        \Magento\Framework\App\FrontControllerInterface $subject,
        \Magento\Framework\App\RequestInterface $request
    ) {
        $code = $request->getParam(static::REQ_REFERRAL);
        if (!empty($code)) {
            $this->session->logout();
        }
        $this->hlpRefCode->processHttpRequest($code);
    }
67620
public function getTokenFromRequest( RequestInterface $request ) {
		if ( $request->get( $this->key ) ) {
			return $request->get( $this->key );
		}

		if ( $request->post( $this->key ) ) {
			return $request->post( $this->key );
		}

		if ( $request->headers( $this->header ) ) {
			return $request->headers( $this->header );
		}

		return '';
	}
516566
public static function getCookie(ServerRequestInterface $request, string $name): string
    {
        $cookies = $request->getCookieParams();

        return isset($cookies[$name]) ? $cookies[$name] : '-';
    }
553120
public function handleRequest(Request $request, RequestHandler $responder): Promise
    {
        return call(function () use ($request, $responder) {
            $cookie = $request->getCookie($this->cookieName);

            $originalId = $cookie ? $cookie->getValue() : null;
            $session = new Session($this->storage, $originalId);

            $request->setAttribute($this->requestAttribute, $session);

            try {
                $response = yield $responder->handleRequest($request);
            } finally {
                if ($session->isLocked()) {
                    $session->unlock();
                }
            }

            if (!$response instanceof Response) {
                throw new \TypeError("Request handler must resolve to an instance of " . Response::class);
            }

            $id = $session->getId();

            if ($id === null || !$session->isRead()) {
                return $response;
            }

            if ($session->isEmpty()) {
                $attributes = $this->cookieAttributes->withExpiry(
                    new \DateTimeImmutable("@0", new \DateTimeZone("UTC"))
                );

                $response->setCookie(new ResponseCookie($this->cookieName, '', $attributes));

                return $response;
            }

            if ($cookie === null || $cookie->getValue() !== $id) {
                $response->setCookie(new ResponseCookie($this->cookieName, $id, $this->cookieAttributes));
            }

            $cacheControl = $response->getHeaderArray("cache-control");

            if (empty($cacheControl)) {
                $response->setHeader("cache-control", "private");
            } else {
                foreach ($cacheControl as $key => $value) {
                    $tokens = \array_map("trim", \explode(",", $value));
                    $tokens = \array_filter($tokens, function ($token) {
                        return $token !== "public";
                    });

                    if (!\in_array("private", $tokens, true)) {
                        $tokens[] = "private";
                    }

                    $cacheControl[$key] = \implode(",", $tokens);
                }

                $response->setHeader("cache-control", $cacheControl);
            }

            return $response;
        });
    }
69295
public function process(Request $request, DelegateInterface $frame)
    {
        $response = $frame->next($request);

        $cleared = $this->responseCookieJar->getClearedCookies();
        foreach ($cleared as $cookie) {
            $response->headers->clearCookie($cookie, DIR_REL . '/');
        }

        $cookies = $this->responseCookieJar->getCookies();
        foreach ($cookies as $cookie) {
            $response->headers->setCookie($cookie);
        }

        return $response;
    }
725107
private function buildSession(ServerRequestInterface $request)
    {
        $data = $this->handler->getCookie($request, $this->options['cookie_name']);

        $session = call_user_func([$this->options['session_class'], 'fromSerialized'], $data);
        if (!$session) {
            $session = new $this->options['session_class'];
        }

        return $session;
    }
615167
function authorize($subject='',$ondeny=NULL) {
        $f3=\Base::instance();
        if (!$this->granted($route=$f3->VERB.' '.$f3->PATH,$subject) &&
            (!isset($ondeny) || FALSE===$f3->call($ondeny,array($route,$subject)))) {
            $f3->error($subject?403:401);
            return FALSE;
        }
        return TRUE;
    }
413698
public function validateHeaders(WebRequest $request)
    {
        $settings = CsrfSettings::singleton();

        $headersValid = false;

        $referrerDomain = $this->getHost($request->header("Referer", ""));

        if ($referrerDomain != "") {
            if ($referrerDomain == $settings->domain){
                $headersValid = true;
            }
        } else {
            if ($this->getHost($request->header("Origin")) == $settings->domain) {
                $headersValid = true;
            }
        }

        if (!$headersValid){
            throw new CsrfViolationException();
        }
    }
659271
public function injectSubject(\PHPCraft\Subject\Subject $subject)
    {
        $this->subjects[$subject->name] = $subject;
    }
726825
protected function getRedisKey(ComponentInterface $subject, $type, $context)
    {
        return sprintf('%s:%s:%s:%s', $this->prefix, $subject->getHash(), $type, $context);
    }
596651
public function messagePage(ServerRequestInterface $request, UserInterface $user): ResponseInterface
    {
        $referer = $request->getHeaderLine('referer');

        $body    = $request->get('body', '');
        $subject = $request->get('subject', '');
        $to      = $request->get('to', '');
        $url     = $request->get('url', $referer);

        $to_user = $this->user_service->findByUserName($to);

        if ($to_user === null || $to_user->getPreference('contactmethod') === 'none') {
            throw new AccessDeniedHttpException('Invalid contact user id');
        }

        $title = I18N::translate('Send a message');

        return $this->viewResponse('message-page', [
            'body'    => $body,
            'from'    => $user,
            'subject' => $subject,
            'title'   => $title,
            'to'      => $to_user,
            'url'     => $url,
        ]);
    }
1363053
protected function getHttpCookie(CookieInterface $cookieModel, Request $request)
    {
        $modelName = $cookieModel->getName();

        if (null === $request->cookies || !$request->cookies->has($modelName)) {
            return null;
        }

        $cookie = $request->cookies->get($modelName);

        return $cookie;
    }
1072473
private function createHttpRequest(RequestInterface $request)
    {
        // Handle authentication first
        if ($this->authenticationMethod) {
            $request = $this->authenticationMethod->authorizeRequest($this, $request);
        }
        
        // The URL
        $url = ltrim(trim($request->getUrl()), '/');
        
        // Handle templated URLs
        if ($urlVariables = $request->getUrlVariables()) {
            $url = (new UriTemplate())->expand($url, $urlVariables);
        }
        
        // Headers
        $headers = [];
        $headersToAdd = $request->getHeaders();
        
        // The message body
        $body = null;
        if ($messageBody = $request->getMessageBody()) {
            $headers['Content-Type'] = $messageBody->getContentType();
            $headers['Content-Length'] = $messageBody->getContentLength();
            $body = $messageBody->getContent();
        }
        
        // Accept hal+json response
        if ($this->profile) {
            $headers['Accept'] = 'application/hal+json; profile="' . $this->profile . '"';
        } else {
            $headers['Accept'] = 'application/json';
        }
        
        // Prepare the Guzzle request
        if (Misc::isGuzzle6()) {
            // Guzzle 6
            $httpRequest = new \GuzzleHttp\Psr7\Request(
                $request->getMethod(),
                $url,
                array_merge($headers, $headersToAdd),
                $body ? \GuzzleHttp\Psr7\stream_for($body) : null
            );
        } else {
            // Guzzle 5.3
            $httpRequest = $this->client->createRequest($request->getMethod(), $url, ['exceptions' => false]);
            
            // verify option for HTTPS requests if needed
            if (($verify = Misc::verify($url, __DIR__ . '/../CA/')) !== null) {
                $httpRequest->getConfig()->set('verify', $verify);
            }
            
            foreach ($headers as $key => $value) {
                $httpRequest->setHeader($key, $value);
            }
            
            foreach ($headersToAdd as $key => $value) {
                $httpRequest->setHeader($key, $value);
            }
            
            if ($body) {
                $httpRequest->setBody(\GuzzleHttp\Stream\Stream::factory($body));
            }
        }
        
        return $httpRequest;
    }
990247
public function afterExecute(Action $subject, $result)
    {
        // Get the code id from the original request
        $codeId = $subject->getRequest()->getParam('code_id');

        // Access protected checkoutSession property with a Closure proxy
        $getQuoteProxy = function () use ($subject) {
            return $subject->checkoutSession->create()->getQuote();
        };
        $quote = $getQuoteProxy->call($subject);

        // Remove Amasty Gift Cart from the parent (session) quote
        $this->discountHelper->removeAmastyGiftCard($codeId, $quote);

        // Access protected updateTotalsInQuote method with a Closure proxy
        $updateTotalsInQuoteProxy = function () use ($subject, $quote) {
            $subject->updateTotalsInQuote($quote);
        };
        $updateTotalsInQuoteProxy->call($subject);

        return $result;
    }
1195909
public function render(Subject $subject)
    {
        $controller = $this->_controller();
        $controller->viewBuilder()->setClassName('CrudJsonApi.JsonApi');

        // render a JSON API response with resource(s) if data is found
        if (isset($subject->entity) || isset($subject->entities)) {
            return $this->_renderWithResources($subject);
        }

        return $this->_renderWithoutResources();
    }
970229
public function authenticateAction(Request $request)
    {
        if(!$this->getUser())
        {
            //Get redirecting route
            $referer = $request->headers->get('referer');
            //Get section on the page to be redirected at
            $pageSection = $request->get('section', false);

            $this->get('session')->set('refererUrl', $referer);

            if($pageSection)
            {
                $this->get('session')->set('refererUrlSection', $pageSection);
            }
        }

        $user = $this->get('security.token_storage')->getToken()->getUser();
        if (!is_object($user) || !$user instanceof UserInterface)
        {
            throw new AccessDeniedException('Please login first.');
        }

        $redirectURL = $this->get('session')->get('refererUrl', null);
        $redirectURLSection = $this->get('session')->get('refererUrlSection', null);

        if(!$redirectURL || $redirectURL == $this->generateUrl('ed_blog_redirect_authenticate', array(), true))
        {
            return $this->redirectToRoute("ed_blog_homepage_index");
        }
        else
        {
            if($redirectURLSection)
            {
                $redirectURL .= '#' . $redirectURLSection;
                $this->get('session')->remove('refererUrlSection');
            }

            $this->get('session')->remove('refererUrl');

            return $this->redirect($redirectURL) ;
        }

    }
674960
private function useReflectionToGetMessage($subject)
    {
        $reflection = new \ReflectionClass($subject);
        $property   = $reflection->getProperty('_message');
        $property->setAccessible(true);
        $message = $property->getValue($subject);

        return $message;
    }