61 private $cookieMetadataFactory;
66 private $cookieMetadataManager;
80 CustomerUrl $customerHelperData,
84 $this->session = $customerSession;
86 $this->customerUrl = $customerHelperData;
89 parent::__construct($context);
98 private function getScopeConfig()
101 return \Magento\Framework\App\ObjectManager::getInstance()->get(
102 \
Magento\Framework\
App\Config\ScopeConfigInterface::class
105 return $this->scopeConfig;
115 private function getCookieManager()
117 if (!$this->cookieMetadataManager) {
119 \
Magento\Framework\Stdlib\Cookie\PhpCookieManager::class
122 return $this->cookieMetadataManager;
131 private function getCookieMetadataFactory()
133 if (!$this->cookieMetadataFactory) {
135 \
Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class
138 return $this->cookieMetadataFactory;
146 ): ?InvalidRequestException {
148 $resultRedirect = $this->resultRedirectFactory->create();
149 $resultRedirect->setPath(
'*/*/');
151 return new InvalidRequestException(
153 [
new Phrase(
'Invalid Form Key. Please refresh the page.')]
173 if ($this->session->isLoggedIn() || !$this->formKeyValidator->validate($this->
getRequest())) {
175 $resultRedirect = $this->resultRedirectFactory->create();
176 $resultRedirect->setPath(
'*/*/');
177 return $resultRedirect;
181 $login = $this->
getRequest()->getPost(
'login');
182 if (!empty($login[
'username']) && !empty($login[
'password'])) {
184 $customer = $this->customerAccountManagement->authenticate($login[
'username'], $login[
'password']);
185 $this->session->setCustomerDataAsLoggedIn(
$customer);
186 $this->session->regenerateId();
187 if ($this->getCookieManager()->getCookie(
'mage-cache-sessid')) {
188 $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
189 $metadata->setPath(
'/');
190 $this->getCookieManager()->deleteCookie(
'mage-cache-sessid', $metadata);
192 $redirectUrl = $this->accountRedirect->getRedirectCookie();
193 if (!$this->getScopeConfig()->getValue(
'customer/startup/redirect_dashboard') && $redirectUrl) {
194 $this->accountRedirect->clearRedirectCookie();
195 $resultRedirect = $this->resultRedirectFactory->create();
197 $resultRedirect->setUrl($this->
_redirect->success($redirectUrl));
198 return $resultRedirect;
200 }
catch (EmailNotConfirmedException $e) {
201 $value = $this->customerUrl->getEmailConfirmationUrl($login[
'username']);
203 'This account is not confirmed. <a href="%1">Click here</a> to resend confirmation email.',
206 }
catch (UserLockedException $e) {
208 'The account sign-in was incorrect or your account is disabled temporarily. ' 209 .
'Please wait and try again later.' 211 }
catch (AuthenticationException $e) {
213 'The account sign-in was incorrect or your account is disabled temporarily. ' 214 .
'Please wait and try again later.' 216 }
catch (LocalizedException $e) {
218 }
catch (\Exception $e) {
220 $this->messageManager->addError(
221 __(
'An unspecified error occurred. Please contact us for assistance.')
225 $this->messageManager->addError(
$message);
226 $this->session->setUsername($login[
'username']);
230 $this->messageManager->addError(
__(
'A login and a password are required.'));
234 return $this->accountRedirect->getRedirect();
_redirect($path, $arguments=[])
__construct(Context $context, Session $customerSession, AccountManagementInterface $customerAccountManagement, CustomerUrl $customerHelperData, Validator $formKeyValidator, AccountRedirect $accountRedirect)
validateForCsrf(RequestInterface $request)
createCsrfValidationException(RequestInterface $request)
$customerAccountManagement