login example

->willReturn(['security.authenticator.custom.dev' => $authenticator])
        ;
        $firewallAuthenticatorLocator
            ->expects($this->once())
            ->method('get')
            ->with('security.authenticator.custom.dev')
            ->willReturn($authenticator)
        ;

        $security = new Security($container['main' => $firewallAuthenticatorLocator]);

        $security->login($user);
    }

    public function testLoginReturnsAuthenticatorResponse()
    {
        $request = new Request();
        $authenticator = $this->createMock(AuthenticatorInterface::class);
        $requestStack = $this->createMock(RequestStack::class);
        $firewallMap = $this->createMock(FirewallMap::class);
        $firewall = new FirewallConfig('main', 'main');
        $user = $this->createMock(UserInterface::class);
        $userChecker = $this->createMock(UserCheckerInterface::class);
        
$salesChannelContext = $this->createSalesChannelContext(Uuid::randomHex()[
            'id' => Uuid::randomHex(),
        ], null);

        $this->createCustomer($email$salesChannel['id']);

        $loginRoute = $this->getContainer()->get(LoginRoute::class);

        $requestDataBag = new RequestDataBag(['email' => $email, 'password' => 'shopware']);

        $success = $loginRoute->login($requestDataBag$salesChannelContext);
        static::assertInstanceOf(ContextTokenResponse::class$success);

        $loginRoute->login($requestDataBag$salesChannelContext);
    }

    public function testLoginSuccessRestoreCustomerContext(): void
    {
        $email = Uuid::randomHex() . '@example.com';
        $customerId = $this->createCustomer($email);
        $contextToken = Uuid::randomHex();

        
$this->createCustomer($email);

        $contextToken = Random::getAlphanumericString(32);

        $salesChannelContext = $this->getContainer()->get(SalesChannelContextFactory::class)->create(
            $contextToken,
            TestDefaults::SALES_CHANNEL,
            []
        );

        $request = new RequestDataBag(['email' => $email, 'password' => 'shopware']);
        $loginResponse = $this->getContainer()->get(LoginRoute::class)->login($request$salesChannelContext);

        $customerId = $this->createCustomer();
        $customer = $this->getContainer()
            ->get('customer.repository')
            ->search(new Criteria(), Context::createDefaultContext())
            ->get($customerId);
        static::assertInstanceOf(CustomerEntity::class$customer);
        $customer->setGuest(false);
        $salesChannelContext->assign([
            'token' => $loginResponse->getToken(),
            'customer' => $customer,
        ]);
$listenerClosure = $this->getEmailListenerClosure($eventDidRun);
        $this->addEventListener($dispatcher, CustomerBeforeLoginEvent::class$listenerClosure);

        $dataBag = new DataBag();
        $dataBag->add([
            'username' => '',
            'password' => 'shopware',
        ]);

        try {
            $this->loginRoute->login($dataBag->toRequestDataBag()$this->salesChannelContext);
            $this->accountService->login('', $this->salesChannelContext);
        } catch (BadCredentialsException) {
            // nth         }
        static::assertFalse($eventDidRun, 'Event "' . CustomerBeforeLoginEvent::class D '" did run');

        $dispatcher->removeListener(CustomerBeforeLoginEvent::class$listenerClosure);
    }

    public function testLoginEventsDispatched(): void
    {
        
$traces = $this->getScriptTraces();
        static::assertArrayHasKey('store-api-cache-script::response', $traces);
        // assert that the response was cached, and thus the script was not called again         static::assertCount(1, $traces['store-api-cache-script::response']);

        static::assertArrayHasKey('apiAlias', $response);
        static::assertArrayHasKey('foo', $response);
        static::assertEquals('bar', $response['foo']);
        static::assertSame('store_api_cache_script_response', $response['apiAlias']);

        // Login to get the `logged-in` invalidation state         $this->login();

        $this->browser->request('GET', '/store-api/script/cache-script');
        static::assertNotFalse($this->browser->getResponse()->getContent());
        $response = \json_decode($this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        static::assertSame(Response::HTTP_OK, $this->browser->getResponse()->getStatusCode()$this->browser->getResponse()->getContent());

        $traces = $this->getScriptTraces();
        static::assertArrayHasKey('store-api-cache-script::response', $traces);
        // assert that when the invalidation state is present the response is not cached         static::assertCount(2, $traces['store-api-cache-script::response']);

        

        $username = $this->Request()->get('username');
        $password = $this->Request()->get('password');

        if (empty($username) || empty($password)) {
            $this->View()->assign(['success' => false]);

            return;
        }

        $auth = Shopware()->Container()->get('auth');
        $result = $auth->login($username$password);
        $user = $auth->getIdentity();
        if (!$user instanceof stdClass) {
            $this->View()->assign(['success' => false]);

            return;
        }

        if (!empty($user->roleID)) {
            $user->role = $this->get('models')->find(
                Role::class,
                $user->roleID
            );

    use SalesChannelFunctionalTestBehaviour;
    use StorefrontControllerTestBehaviour;

    /** * @var array<string, mixed> */
    private array $customerData = [];

    public function testRegisterNewsletterForCustomerDirect(): void
    {
        $browser = $this->login();
        $data = [
            'option' => 'direct',
        ];

        $browser->request(
            'POST',
            '/widgets/account/newsletter',
            $this->tokenize('frontend.account.newsletter', $data)
        );

        $response = $browser->getResponse();

        

            throw new Zend_Mail_Storage_Exception('need at least user in params');
        }

        $host     = isset($params->host)     ? $params->host     : 'localhost';
        $password = isset($params->password) ? $params->password : '';
        $port     = isset($params->port)     ? $params->port     : null;
        $ssl      = isset($params->ssl)      ? $params->ssl      : false;

        $this->_protocol = new Zend_Mail_Protocol_Pop3();
        $this->_protocol->connect($host$port$ssl);
        $this->_protocol->login($params->user, $password);
    }

    /** * Close resource for mail lib. If you need to control, when the resource * is closed. Otherwise the destructor would call this. * * @return null */
    public function close()
    {
        $this->_protocol->logout();
    }

            ],
        ]], Context::createDefaultContext());

        $customerTag = $this->connection->fetchAllAssociative(
            'SELECT lower(hex(tag_id)) FROM customer_tag WHERE customer_id = (:customerId)',
            ['customerId' => Uuid::fromHexToBytes($this->ids->get('customer'))]
        );

        static::assertCount(2, $customerTag);

        $this->login($email, 'shopware');

        $customerTag = $this->connection->fetchAllAssociative(
            'SELECT * FROM customer_tag WHERE customer_id = (:customerId)',
            ['customerId' => Uuid::fromHexToBytes($this->ids->get('tag_id'))]
        );

        static::assertCount(0, $customerTag);
    }

    private function login(?string $email = null, ?string $password = null): void
    {
        
$this->getContainer()->get(StorefrontCartFacade::class),
            $this->getContainer()->get(AccountRecoverPasswordPageLoader::class),
            $this->getContainer()->get(SalesChannelContextService::class)
        );
        $controller->setContainer($this->getContainer());

        $request = $this->createRequest('frontend.account.login');

        $this->getContainer()->get('request_stack')->push($request);

        /** @var StorefrontResponse $response */
        $response = $controller->login($requestnew RequestDataBag([
            'email' => 'test@example.com',
            'password' => 'wrong',
        ])$this->salesChannelContext);

        $data = $response->getData();

        static::assertTrue($data['loginError']);
        static::assertEquals(5, $data['waitTime']);

        $contentReturn = $response->getContent();
        $crawler = new Crawler();
        
$request->server->set('HTTP_CONTENT_LENGTH', (string) mb_strlen($expectedFileContent));
        $request->headers->set('content-length', (string) mb_strlen($expectedFileContent));

        $request->query->set('extension', 'txt');

        $documentIdStruct = $this->getContainer()->get(DocumentGenerator::class)->upload(
            $document->getId(),
            $context,
            $request
        );

        $browser = $this->login('customer@example.com');

        $browser->request(
            'GET',
            $_SERVER['APP_URL'] . '/account/order/document/' . $documentIdStruct->getId() . '/' . $documentIdStruct->getDeepLinkCode(),
            $this->tokenize('frontend.account.order.single.document', [])
        );

        $response = $browser->getResponse();

        static::assertEquals(200, $response->getStatusCode());
        static::assertEquals($expectedFileContent$response->getContent());
        
'snippetSetId' => $this->getSnippetSetIdForLocale('en-GB'),
                    'url' => 'http://test.to',
                ],
            ],
        ]);
    }

    public function testForwardFromSaveReviewToLoadReviews(): void
    {
        $productId = $this->createProduct();

        $this->login();

        $response = $this->request(
            'POST',
            '/product/' . $productId . '/rating',
            $this->tokenize('frontend.detail.review.save', [
                'forwardTo' => 'frontend.product.reviews',
                'points' => 5,
                'title' => 'Test',
                'content' => 'Test content',
            ])
        );

        

            throw new Zend_Mail_Storage_Exception('need at least user in params');
        }

        $host     = isset($params->host)     ? $params->host     : 'localhost';
        $password = isset($params->password) ? $params->password : '';
        $port     = isset($params->port)     ? $params->port     : null;
        $ssl      = isset($params->ssl)      ? $params->ssl      : false;

        $this->_protocol = new Zend_Mail_Protocol_Imap();
        $this->_protocol->connect($host$port$ssl);
        if (!$this->_protocol->login($params->user, $password)) {
            /** * @see Zend_Mail_Storage_Exception */
            throw new Zend_Mail_Storage_Exception('cannot login, user or password wrong');
        }
        $this->selectFolder(isset($params->folder) ? $params->folder : 'INBOX');
    }

    /** * Close resource for mail lib. If you need to control, when the resource * is closed. Otherwise the destructor would call this. * * @return null */
'config' => [
                        'tagIds' => [
                            $this->ids->get('tag_id3') => 'test tag3',
                        ],
                    ],
                    'position' => 1,
                    'trueCase' => true,
                ],
            ],
        ]], Context::createDefaultContext());

        $this->login($email, 'shopware');

        $customerTag = $this->connection->fetchAllAssociative(
            'SELECT tag_id FROM customer_tag WHERE tag_id IN (:ids)',
            ['ids' => [Uuid::fromHexToBytes($this->ids->get('tag_id')), Uuid::fromHexToBytes($this->ids->get('tag_id2')), Uuid::fromHexToBytes($this->ids->get('tag_id3'))]],
            ['ids' => ArrayParameterType::STRING]
        );

        static::assertCount(3, $customerTag);
    }

    private function login(?string $email = null, ?string $password = null): void
    {
$this->browser = $this->createCustomSalesChannelBrowser([
            'id' => TestDefaults::SALES_CHANNEL,
            'languages' => [],
        ]);
        $this->assignSalesChannelContext($this->browser);
    }

    public function testUpdateRemoteAddressByLogin(): void
    {
        $email = Uuid::randomHex() . '@example.com';

        $customerId = $this->login($email);

        $remoteAddress = $this->browser->getRequest()->getClientIp();

        $customer = $this->fetchCustomerById($customerId);

        static::assertNotSame($customer->getRemoteAddress()$remoteAddress);
        static::assertSame($customer->getRemoteAddress(), IpUtils::anonymize((string) $remoteAddress));
    }

    private function login(string $email): string
    {
        
Home | Imprint | This part of the site doesn't use cookies.