updatePassword example

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

        return new Response();
    }

    private function getErrorResponse(): Response
    {
        

        $this->createRecovery(self::VALID_EMAIL);

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

        $hash = $recovery->getHash();

        static::assertInstanceOf(UserEntity::class$user = $this->userRepo->search(new Criteria()$this->context)->first());

        $passwordBefore = $user->getPassword();

        $this->userRecoveryService->updatePassword($hash, 'newPassword', $this->context);

        static::assertInstanceOf(UserEntity::class$userAfter = $this->userRepo->search(new Criteria()$this->context)->first());

        $passwordAfter = $userAfter->getPassword();

        static::assertNotEquals($passwordBefore$passwordAfter);
    }

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

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