Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Logout.php
Go to the documentation of this file.
1 <?php
9 
17 {
21  protected $session;
22 
26  protected $resultJsonFactory;
27 
35  public function __construct(
36  \Magento\Framework\App\Action\Context $context,
37  \Magento\Customer\Model\Session $customerSession,
38  \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
39  ) {
40  parent::__construct($context);
41  $this->customerSession = $customerSession;
42  $this->resultJsonFactory = $resultJsonFactory;
43  }
44 
50  public function execute()
51  {
52  $lastCustomerId = $this->customerSession->getId();
53  $this->customerSession->logout()
54  ->setBeforeAuthUrl($this->_redirect->getRefererUrl())
55  ->setLastCustomerId($lastCustomerId);
56 
58  $resultJson = $this->resultJsonFactory->create();
59  return $resultJson->setData(['message' => 'Logout Successful']);
60  }
61 }
_redirect($path, $arguments=[])
Definition: Action.php:167
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory)
Definition: Logout.php:35