27 use Magento\Newsletter\Model\SubscriberFactory;
28 use Magento\Customer\Api\Data\RegionInterfaceFactory;
29 use Magento\Customer\Api\Data\AddressInterfaceFactory;
30 use Magento\Customer\Api\Data\CustomerInterfaceFactory;
119 private $accountRedirect;
124 private $cookieMetadataFactory;
129 private $cookieMetadataManager;
134 private $formKeyValidator;
177 AccountRedirect $accountRedirect,
180 $this->session = $customerSession;
181 $this->scopeConfig = $scopeConfig;
194 $this->urlModel = $urlFactory->
create();
196 $this->accountRedirect = $accountRedirect;
198 parent::__construct($context);
207 private function getCookieManager()
209 if (!$this->cookieMetadataManager) {
211 \
Magento\Framework\Stdlib\Cookie\PhpCookieManager::class
214 return $this->cookieMetadataManager;
223 private function getCookieMetadataFactory()
225 if (!$this->cookieMetadataFactory) {
227 \
Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class
230 return $this->cookieMetadataFactory;
240 if (!$this->
getRequest()->getPost(
'create_address')) {
244 $addressForm = $this->formFactory->create(
'customer_address',
'customer_register_address');
245 $allowedAttributes = $addressForm->getAllowedAttributes();
249 $regionDataObject = $this->regionDataFactory->create();
258 $regionDataObject->setRegionId(
$value);
261 $regionDataObject->setRegion(
$value);
267 $addressDataObject = $this->addressDataFactory->create();
268 $this->dataObjectHelper->populateWithArray(
271 \
Magento\Customer\Api\Data\AddressInterface::class
273 $addressDataObject->setRegion($regionDataObject);
275 $addressDataObject->setIsDefaultBilling(
276 $this->
getRequest()->getParam(
'default_billing',
false)
277 )->setIsDefaultShipping(
278 $this->
getRequest()->getParam(
'default_shipping',
false)
280 return $addressDataObject;
290 $resultRedirect = $this->resultRedirectFactory->create();
291 $url = $this->urlModel->getUrl(
'*/*/create', [
'_secure' =>
true]);
296 [
new Phrase(
'Invalid Form Key. Please refresh the page.')]
318 $resultRedirect = $this->resultRedirectFactory->create();
319 if ($this->session->isLoggedIn() || !$this->registration->isAllowed()) {
320 $resultRedirect->setPath(
'*/*/');
321 return $resultRedirect;
325 || !$this->formKeyValidator->validate($this->getRequest())
327 $url = $this->urlModel->getUrl(
'*/*/create', [
'_secure' =>
true]);
328 return $this->resultRedirectFactory->create()
332 $this->session->regenerateId();
338 $customer = $this->customerExtractor->extract(
'customer_account_create', $this->_request);
341 $password = $this->
getRequest()->getParam(
'password');
342 $confirmation = $this->
getRequest()->getParam(
'password_confirmation');
343 $redirectUrl = $this->session->getBeforeAuthUrl();
348 ->createAccount(
$customer, $password, $redirectUrl);
350 if ($this->
getRequest()->getParam(
'is_subscribed',
false)) {
351 $this->subscriberFactory->create()->subscribeCustomerById(
$customer->getId());
354 $this->_eventManager->dispatch(
355 'customer_register_success',
356 [
'account_controller' => $this,
'customer' =>
$customer]
359 $confirmationStatus = $this->accountManagement->getConfirmationStatus(
$customer->getId());
361 $email = $this->customerUrl->getEmailConfirmationUrl(
$customer->getEmail());
363 $this->messageManager->addSuccess(
365 'You must confirm your account. Please check your email for the confirmation link or <a href="%1">click here</a> for a new link.',
370 $url = $this->urlModel->getUrl(
'*/*/index', [
'_secure' =>
true]);
373 $this->session->setCustomerDataAsLoggedIn(
$customer);
375 $requestedRedirect = $this->accountRedirect->getRedirectCookie();
376 if (!$this->scopeConfig->getValue(
'customer/startup/redirect_dashboard') && $requestedRedirect) {
377 $resultRedirect->setUrl($this->
_redirect->success($requestedRedirect));
378 $this->accountRedirect->clearRedirectCookie();
379 return $resultRedirect;
381 $resultRedirect = $this->accountRedirect->getRedirect();
383 if ($this->getCookieManager()->getCookie(
'mage-cache-sessid')) {
384 $metadata = $this->getCookieMetadataFactory()->createCookieMetadata();
385 $metadata->setPath(
'/');
386 $this->getCookieManager()->deleteCookie(
'mage-cache-sessid', $metadata);
389 return $resultRedirect;
390 }
catch (StateException $e) {
391 $url = $this->urlModel->getUrl(
'customer/account/forgotpassword');
394 '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.',
398 $this->messageManager->addError(
$message);
399 }
catch (InputException $e) {
400 $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage()));
401 foreach ($e->getErrors() as $error) {
402 $this->messageManager->addError($this->escaper->escapeHtml($error->getMessage()));
404 }
catch (LocalizedException $e) {
405 $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage()));
406 }
catch (\Exception $e) {
407 $this->messageManager->addException($e,
__(
'We can\'t save the customer.'));
410 $this->session->setCustomerFormData($this->
getRequest()->getPostValue());
411 $defaultUrl = $this->urlModel->getUrl(
'*/*/create', [
'_secure' =>
true]);
412 return $resultRedirect->setUrl($this->
_redirect->error($defaultUrl));
425 if ($password != $confirmation) {
437 if ($this->addressHelper->isVatValidationEnabled()) {
441 'If you are a registered VAT customer, please <a href="%1">click here</a> to enter your shipping address for proper VAT calculation.',
442 $this->urlModel->getUrl(
'customer/address/edit')
448 'If you are a registered VAT customer, please <a href="%1">click here</a> to enter your billing address for proper VAT calculation.',
449 $this->urlModel->getUrl(
'customer/address/edit')
454 $message =
__(
'Thank you for registering with %1.', $this->storeManager->getStore()->getFrontendName());
_redirect($path, $arguments=[])
checkPasswordConfirmation($password, $confirmation)
__construct(Context $context, Session $customerSession, ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, AccountManagementInterface $accountManagement, Address $addressHelper, UrlFactory $urlFactory, FormFactory $formFactory, SubscriberFactory $subscriberFactory, RegionInterfaceFactory $regionDataFactory, AddressInterfaceFactory $addressDataFactory, CustomerInterfaceFactory $customerDataFactory, CustomerUrl $customerUrl, Registration $registration, Escaper $escaper, CustomerExtractor $customerExtractor, DataObjectHelper $dataObjectHelper, AccountRedirect $accountRedirect, Validator $formKeyValidator=null)
validateForCsrf(RequestInterface $request)
createCsrfValidationException(RequestInterface $request)
const ACCOUNT_CONFIRMATION_REQUIRED