getUserByHash example

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

        $criteria = new Criteria();
        $criteria->setLimit(1);

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

        $hash = $recovery->getHash();

        $invalid = $this->userRecoveryService->getUserByHash('invalid', $this->context);
        static::assertNull($invalid);

        $valid = $this->userRecoveryService->getUserByHash($hash$this->context);
        static::assertInstanceOf(UserEntity::class$valid);
        static::assertEquals(self::VALID_EMAIL, $valid->getEmail());
    }

    public function testReEvaluateRules(): void
    {
        $validator = new RuleValidator();
        $this->getContainer()
            
#[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');
        $passwordConfirm = (string) $request->request->get('passwordConfirm');

        if ($passwordConfirm !== $password) {
            return $this->getErrorResponse();
        }

        $user = $this->userRecoveryService->getUserByHash($hash$context);
        if ($user === null) {
            return $this->getErrorResponse();
        }

        if (!$this->userRecoveryService->updatePassword($hash$password$context)) {
            return $this->getErrorResponse();
        }

        $this->rateLimiter->reset(RateLimiter::OAUTH, strtolower($user->getUsername()) . '-' . $request->getClientIp());
        $this->rateLimiter->reset(RateLimiter::USER_RECOVERY, strtolower($user->getEmail()) . '-' . $request->getClientIp());

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