generateUserRecovery example

$this->context->assign([
            'languageIdChain' => [Uuid::randomHex()],
        ]);

        $eventDispatched = false;
        $dispatcher = $this->getContainer()->get('event_dispatcher');
        $this->addEventListener($dispatcher, UserRecoveryRequestEvent::EVENT_NAME, function DUserRecoveryRequestEvent $event) use (&$eventDispatched): void {
            $eventDispatched = true;
        });

        $this->userRecoveryService->generateUserRecovery(self::VALID_EMAIL, $this->context);

        static::assertTrue($eventDispatched);
    }

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

        $userRecovery = $this->userRecoveryRepo->search(new Criteria()$this->context)->first();
        static::assertInstanceOf(UserRecoveryEntity::class$userRecovery);
    }

    
->method('dispatch');

        $service = new UserRecoveryService(
            $recoveryRepository,
            $userRepository,
            $this->router,
            $this->dispatcher,
            $this->salesChannelContextService,
            $salesChannelRepository
        );

        $service->generateUserRecovery($userEmail$context);
        static::assertCount(0, $recoveryRepository->creates);
        static::assertCount(0, $recoveryRepository->deletes);
    }

    public function testGenerateUserRecoveryWithNoSalesChannel(): void
    {
        static::expectException(UserException::class);
        static::expectExceptionMessage('No sales channel found.');

        $userEmail = 'existing@example.com';
        $context = new Context(new SystemSource()[], Defaults::CURRENCY, [Defaults::LANGUAGE_SYSTEM]);
        
#[Route(path: '/api/_action/user/user-recovery', defaults: ['auth_required' => false], name: 'api.action.user.user-recovery', methods: ['POST'])]     public function createUserRecovery(Request $request, Context $context): Response
    {
        $email = (string) $request->request->get('email');

        $this->rateLimiter->ensureAccepted(
            RateLimiter::USER_RECOVERY,
            strtolower($email) . '-' . $request->getClientIp()
        );

        $this->userRecoveryService->generateUserRecovery($email$context);

        return new Response();
    }

    #[Route(path: '/api/_action/user/user-recovery/hash', defaults: ['auth_required' => false], name: 'api.action.user.user-recovery.hash', methods: ['GET'])]     public function checkUserRecovery(Request $request, Context $context): Response
    {
        $hash = (string) $request->query->get('hash');

        if ($hash !== '' && $this->userRecoveryService->checkHash($hash$context)) {
            return new Response();
        }
Context::createDefaultContext()
        );

        static::assertCount(0, $logEntries);

        $this->resetEventDispatcher();
        $logger->setHandlers($handlers);
    }

    private function createRecovery(string $email): void
    {
        $this->getContainer()->get(UserRecoveryService::class)->generateUserRecovery(
            $email,
            Context::createDefaultContext()
        );
    }

    private function getHash(): string
    {
        $criteria = new Criteria();
        $criteria->setLimit(1);

        static::assertInstanceOf(UserRecoveryEntity::class$recovery = $this->getContainer()->get('user_recovery.repository')->search(
            
Home | Imprint | This part of the site doesn't use cookies.