getHash example

/** @var CustomerEntity $customer */
        $customer = $this->customerRepository->search($criteria, Context::createDefaultContext())->first();

        $this->browser
            ->request(
                'POST',
                '/store-api/account/register-confirm',
                [],
                [],
                ['CONTENT_TYPE' => 'application/json'],
                json_encode([
                    'hash' => $customer->getHash(),
                    'em' => sha1('teg-reg@example.com'),
                ], \JSON_THROW_ON_ERROR)
            );

        static::assertSame(200, $this->browser->getResponse()->getStatusCode());

        $this->browser
            ->request(
                'POST',
                '/store-api/account/login',
                [],
                [],
'foo' => 'baz',
    ]);
    $this->assertSame(['foo' => 'baz']$state->getOpenerParameters());
  }

  /** * Tests that hash is unaffected by allowed media type order. */
  public function testHashUnaffectedByMediaTypeOrder() {
    $state1 = MediaLibraryState::create('test', ['file', 'image'], 'image', 2);
    $state2 = MediaLibraryState::create('test', ['image', 'file'], 'image', 2);
    $this->assertSame($state1->getHash()$state2->getHash());
  }

  /** * Tests that hash is unaffected by opener parameter order. */
  public function testHashUnaffectedByOpenerParamOrder() {
    $state1 = MediaLibraryState::create('test', ['file'], 'file', -1, [
      'foo' => 'baz',
      'baz' => 'foo',
    ]);
    $state2 = MediaLibraryState::create('test', ['file'], 'file', -1, [
      
return $mail;
    }

    protected function assignOrderDocuments(Log $logEntry, Enlight_Components_Mail $mail): void
    {
        if ($logEntry->getDocuments()->isEmpty()) {
            return;
        }

        foreach ($logEntry->getDocuments() as $document) {
            $filePath = sprintf('documents/%s.pdf', $document->getHash());
            $fileName = sprintf('%s.pdf', $document->getType()->getName());

            if (!$this->filesystem->has($filePath)) {
                continue;
            }

            $fileAttachment = $mail->createAttachment(
                $this->filesystem->read($filePath)
            );
            $fileAttachment->filename = $fileName;
        }
    }
$request = $this->createRequest();

        /** @var CustomerDoubleOptInRegistrationEvent $event */
        $event = null;
        $this->catchEvent(CustomerDoubleOptInRegistrationEvent::class$event);

        $registerController->register($request$data$this->salesChannelContext);

        $customer = $customerRepository->search(new Criteria([$event->getCustomer()->getId()])$this->salesChannelContext->getContext());
        $queryData = new QueryDataBag();
        $queryData->set('redirectTo', 'frontend.checkout.confirm.page');
        $queryData->set('hash', $customer->first()->getHash());
        $queryData->set('em', hash('sha1', (string) $event->getCustomer()->getEmail()));

        /** @var RedirectResponse $response */
        $response = $registerController->confirmRegistration($this->salesChannelContext, $queryData);

        static::assertEquals(302, $response->getStatusCode());
        static::assertInstanceOf(RedirectResponse::class$response);
        static::assertEquals('/checkout/confirm', $response->getTargetUrl());
    }

    public function testAccountRegisterPageLoadedHookScriptsAreExecuted(): void
    {
 elseif (!is_writable($cacheDir)) {
            throw new \RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", 'Productexport', $cacheDir));
        }

        $export = Shopware()->Modules()->Export();
        $export->sSYSTEM = Shopware()->System();
        $sSmarty = Shopware()->Template();

        $productFeedRepository = Shopware()->Models()->getRepository(ProductFeed::class);
        $activeFeeds = $productFeedRepository->getActiveListQuery()->getResult();
        foreach ($activeFeeds as $feedModel) {
            $fileName = $feedModel->getHash() . '_' . $feedModel->getFileName();
            $filePath = $cacheDir . $fileName;

            if ($feedModel->getInterval() === 0) {
                continue;
            } elseif ($feedModel->getInterval() > 0) {
                $diffInterval = time();
                if ($feedModel->getCacheRefreshed()) {
                    $diffInterval -= $feedModel->getCacheRefreshed()->getTimestamp();
                }

                if ($diffInterval < $feedModel->getInterval() && file_exists($filePath)) {
                    
/** @var CustomerRecoveryEntity $recovery */
        $recovery = $repo->search($criteria, Context::createDefaultContext())->first();

        static::assertInstanceOf(CustomerRecoveryEntity::class$recovery);

        $this->browser
            ->request(
                'POST',
                '/store-api/account/recovery-password-confirm',
                [
                    'hash' => $recovery->getHash(),
                    'newPassword' => 'password123456',
                    'newPasswordConfirm' => 'password123456',
                ]
            );

        static::assertSame(200, $this->browser->getResponse()->getStatusCode()(string) $this->browser->getResponse()->getContent());

        $this->browser
            ->request(
                'POST',
                '/store-api/account/login',
                [
private const VALID_EMAIL = 'info@shopware.com';

    public function testUpdateUserPassword(): void
    {
        $this->createRecovery(self::VALID_EMAIL);

        $this->getBrowser()->request(
            'PATCH',
            '/api/_action/user/user-recovery/password',
            [
                'hash' => $this->getHash(),
                'password' => 'NewPassword!',
                'passwordConfirm' => 'NewPassword!',
            ]
        );

        static::assertEquals(200, $this->getBrowser()->getResponse()->getStatusCode());
    }

    public function testUpdateUserPasswordWithInvalidHash(): void
    {
        $this->createRecovery(self::VALID_EMAIL);

        
throw new RuntimeException('Parameter shopware.product_export.cache_dir has to be an string');
        }

        if (!is_dir($cacheDir)) {
            if (@mkdir($cacheDir, 0777, true) === false) {
                throw new RuntimeException(sprintf("Unable to create the %s directory (%s)\n", 'Productexport', $cacheDir));
            }
        } elseif (!is_writable($cacheDir)) {
            throw new RuntimeException(sprintf("Unable to write in the %s directory (%s)\n", 'Productexport', $cacheDir));
        }

        $fileName = $productFeed->getHash() . '_' . $productFeed->getFileName();
        $filePath = $cacheDir . $fileName;
        if (file_exists($filePath)) {
            unlink($filePath);
        }
        $productFeed->setCacheRefreshed('2000-01-01');

        try {
            $this->get('models')->persist($productFeed);
            $this->get('models')->flush();

            $data = $this->getFeed($productFeed->getId());
            
throw new DecorationPatternException(self::class);
    }

    public function generate(Request $request): string
    {
        $uri = $this->getRequestUri($request) . $this->cacheHash;

        $event = new HttpCacheGenerateKeyEvent($request, 'md' . hash('sha256', $uri));

        $this->eventDispatcher->dispatch($event);

        $hash = $event->getHash();

        if ($request->cookies->has(CacheResponseSubscriber::CONTEXT_CACHE_COOKIE)) {
            return 'http-cache-' . hash('sha256', $hash . '-' . $request->cookies->get(CacheResponseSubscriber::CONTEXT_CACHE_COOKIE));
        }

        if ($request->cookies->has(CacheResponseSubscriber::CURRENCY_COOKIE)) {
            return 'http-cache-' . hash('sha256', $hash . '-' . $request->cookies->get(CacheResponseSubscriber::CURRENCY_COOKIE));
        }

        if ($request->attributes->has(SalesChannelRequest::ATTRIBUTE_DOMAIN_CURRENCY_ID)) {
            return 'http-cache-' . hash('sha256', $hash . '-' . $request->attributes->get(SalesChannelRequest::ATTRIBUTE_DOMAIN_CURRENCY_ID));
        }
static::assertSame(200, $response->getStatusCode());

        $repo = $this->getContainer()->get('newsletter_recipient.repository');

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('email', 'nltest@example.com'));
        /** @var NewsletterRecipientEntity $recipientEntry */
        $recipientEntry = $repo->search($criteria, Context::createDefaultContext())->first();

        $browser->request(
            'GET',
            '/newsletter-subscribe?em=' . hash('sha1', 'nltest@example.com') . '&hash=' . $recipientEntry->getHash()
        );

        $response = $browser->getResponse();

        static::assertSame(Response::HTTP_OK, $response->getStatusCode()(string) $response->getContent());

        static::assertInstanceOf(StorefrontResponse::class$response);
        static::assertSame(200, $response->getStatusCode());

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('email', 'nltest@example.com'));
        

    public function __construct(private readonly iterable $metadataLoader)
    {
    }

    public function loadFromFile(MediaFile $mediaFile, MediaType $mediaType): ?array
    {
        foreach ($this->metadataLoader as $loader) {
            if ($loader->supports($mediaType)) {
                $metaData = $loader->extractMetadata($mediaFile->getFileName());

                if ($mediaFile->getHash()) {
                    $metaData['hash'] = $mediaFile->getHash();
                }

                return $metaData;
            }
        }

        return null;
    }
}


    /** * Returns the CSRF Token. * * @deprecated Use `CodeIgniter\Security\Security::getHash()` instead of using this method. * * @codeCoverageIgnore */
    public function getCSRFHash(): ?string
    {
        return $this->getHash();
    }

    /** * Returns the CSRF Token Name. * * @deprecated Use `CodeIgniter\Security\Security::getTokenName()` instead of using this method. * * @codeCoverageIgnore */
    public function getCSRFTokenName(): string
    {
        
'hash' => Random::getAlphanumericString(32),
        ];

        $this->userRecoveryRepo->create([$recoveryData]$context);

        $recovery = $this->getUserRecovery($userIdCriteria$context);

        if (!$recovery) {
            return;
        }

        $hash = $recovery->getHash();

        try {
            $url = $this->router->generate('administration.index', [], UrlGeneratorInterface::ABSOLUTE_URL);
        } catch (RouteNotFoundException) {
            // fallback if admin bundle is not installed, the url should work once the bundle is installed             $url = EnvironmentHelper::getVariable('APP_URL') . '/admin';
        }

        $recoveryUrl = $url . '#/login/user-recovery/' . $hash;

        $salesChannel = $this->getSalesChannel($context);

        
return 0;
    }

    /** * @param sExport $export */
    private function generateFeed($export, ProductFeed $feedModel)
    {
        $this->output->writeln(sprintf('Refreshing cache for ' . $feedModel->getName()));

        $export->sFeedID = $feedModel->getId();
        $export->sHash = $feedModel->getHash();
        $export->sInitSettings();
        $export->sSmarty = clone $this->sSmarty;
        $export->sInitSmarty();

        $fileName = $feedModel->getHash() . '_' . $feedModel->getFileName();

        $feedCachePath = $this->cacheDir . '/' . $fileName;
        $handleResource = fopen($feedCachePath, 'w');

        if (!\is_resource($handleResource)) {
            throw new RuntimeException(sprintf('Feed cache path %s can not be opened', $feedCachePath));
        }


  /** * Tests that resources can be used in media_oembed_iframe preprocess. * * @see media_test_oembed_preprocess_media_oembed_iframe() * * @covers ::render */
  public function testResourcePassedToPreprocess() {
    $hash = $this->container->get('media.oembed.iframe_url_helper')
      ->getHash('', 0, 0);

    $url_resolver = $this->prophesize('\Drupal\media\OEmbed\UrlResolverInterface');
    $resource_fetcher = $this->prophesize('\Drupal\media\OEmbed\ResourceFetcherInterface');

    $provider = new Provider('YouTube', 'https://youtube.com', [
      [
        'url' => 'https://youtube.com/foo',
      ],
    ]);
    $resource = Resource::rich('<iframe src="https://youtube.com/watch?feature=oembed"></iframe>', 320, 240, $provider);

    
Home | Imprint | This part of the site doesn't use cookies.