deleteRecoveryForCustomer example

$customer = $this->getCustomerByEmail($data->get('email')$context);
        $customerId = $customer->getId();

        $customerIdCriteria = new Criteria();
        $customerIdCriteria->addFilter(new EqualsFilter('customerId', $customerId));
        $customerIdCriteria->addAssociation('customer.salutation');

        $repoContext = $context->getContext();

        $existingRecovery = $this->customerRecoveryRepository->search($customerIdCriteria$repoContext)->first();
        if ($existingRecovery instanceof CustomerRecoveryEntity) {
            $this->deleteRecoveryForCustomer($existingRecovery$repoContext);
        }

        $recoveryData = [
            'customerId' => $customerId,
            'hash' => Random::getAlphanumericString(32),
        ];

        $this->customerRecoveryRepository->create([$recoveryData]$repoContext);

        $customerRecovery = $this->customerRecoveryRepository->search($customerIdCriteria$repoContext)->first();
        \assert($customerRecovery instanceof CustomerRecoveryEntity);

        
$this->rateLimiter->reset(RateLimiter::RESET_PASSWORD, $cacheKey);
        }

        $customerData = [
            'id' => $customer->getId(),
            'password' => $data->get('newPassword'),
            'legacyPassword' => null,
            'legacyEncoder' => null,
        ];

        $this->customerRepository->update([$customerData]$context->getContext());
        $this->deleteRecoveryForCustomer($customerRecovery$context->getContext());

        return new SuccessResponse();
    }

    /** * @throws ConstraintViolationException */
    private function validateResetPassword(DataBag $data, SalesChannelContext $context): void
    {
        $definition = new DataValidationDefinition('customer.password.update');

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