67 private $cookieManager;
72 private $cookieMetadataFactory;
96 parent::__construct($context);
97 $this->customerSession = $customerSession;
102 $this->cookieManager = $cookieManager ?:
104 $this->cookieMetadataFactory = $cookieMetadataFactory ?:
117 if (!is_object($this->accountRedirect)) {
132 $this->accountRedirect =
$value;
141 if (!is_object($this->scopeConfig)) {
154 $this->scopeConfig =
$value;
168 $httpBadRequestCode = 400;
171 $resultRaw = $this->resultRawFactory->create();
173 $credentials = $this->helper->jsonDecode($this->
getRequest()->getContent());
174 }
catch (\Exception $e) {
175 return $resultRaw->setHttpResponseCode($httpBadRequestCode);
177 if (!$credentials || $this->
getRequest()->getMethod() !==
'POST' || !$this->
getRequest()->isXmlHttpRequest()) {
178 return $resultRaw->setHttpResponseCode($httpBadRequestCode);
183 'message' =>
__(
'Login successful.')
186 $customer = $this->customerAccountManagement->authenticate(
187 $credentials[
'username'],
188 $credentials[
'password']
190 $this->customerSession->setCustomerDataAsLoggedIn(
$customer);
191 $this->customerSession->regenerateId();
193 if ($this->cookieManager->getCookie(
'mage-cache-sessid')) {
194 $metadata = $this->cookieMetadataFactory->createCookieMetadata();
195 $metadata->setPath(
'/');
196 $this->cookieManager->deleteCookie(
'mage-cache-sessid', $metadata);
198 if (!$this->
getScopeConfig()->getValue(
'customer/startup/redirect_dashboard') && $redirectRoute) {
202 }
catch (EmailNotConfirmedException $e) {
205 'message' => $e->getMessage()
207 }
catch (InvalidEmailOrPasswordException $e) {
210 'message' => $e->getMessage()
212 }
catch (LocalizedException $e) {
215 'message' => $e->getMessage()
217 }
catch (\Exception $e) {
220 'message' =>
__(
'Invalid login or password.')
224 $resultJson = $this->resultJsonFactory->create();
setAccountRedirect($value)
_redirect($path, $arguments=[])
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Json\Helper\Data $helper, AccountManagementInterface $customerAccountManagement, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory, CookieManagerInterface $cookieManager=null, CookieMetadataFactory $cookieMetadataFactory=null)
$customerAccountManagement