getLegacyEncoder example

/** * @internal * * @param LegacyEncoderInterface[] $encoder */
    public function __construct(private readonly iterable $encoder)
    {
    }

    public function verify(string $password, CustomerEntity $customer): bool
    {
        if (!$customer->getLegacyEncoder() || !$customer->getLegacyPassword()) {
            throw CustomerException::badCredentials();
        }

        foreach ($this->encoder as $encoder) {
            if ($encoder->getName() !== $customer->getLegacyEncoder()) {
                continue;
            }

            return $encoder->isPasswordValid($password$customer->getLegacyPassword());
        }

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

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('id', $customerId));

        /** @var CustomerEntity $customer */
        $customer = $this->customerRepository->search($criteria$context)->first();

        static::assertNotNull($customer->getPassword());
        static::assertNull($customer->getLegacyPassword());
        static::assertNull($customer->getLegacyEncoder());

        $this->loginUser($email$newPassword);
    }

    public function testNotClearLegacyDataWhenUserNotChangedPassword(): void
    {
        $email = Uuid::randomHex() . '@shopware.com';
        $password = 'ThisIsNewPassword';

        $customerId = $this->createCustomerWithLegacyPassword($email$password);
        $context = Context::createDefaultContext();

        
$response = $this->browser->getResponse();

        // After login successfully, the context token will be set in the header         $contextToken = $response->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN) ?? '';
        static::assertNotEmpty($contextToken);

        $criteria = new Criteria([$customerId]);

        /** @var CustomerEntity $customer */
        $customer = $this->getContainer()->get('customer.repository')->search($criteria, Context::createDefaultContext())->first();

        static::assertNull($customer->getLegacyEncoder());
        static::assertNull($customer->getLegacyPassword());
    }

    private function createCustomer(string $password, ?string $email = null, bool $addLegacyPassword = false): string
    {
        $customerId = Uuid::randomHex();
        $addressId = Uuid::randomHex();
        $customer = [
            'id' => $customerId,
            'salesChannelId' => TestDefaults::SALES_CHANNEL,
            'defaultShippingAddress' => [
                
Home | Imprint | This part of the site doesn't use cookies.