Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Confirmation.php
Go to the documentation of this file.
1 <?php
8 
17 
19 {
23  protected $storeManager;
24 
29 
33  protected $session;
34 
38  protected $resultPageFactory;
39 
43  private $customerUrl;
44 
53  public function __construct(
54  Context $context,
55  Session $customerSession,
59  Url $customerUrl = null
60  ) {
61  $this->session = $customerSession;
62  $this->resultPageFactory = $resultPageFactory;
63  $this->storeManager = $storeManager;
64  $this->customerAccountManagement = $customerAccountManagement;
65  $this->customerUrl = $customerUrl ?: ObjectManager::getInstance()->get(Url::class);
66  parent::__construct($context);
67  }
68 
74  public function execute()
75  {
76  if ($this->session->isLoggedIn()) {
78  $resultRedirect = $this->resultRedirectFactory->create();
79  $resultRedirect->setPath('*/*/');
80  return $resultRedirect;
81  }
82 
83  // try to confirm by email
84  $email = $this->getRequest()->getPost('email');
85  if ($email) {
87  $resultRedirect = $this->resultRedirectFactory->create();
88 
89  try {
90  $this->customerAccountManagement->resendConfirmation(
91  $email,
92  $this->storeManager->getStore()->getWebsiteId()
93  );
94  $this->messageManager->addSuccess(__('Please check your email for confirmation key.'));
95  } catch (InvalidTransitionException $e) {
96  $this->messageManager->addSuccess(__('This email does not require confirmation.'));
97  } catch (\Exception $e) {
98  $this->messageManager->addException($e, __('Wrong email.'));
99  $resultRedirect->setPath('*/*/*', ['email' => $email, '_secure' => true]);
100  return $resultRedirect;
101  }
102  $this->session->setUsername($email);
103  $resultRedirect->setPath('*/*/index', ['_secure' => true]);
104  return $resultRedirect;
105  }
106 
108  $resultPage = $this->resultPageFactory->create();
109  $resultPage->getLayout()->getBlock('accountConfirmation')->setEmail(
110  $this->getRequest()->getParam('email', $email)
111  )->setLoginUrl(
112  $this->customerUrl->getLoginUrl()
113  );
114  return $resultPage;
115  }
116 }
__construct(Context $context, Session $customerSession, PageFactory $resultPageFactory, StoreManagerInterface $storeManager, AccountManagementInterface $customerAccountManagement, Url $customerUrl=null)
$email
Definition: details.phtml:13
__()
Definition: __.php:13