本文整理汇总了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');
}