当前位置: 首页>>代码示例>>PHP>>正文


PHP AccountManagementInterface::changePassword方法代码示例

本文整理汇总了PHP中Magento\Customer\Api\AccountManagementInterface::changePassword方法的典型用法代码示例。如果您正苦于以下问题:PHP AccountManagementInterface::changePassword方法的具体用法?PHP AccountManagementInterface::changePassword怎么用?PHP AccountManagementInterface::changePassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Api\AccountManagementInterface的用法示例。


在下文中一共展示了AccountManagementInterface::changePassword方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * Change customer password action
  *
  * @return \Magento\Framework\Controller\Result\Redirect
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function execute()
 {
     /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if (!$this->formKeyValidator->validate($this->getRequest())) {
         $resultRedirect->setPath('*/*/edit');
         return $resultRedirect;
     }
     if ($this->getRequest()->isPost()) {
         $customerId = $this->_getSession()->getCustomerId();
         $customer = $this->customerExtractor->extract('customer_account_edit', $this->_request);
         $customer->setId($customerId);
         if ($customer->getAddresses() == null) {
             $customer->setAddresses($this->customerRepository->getById($customerId)->getAddresses());
         }
         if ($this->getRequest()->getParam('change_password')) {
             $currPass = $this->getRequest()->getPost('current_password');
             $newPass = $this->getRequest()->getPost('password');
             $confPass = $this->getRequest()->getPost('password_confirmation');
             if (strlen($newPass)) {
                 if ($newPass == $confPass) {
                     try {
                         $customerEmail = $this->customerRepository->getById($customerId)->getEmail();
                         $this->customerAccountManagement->changePassword($customerEmail, $currPass, $newPass);
                     } catch (AuthenticationException $e) {
                         $this->messageManager->addError($e->getMessage());
                     } catch (\Exception $e) {
                         $this->messageManager->addException($e, __('Something went wrong while changing the password.'));
                     }
                 } else {
                     $this->messageManager->addError(__('Confirm your new password.'));
                 }
             } else {
                 $this->messageManager->addError(__('Please enter new password.'));
             }
         }
         try {
             $this->customerRepository->save($customer);
         } catch (AuthenticationException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (InputException $e) {
             $this->messageManager->addException($e, __('Invalid input'));
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('We can\'t save the customer.') . $e->getMessage() . '<pre>' . $e->getTraceAsString() . '</pre>');
         }
         if ($this->messageManager->getMessages()->getCount() > 0) {
             $this->_getSession()->setCustomerFormData($this->getRequest()->getPostValue());
             $resultRedirect->setPath('*/*/edit');
             return $resultRedirect;
         }
         $this->messageManager->addSuccess(__('You saved the account information.'));
         $resultRedirect->setPath('customer/account');
         return $resultRedirect;
     }
     $resultRedirect->setPath('*/*/edit');
     return $resultRedirect;
 }
开发者ID:nja78,项目名称:magento2,代码行数:63,代码来源:EditPost.php

示例2: changeCustomerPassword

 /**
  * Change customer password
  *
  * @param string $email
  * @return bool
  * @throws InvalidEmailOrPasswordException|InputException
  */
 protected function changeCustomerPassword($email)
 {
     $currPass = $this->getRequest()->getPost('current_password');
     $newPass = $this->getRequest()->getPost('password');
     $confPass = $this->getRequest()->getPost('password_confirmation');
     if ($newPass != $confPass) {
         throw new InputException(__('Password confirmation doesn\'t match entered password.'));
     }
     return $this->customerAccountManagement->changePassword($email, $currPass, $newPass);
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:17,代码来源:EditPost.php

示例3: changeCustomerPassword

 /**
  * Change customer password
  *
  * @param string $email
  * @return $this
  */
 protected function changeCustomerPassword($email)
 {
     $currPass = $this->getRequest()->getPost('current_password');
     $newPass = $this->getRequest()->getPost('password');
     $confPass = $this->getRequest()->getPost('password_confirmation');
     if (!strlen($newPass)) {
         $this->messageManager->addError(__('Please enter new password.'));
         return $this;
     }
     if ($newPass !== $confPass) {
         $this->messageManager->addError(__('Confirm your new password.'));
         return $this;
     }
     try {
         $this->customerAccountManagement->changePassword($email, $currPass, $newPass);
     } catch (AuthenticationException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __('Something went wrong while changing the password.'));
     }
     return $this;
 }
开发者ID:nblair,项目名称:magescotch,代码行数:28,代码来源:EditPost.php

示例4: testChangePasswordWrongUser

 /**
  * @expectedException \Magento\Framework\Exception\InvalidEmailOrPasswordException
  * @expectedExceptionMessage Invalid login or password.
  */
 public function testChangePasswordWrongUser()
 {
     $this->accountManagement->changePassword('wrong.email@example.com', 'password', 'new_password');
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:8,代码来源:AccountManagementTest.php


注:本文中的Magento\Customer\Api\AccountManagementInterface::changePassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。