当前位置: 首页>>代码示例>>PHP>>正文


PHP Session::logout方法代码示例

本文整理汇总了PHP中Magento\Customer\Model\Session::logout方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::logout方法的具体用法?PHP Session::logout怎么用?PHP Session::logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Model\Session的用法示例。


在下文中一共展示了Session::logout方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testEmulateWelcomeBlock

 /**
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_default 1
  * @magentoAppArea frontend
  * @magentoAppIsolation enabled
  */
 public function testEmulateWelcomeBlock()
 {
     $this->_customerSession->loginById(1);
     $httpContext = new \Magento\Framework\App\Http\Context();
     $httpContext->setValue(Context::CONTEXT_AUTH, 1, 1);
     $block = $this->_objectManager->create('Magento\\Sales\\Block\\Reorder\\Sidebar', ['httpContext' => $httpContext]);
     $this->_observer->emulateWelcomeBlock($block);
     $customerName = $this->_escaper->escapeHtml($this->_customerViewHelper->getCustomerName($this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId())));
     $translation = __('Welcome, %1!', $customerName);
     $this->assertStringMatchesFormat('%A' . $translation . '%A', $block->getWelcome());
     $this->_customerSession->logout();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:ObserverTest.php

示例2: testToHtml

 /**
  * @magentoConfigFixture current_store persistent/options/customer 1
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_default 1
  * @magentoAppArea frontend
  * @magentoAppIsolation enabled
  */
 public function testToHtml()
 {
     $this->_customerSession->loginById(1);
     $translation = __('Not you?');
     $this->assertStringMatchesFormat('%A<span>%A<a%Ahref="' . $this->_block->getHref() . '"%A>' . $translation . '</a>%A</span>%A', $this->_block->toHtml());
     $this->_customerSession->logout();
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:15,代码来源:AdditionalTest.php

示例3: tearDown

 /**
  * Clear wishlist helper property
  */
 protected function tearDown()
 {
     $this->_wishlistHelper = null;
     if ($this->_customerSession->isLoggedIn()) {
         $this->_customerSession->logout();
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:10,代码来源:DataTest.php

示例4: execute

 /**
  * Customer logout action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     $lastCustomerId = $this->session->getId();
     $this->session->logout()->setBeforeAuthUrl($this->_redirect->getRefererUrl())->setLastCustomerId($lastCustomerId);
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath('*/*/logoutSuccess');
     return $resultRedirect;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:14,代码来源:Logout.php

示例5: testEmulateCustomer

 /**
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  * @magentoConfigFixture current_store persistent/options/enabled 1
  */
 public function testEmulateCustomer()
 {
     $observer = new \Magento\Framework\Event\Observer();
     $this->_customerSession->loginById(1);
     $this->_customerSession->logout();
     $this->assertNull($this->_customerSession->getCustomerId());
     $this->assertEquals(\Magento\Customer\Service\V1\CustomerGroupServiceInterface::NOT_LOGGED_IN_ID, $this->_customerSession->getCustomerGroupId());
     $this->_observer->execute($observer);
     $customer = $this->_customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->assertEquals($customer->getId(), $this->_customerSession->getCustomerId());
     $this->assertEquals($customer->getGroupId(), $this->_customerSession->getCustomerGroupId());
 }
开发者ID:zhangjiachao,项目名称:magento2,代码行数:18,代码来源:EmulateCustomerTest.php

示例6: testEmulateCustomer

 /**
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  * @magentoConfigFixture current_store persistent/options/enabled 1
  */
 public function testEmulateCustomer()
 {
     $observer = new \Magento\Framework\Event\Observer();
     $this->_customerSession->loginById(1);
     $this->_customerSession->logout();
     $this->assertNull($this->_customerSession->getCustomerId());
     $this->assertEquals(\Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID, $this->_customerSession->getCustomerGroupId());
     $this->_observer->execute($observer);
     $customer = $this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->assertEquals($customer->getId(), $this->_customerSession->getCustomerId());
     $this->assertEquals($customer->getGroupId(), $this->_customerSession->getCustomerGroupId());
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:18,代码来源:EmulateCustomerTest.php

示例7: testEmulateQuote

 /**
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_default 1
  * @magentoAppArea frontend
  * @magentoConfigFixture current_store persistent/options/shopping_cart 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 0
  */
 public function testEmulateQuote()
 {
     $requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->setMethods([])->getMock();
     $requestMock->expects($this->once())->method('getFullActionName')->will($this->returnValue('valid_action'));
     $event = new \Magento\Framework\Event(['request' => $requestMock]);
     $observer = new \Magento\Framework\Event\Observer();
     $observer->setEvent($event);
     $this->_customerSession->loginById(1);
     $customer = $this->customerRepository->getById($this->_persistentSessionHelper->getSession()->getCustomerId());
     $this->_checkoutSession->expects($this->once())->method('setCustomerData')->with($customer);
     $this->_customerSession->logout();
     $this->_observer->execute($observer);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:21,代码来源:EmulateQuoteTest.php

示例8: testToHtml

 /**
  * @magentoConfigFixture current_store persistent/options/customer 1
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_enabled 1
  * @magentoConfigFixture current_store persistent/options/remember_default 1
  * @magentoAppArea frontend
  * @magentoAppIsolation enabled
  */
 public function testToHtml()
 {
     $this->_customerSession->loginById(1);
     /** @var \Magento\Customer\Helper\View $customerViewHelper */
     $customerViewHelper = $this->_objectManager->create('Magento\\Customer\\Helper\\View');
     $customerAccountService = $this->_objectManager->create('Magento\\Customer\\Service\\V1\\CustomerAccountServiceInterface');
     /** @var \Magento\Framework\Escaper $escaper */
     $escaper = $this->_objectManager->create('Magento\\Framework\\Escaper');
     $persistentName = $escaper->escapeHtml($customerViewHelper->getCustomerName($customerAccountService->getCustomer($this->_persistentSessionHelper->getSession()->getCustomerId())));
     $translation = __('(Not %1?)', $persistentName);
     $this->assertStringMatchesFormat('%A<span>%A<a%Ahref="' . $this->_block->getHref() . '"%A>' . $translation . '</a>%A</span>%A', $this->_block->toHtml());
     $this->_customerSession->logout();
 }
开发者ID:aiesh,项目名称:magento2,代码行数:21,代码来源:AdditionalTest.php

示例9: execute

 /**
  * Customer logout action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     $lastCustomerId = $this->session->getId();
     $this->session->logout()->setBeforeAuthUrl($this->_redirect->getRefererUrl())->setLastCustomerId($lastCustomerId);
     if ($this->getCookieManager()->getCookie('mage-cache-sessid')) {
         $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
         $metadata->setPath('/');
         $this->getCookieManager()->deleteCookie('mage-cache-sessid', $metadata);
     }
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     $resultRedirect->setPath('*/*/logoutSuccess');
     return $resultRedirect;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:19,代码来源:Logout.php

示例10: testSynchronizePersistentOnLogout

 /**
  * @magentoConfigFixture current_store persistent/options/enabled 1
  * @magentoConfigFixture current_store persistent/options/logout_clear 1
  * @magentoAppArea frontend
  * @magentoAppIsolation enabled
  */
 public function testSynchronizePersistentOnLogout()
 {
     $this->_customerSession->loginById(1);
     // check that persistent session has been stored for Customer
     /** @var \Magento\Persistent\Model\Session $sessionModel */
     $sessionModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Persistent\\Model\\Session');
     $sessionModel->loadByCookieKey();
     $this->assertEquals(1, $sessionModel->getCustomerId());
     $this->_customerSession->logout();
     /** @var \Magento\Persistent\Model\Session $sessionModel */
     $sessionModel = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Persistent\\Model\\Session');
     $sessionModel->loadByCookieKey();
     $this->assertNull($sessionModel->getCustomerId());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:20,代码来源:SynchronizePersistentOnLogoutObserverTest.php

示例11: execute

 /**
  * Check Captcha On Forgot Password Page
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $captchaModel = $this->helper->getCaptcha(self::FORM_ID);
     if ($captchaModel->isRequired()) {
         /** @var \Magento\Framework\App\Action\Action $controller */
         $controller = $observer->getControllerAction();
         if (!$captchaModel->isCorrect($this->captchaStringResolver->resolve($controller->getRequest(), self::FORM_ID))) {
             $customerId = $this->customerSession->getCustomerId();
             $this->authentication->processAuthenticationFailure($customerId);
             if ($this->authentication->isLocked($customerId)) {
                 $this->customerSession->logout();
                 $this->customerSession->start();
                 $message = __('The account is locked. Please wait and try again or contact %1.', $this->scopeConfig->getValue('contact/email/recipient_email'));
                 $this->messageManager->addError($message);
             }
             $this->messageManager->addError(__('Incorrect CAPTCHA'));
             $this->actionFlag->set('', \Magento\Framework\App\Action\Action::FLAG_NO_DISPATCH, true);
             $this->redirect->redirect($controller->getResponse(), '*/*/edit');
         }
     }
     $customer = $this->customerSession->getCustomer();
     $login = $customer->getEmail();
     $captchaModel->logAttempt($login);
     return $this;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:31,代码来源:CheckUserEditObserver.php

示例12: execute

 /**
  * Change customer email or password action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if (!$this->formKeyValidator->validate($this->getRequest())) {
         return $resultRedirect->setPath('*/*/edit');
     }
     if ($this->getRequest()->isPost()) {
         $currentCustomerDataObject = $this->getCurrentCustomerDataObject();
         $customerCandidateDataObject = $this->populateNewCustomerDataObject($this->_request, $currentCustomerDataObject);
         try {
             // whether a customer enabled change email option
             $this->changeEmail($currentCustomerDataObject);
             // whether a customer enabled change password option
             $isPasswordChanged = $this->changePassword($currentCustomerDataObject);
             $this->customerRepository->save($customerCandidateDataObject);
             $this->getEmailNotification()->sendNotificationEmailsIfRequired($currentCustomerDataObject, $customerCandidateDataObject, $isPasswordChanged);
             $this->dispatchSuccessEvent($customerCandidateDataObject);
             $this->messageManager->addSuccess(__('You saved the account information.'));
             return $resultRedirect->setPath('customer/account');
         } catch (InvalidEmailOrPasswordException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (UserLockedException $e) {
             $this->session->logout();
             $this->session->start();
             $this->messageManager->addError($e->getMessage());
             return $resultRedirect->setPath('customer/account/login');
         } catch (InputException $e) {
             $this->messageManager->addError($e->getMessage());
             foreach ($e->getErrors() as $error) {
                 $this->messageManager->addError($error->getMessage());
             }
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('We can\'t save the customer.'));
         }
         $this->session->setCustomerFormData($this->getRequest()->getPostValue());
         return $resultRedirect->setPath('*/*/edit');
     }
     return $resultRedirect->setPath('*/*/edit');
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:47,代码来源:EditPost.php

示例13: tearDown

 protected function tearDown()
 {
     $this->_customerSession->logout();
     $this->_customerSession = null;
     parent::tearDown();
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:6,代码来源:IndexTest.php


注:本文中的Magento\Customer\Model\Session::logout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。