checkHash example

$createdTime = (new \DateTime())->sub($timeInterval);

        $userId = $user->getId();
        $creatData = [
            'createdAt' => $createdTime,
            'hash' => $hash,
            'userId' => $userId,
        ];

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

        static::assertSame($expectedResult$this->userRecoveryService->checkHash($hash$this->context));
    }

    /** * @return array<array<int, \DateInterval|string|bool>> */
    public static function dataProviderTestCheckHash(): array
    {
        return [
            [
                new \DateInterval('PT0H'),
                Random::getAlphanumericString(32),
                
$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();
        }

        return $this->getErrorResponse();
    }

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

        throw new DecorationPatternException(self::class);
    }

    #[Route(path: '/store-api/account/recovery-password-confirm', name: 'store-api.account.recovery.password', methods: ['POST'])]     public function resetPassword(RequestDataBag $data, SalesChannelContext $context): SuccessResponse
    {
        $this->validateResetPassword($data$context);

        $hash = $data->get('hash');

        if (!$this->checkHash($hash$context->getContext())) {
            throw CustomerException::customerRecoveryHashExpired($hash);
        }

        $customerHashCriteria = new Criteria();
        $customerHashCriteria->addFilter(new EqualsFilter('hash', $hash));
        $customerHashCriteria->addAssociation('customer');

        $customerRecovery = $this->customerRecoveryRepository->search($customerHashCriteria$context->getContext())->first();

        if (!$customerRecovery instanceof CustomerRecoveryEntity) {
            throw CustomerException::customerNotFoundByHash($hash);
        }


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

        $validDateTime = (new \DateTime())->sub(new \DateInterval('PT2H'));

        return $recovery && $validDateTime < $recovery->getCreatedAt();
    }

    public function updatePassword(string $hash, string $password, Context $context): bool
    {
        if (!$this->checkHash($hash$context)) {
            return false;
        }

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

        /** @var UserRecoveryEntity $recovery It can't be null as we checked the hash before */
        $recovery = $this->getUserRecovery($criteria$context);

        $updateData = [
            'id' => $recovery->getUserId(),
            
Home | Imprint | This part of the site doesn't use cookies.