本文整理匯總了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;
}
示例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);
}
示例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;
}
示例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');
}