예제 #1
0
 /**
  * Login post action
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     if ($this->_getSession()->isLoggedIn() || !$this->_formKeyValidator->validate($this->getRequest())) {
         $this->_redirect('*/*/');
         return;
     }
     if ($this->getRequest()->isPost()) {
         $login = $this->getRequest()->getPost('login');
         if (!empty($login['username']) && !empty($login['password'])) {
             try {
                 $customer = $this->_customerAccountService->authenticate($login['username'], $login['password']);
                 $this->_getSession()->setCustomerDataAsLoggedIn($customer);
                 $this->_getSession()->regenerateId();
             } catch (EmailNotConfirmedException $e) {
                 $value = $this->_customerHelperData->getEmailConfirmationUrl($login['username']);
                 $message = __('This account is not confirmed.' . ' <a href="%1">Click here</a> to resend confirmation email.', $value);
                 $this->messageManager->addError($message);
                 $this->_getSession()->setUsername($login['username']);
             } catch (AuthenticationException $e) {
                 $message = __('Invalid login or password.');
                 $this->messageManager->addError($message);
                 $this->_getSession()->setUsername($login['username']);
             } catch (\Exception $e) {
                 // PA DSS violation: this exception log can disclose customer password
                 // $this->_objectManager->get('Magento\Framework\Logger')->logException($e);
                 $this->messageManager->addError(__('There was an error validating the login and password.'));
             }
         } else {
             $this->messageManager->addError(__('Login and password are required.'));
         }
     }
     $this->_loginPostRedirect();
 }
예제 #2
0
 /**
  * Create customer account action
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     if ($this->_getSession()->isLoggedIn() || !$this->isRegistrationAllowed()) {
         $this->_redirect('*/*/');
         return;
     }
     if (!$this->getRequest()->isPost()) {
         $url = $this->_createUrl()->getUrl('*/*/create', array('_secure' => true));
         $this->getResponse()->setRedirect($this->_redirect->error($url));
         return;
     }
     $this->_session->regenerateId();
     try {
         $customer = $this->customerExtractor->extract('customer_account_create', $this->_request);
         $address = $this->_extractAddress();
         $addresses = is_null($address) ? array() : array($address);
         $password = $this->getRequest()->getParam('password');
         $redirectUrl = $this->_getSession()->getBeforeAuthUrl();
         $customerDetails = $this->_customerDetailsBuilder->setCustomer($customer)->setAddresses($addresses)->create();
         $customer = $this->_customerAccountService->createCustomer($customerDetails, $password, $redirectUrl);
         if ($this->getRequest()->getParam('is_subscribed', false)) {
             $this->_subscriberFactory->create()->subscribeCustomerById($customer->getId());
         }
         $this->_eventManager->dispatch('customer_register_success', array('account_controller' => $this, 'customer' => $customer));
         $confirmationStatus = $this->_customerAccountService->getConfirmationStatus($customer->getId());
         if ($confirmationStatus === CustomerAccountServiceInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
             $email = $this->_customerHelperData->getEmailConfirmationUrl($customer->getEmail());
             // @codingStandardsIgnoreStart
             $this->messageManager->addSuccess(__('Account confirmation is required. Please, check your email for the confirmation link. To resend the confirmation email please <a href="%1">click here</a>.', $email));
             // @codingStandardsIgnoreEnd
             $url = $this->_createUrl()->getUrl('*/*/index', array('_secure' => true));
             $this->getResponse()->setRedirect($this->_redirect->success($url));
         } else {
             $this->_getSession()->setCustomerDataAsLoggedIn($customer);
             $url = $this->_welcomeCustomer($customer);
             $this->getResponse()->setRedirect($this->_redirect->success($url));
         }
         return;
     } catch (StateException $e) {
         $url = $this->_createUrl()->getUrl('customer/account/forgotpassword');
         // @codingStandardsIgnoreStart
         $message = __('There is already an account with this email address. If you are sure that it is your email address, <a href="%1">click here</a> to get your password and access your account.', $url);
         // @codingStandardsIgnoreEnd
         $this->messageManager->addError($message);
     } catch (InputException $e) {
         $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage()));
         foreach ($e->getErrors() as $error) {
             $this->messageManager->addError($this->escaper->escapeHtml($error->getMessage()));
         }
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Cannot save the customer.'));
     }
     $this->_getSession()->setCustomerFormData($this->getRequest()->getPost());
     $defaultUrl = $this->_createUrl()->getUrl('*/*/create', array('_secure' => true));
     $this->getResponse()->setRedirect($this->_redirect->error($defaultUrl));
 }
예제 #3
0
 /**
  * Involve new customer to system
  *
  * @return $this
  */
 protected function _involveNewCustomer()
 {
     $customer = $this->getQuote()->getCustomerData();
     $confirmationStatus = $this->_customerAccountService->getConfirmationStatus($customer->getId());
     if ($confirmationStatus === CustomerAccountServiceInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
         $url = $this->_customerData->getEmailConfirmationUrl($customer->getEmail());
         $this->messageManager->addSuccess(__('Account confirmation is required. Please, check your e-mail for confirmation link. To resend confirmation email please <a href="%1">click here</a>.', $url));
     } else {
         $this->getCustomerSession()->loginById($customer->getId());
     }
     return $this;
 }