/** * {@inheritdoc} */ protected function _toHtml() { if (!$this->_registration->isAllowed() || $this->httpContext->getValue(Context::CONTEXT_AUTH)) { return ''; } return parent::_toHtml(); }
/** * {@inheritdoc} */ public function toHtml() { if ($this->customerSession->isLoggedIn() || !$this->registration->isAllowed() || !$this->accountManagement->isEmailAvailable($this->getEmailAddress()) || !$this->validateAddresses()) { return ''; } return parent::toHtml(); }
/** * Customer register form page * * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page */ public function executeInternal() { if ($this->session->isLoggedIn() || !$this->registration->isAllowed()) { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('*/*'); return $resultRedirect; } /** @var \Magento\Framework\View\Result\Page $resultPage */ $resultPage = $this->resultPageFactory->create(); return $resultPage; }
public function execute() { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); // redirect logged in user to the dashboard if ($this->getSession()->isLoggedIn() || !$this->registration->isAllowed()) { /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */ $resultRedirect = $this->resultRedirectFactory->create(); $resultRedirect->setPath('customer/account/index'); return $resultRedirect; } try { /* @var $requestData \BelVG\FacebookFree\Model\Request */ $requestData = $this->_objectManager->create('BelVG\\FacebookFree\\Model\\Request'); $fbData = $requestData->load(); $fbData['store_id'] = $this->storeManager->getStore()->getId(); $fbData['website_id'] = $this->storeManager->getStore()->getWebsiteId(); /* @var $customer \BelVG\FacebookFree\Model\Customer */ $customer = $this->_objectManager->create('BelVG\\FacebookFree\\Model\\Customer')->setFbData($fbData); /* @var $facebook \BelVG\FacebookFree\Model\FacebookFree */ $facebook = $this->_objectManager->create('BelVG\\FacebookFree\\Model\\FacebookFree'); if (!($customerId = $facebook->checkFbCustomer($customer->getFbData()))) { if (!($customerId = $customer->checkCustomer())) { // create customer $customerModel = $this->createCustomer($customer); $customerId = $customerModel->getId(); $this->messageManager->addSuccess($this->getSuccessMessage()); } if (!isset($customerModel)) { $customerModel = $customer->load($customerId); } $fbData['customer_id'] = $customerId; // create record about FB user $facebook->prepareData($fbData)->save(); $this->getSession()->setCustomerDataAsLoggedIn($customerModel); } else { $customerModel = $customer->load($customerId); $this->getSession()->setCustomerAsLoggedIn($customerModel); } $resultRedirect = $this->accountRedirect->getRedirect(); } catch (\Exception $e) { $this->logger->error($e->getMessage()); $this->messageManager->addError($e->getMessage()); $url = $this->urlModel->getUrl('customer/account/login', ['_secure' => true]); $resultRedirect->setUrl($url); return $resultRedirect; } return $resultRedirect; }
/** * @param $customerId * @param $password * @param $confirmationStatus * @param $successUrl * @param $isSetFlag * @param $successMessage * * @dataProvider getSuccessRedirectDataProvider */ public function testSuccessRedirect($customerId, $password, $confirmationStatus, $successUrl, $isSetFlag, $successMessage) { $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->will($this->returnValue(false)); $this->registration->expects($this->once())->method('isAllowed')->will($this->returnValue(true)); $this->customerSessionMock->expects($this->once())->method('regenerateId'); $this->customerMock->expects($this->any())->method('getId')->will($this->returnValue($customerId)); $this->customerExtractorMock->expects($this->any())->method('extract')->with($this->equalTo('customer_account_create'), $this->equalTo($this->requestMock))->will($this->returnValue($this->customerMock)); $this->requestMock->expects($this->once())->method('isPost')->will($this->returnValue(true)); $this->requestMock->expects($this->any())->method('getPost')->will($this->returnValue(false)); $this->requestMock->expects($this->any())->method('getParam')->willReturnMap([['password', null, $password], ['password_confirmation', null, $password], ['is_subscribed', false, true]]); $this->customerMock->expects($this->once())->method('setAddresses')->with($this->equalTo([]))->will($this->returnSelf()); $this->accountManagement->expects($this->once())->method('createAccount')->with($this->equalTo($this->customerDetailsMock), $this->equalTo($password), '')->will($this->returnValue($this->customerMock)); $this->accountManagement->expects($this->once())->method('getConfirmationStatus')->with($this->equalTo($customerId))->will($this->returnValue($confirmationStatus)); $this->subscriberMock->expects($this->once())->method('subscribeCustomerById')->with($this->equalTo($customerId)); $this->messageManagerMock->expects($this->any())->method('addSuccess')->with($this->stringContains($successMessage))->will($this->returnSelf()); $this->urlMock->expects($this->any())->method('getUrl')->willReturnMap([['*/*/index', ['_secure' => true], $successUrl], ['*/*/create', ['_secure' => true], $successUrl]]); $this->redirectMock->expects($this->once())->method('success')->with($this->equalTo($successUrl))->will($this->returnValue($successUrl)); $this->scopeConfigMock->expects($this->once())->method('isSetFlag')->with($this->equalTo(Url::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD), $this->equalTo(ScopeInterface::SCOPE_STORE))->will($this->returnValue($isSetFlag)); $this->storeMock->expects($this->any())->method('getFrontendName')->will($this->returnValue('frontend')); $this->storeManagerMock->expects($this->any())->method('getStore')->will($this->returnValue($this->storeMock)); $this->model->execute(); }
/** * 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; }