當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。