/** * Involve new customer to system * * @return $this */ protected function _involveNewCustomer() { $customer = $this->getQuote()->getCustomer(); $confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === \Magento\Customer\Model\AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) { $url = $this->_customerUrl->getEmailConfirmationUrl($customer->getEmail()); $this->messageManager->addSuccess(__('You must confirm your account. Please check your email for the confirmation link or <a href="%1">click here</a> for a new link.', $url)); } else { $this->getCustomerSession()->loginById($customer->getId()); } return $this; }
/** * Create customer account action * * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); if ($this->session->isLoggedIn() || !$this->registration->isAllowed()) { $resultRedirect->setPath('*/*/'); return $resultRedirect; } if (!$this->getRequest()->isPost()) { $url = $this->urlModel->getUrl('*/*/create', ['_secure' => true]); $resultRedirect->setUrl($this->_redirect->error($url)); return $resultRedirect; } $this->session->regenerateId(); try { $address = $this->extractAddress(); $addresses = $address === null ? [] : [$address]; $customer = $this->customerExtractor->extract('customer_account_create', $this->_request); $customer->setAddresses($addresses); $password = $this->getRequest()->getParam('password'); $confirmation = $this->getRequest()->getParam('password_confirmation'); $redirectUrl = $this->session->getBeforeAuthUrl(); $this->checkPasswordConfirmation($password, $confirmation); $customer = $this->accountManagement->createAccount($customer, $password, $redirectUrl); if ($this->getRequest()->getParam('is_subscribed', false)) { $this->subscriberFactory->create()->subscribeCustomerById($customer->getId()); } $this->_eventManager->dispatch('customer_register_success', ['account_controller' => $this, 'customer' => $customer]); $confirmationStatus = $this->accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) { $email = $this->customerUrl->getEmailConfirmationUrl($customer->getEmail()); // @codingStandardsIgnoreStart $this->messageManager->addSuccess(__('You must confirm your account. Please check your email for the confirmation link or <a href="%1">click here</a> for a new link.', $email)); // @codingStandardsIgnoreEnd $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]); $resultRedirect->setUrl($this->_redirect->success($url)); } else { $this->session->setCustomerDataAsLoggedIn($customer); $this->messageManager->addSuccess($this->getSuccessMessage()); $resultRedirect = $this->accountRedirect->getRedirect(); } return $resultRedirect; } catch (StateException $e) { $url = $this->urlModel->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, __('We can\'t save the customer.')); } $this->session->setCustomerFormData($this->getRequest()->getPostValue()); $defaultUrl = $this->urlModel->getUrl('*/*/create', ['_secure' => true]); $resultRedirect->setUrl($this->_redirect->error($defaultUrl)); return $resultRedirect; }
/** * Involve new customer to system * * @return $this */ protected function _involveNewCustomer() { $customer = $this->_quote->getCustomer(); $confirmationStatus = $this->_accountManagement->getConfirmationStatus($customer->getId()); if ($confirmationStatus === AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED) { $url = $this->_customerUrl->getEmailConfirmationUrl($customer->getEmail()); $this->_messageManager->addSuccess(__('Account confirmation is required. Please check your email for confirmation link. To resend confirmation email please <a href="%1">click here</a>.', $url)); } else { $this->getCustomerSession()->regenerateId(); $this->getCustomerSession()->loginById($customer->getId()); } return $this; }