當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AccountManagementInterface::activate方法代碼示例

本文整理匯總了PHP中Magento\Customer\Api\AccountManagementInterface::activate方法的典型用法代碼示例。如果您正苦於以下問題:PHP AccountManagementInterface::activate方法的具體用法?PHP AccountManagementInterface::activate怎麽用?PHP AccountManagementInterface::activate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Magento\Customer\Api\AccountManagementInterface的用法示例。


在下文中一共展示了AccountManagementInterface::activate方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: execute

 /**
  * Confirm customer account by id and confirmation key
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
     if ($this->_getSession()->isLoggedIn()) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     try {
         $customerId = $this->getRequest()->getParam('id', false);
         $key = $this->getRequest()->getParam('key', false);
         if (empty($customerId) || empty($key)) {
             throw new \Exception(__('Bad request.'));
         }
         // log in and send greeting email
         $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
         $customer = $this->customerAccountManagement->activate($customerEmail, $key);
         $this->_getSession()->setCustomerDataAsLoggedIn($customer);
         $this->messageManager->addSuccess($this->getSuccessMessage());
         $resultRedirect->setUrl($this->getSuccessRedirect());
         return $resultRedirect;
     } catch (StateException $e) {
         $this->messageManager->addException($e, __('This confirmation key is invalid or has expired.'));
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('There was an error confirming the account'));
     }
     $url = $this->urlModel->getUrl('*/*/index', ['_secure' => true]);
     return $resultRedirect->setUrl($this->_redirect->error($url));
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:34,代碼來源:Confirm.php

示例2: testActivateCustomerAlreadyActive

 /**
  * @magentoDataFixture Magento/Customer/_files/inactive_customer.php
  * @magentoAppArea frontend
  * @expectedException \Magento\Framework\Exception\State\InvalidTransitionException
  */
 public function testActivateCustomerAlreadyActive()
 {
     /** @var \Magento\Customer\Model\Customer $customerModel */
     $customerModel = $this->objectManager->create('Magento\\Customer\\Model\\Customer');
     $customerModel->load(1);
     $key = $customerModel->getConfirmation();
     $this->accountManagement->activate($customerModel->getEmail(), $key);
     // activate it one more time to produce an exception
     $this->accountManagement->activate($customerModel->getEmail(), $key);
 }
開發者ID:kidaa30,項目名稱:magento2-platformsh,代碼行數:15,代碼來源:AccountManagementTest.php

示例3: execute

 /**
  * Confirm customer account by id and confirmation key
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @throws \Exception
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($this->_getSession()->isLoggedIn()) {
         $resultRedirect->setPath('*/*/');
         return $resultRedirect;
     }
     $customerId = $this->getRequest()->getParam('id', false);
     $key = $this->getRequest()->getParam('key', false);
     if (empty($customerId) || empty($key)) {
         throw new \Exception(__('Bad request.'));
     }
     // log in and send greeting email
     $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
     $customer = $this->customerAccountManagement->activate($customerEmail, $key);
     $this->_getSession()->setCustomerDataAsLoggedIn($customer);
     $this->messageManager->addSuccess($this->getSuccessMessage());
     $resultRedirect->setUrl($this->getSuccessRedirect());
     return $resultRedirect;
 }
開發者ID:opexsw,項目名稱:magento2,代碼行數:27,代碼來源:Confirm.php


注:本文中的Magento\Customer\Api\AccountManagementInterface::activate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。