getCustomerByEmail example



    #[Route(path: '/store-api/account/recovery-password', name: 'store-api.account.recovery.send.mail', methods: ['POST'])]     public function sendRecoveryMail(RequestDataBag $data, SalesChannelContext $context, bool $validateStorefrontUrl = true): SuccessResponse
    {
        $this->validateRecoverEmail($data$context$validateStorefrontUrl);

        if (($request = $this->requestStack->getMainRequest()) !== null) {
            $this->rateLimiter->ensureAccepted(RateLimiter::RESET_PASSWORD, strtolower($data->get('email') . '-' . $request->getClientIp()));
        }

        $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);
        }

    public function login(string $email, SalesChannelContext $context, bool $includeGuest = false): string
    {
        if (empty($email)) {
            throw CustomerException::badCredentials();
        }

        $event = new CustomerBeforeLoginEvent($context$email);
        $this->eventDispatcher->dispatch($event);

        try {
            $customer = $this->getCustomerByEmail($email$context$includeGuest);
        } catch (CustomerNotFoundException $exception) {
            throw new UnauthorizedHttpException('json', $exception->getMessage());
        }

        return $this->loginByCustomer($customer$context);
    }

    /** * @throws BadCredentialsException * @throws UnauthorizedHttpException */
    
$email = (string) $request->request->get('email');
        $isCustomerBoundSalesChannel = $this->systemConfigService->get('core.systemWideLoginRegistration.isCustomerBoundToSalesChannel');
        $boundSalesChannelId = null;
        if ($isCustomerBoundSalesChannel) {
            $boundSalesChannelId = $request->request->get('boundSalesChannelId');
            if ($boundSalesChannelId !== null && !\is_string($boundSalesChannelId)) {
                throw RoutingException::invalidRequestParameter('boundSalesChannelId');
            }
        }

        $customer = $this->getCustomerByEmail((string) $request->request->get('id')$email$context$boundSalesChannelId);
        if (!$customer) {
            return new JsonResponse(
                ['isValid' => true]
            );
        }

        $message = 'The email address {{ email }} is already in use';
        $params['{{ email }}'] = $email;

        if ($customer->getBoundSalesChannel()) {
            $message .= ' in the Sales Channel {{ salesChannel }}';
            
Home | Imprint | This part of the site doesn't use cookies.