当前位置: 首页>>代码示例>>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;未经允许,请勿转载。