Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ResetPassword.php
Go to the documentation of this file.
1 <?php
7 
11 
18 {
24  public function execute()
25  {
26  $resultRedirect = $this->resultRedirectFactory->create();
27  $customerId = (int)$this->getRequest()->getParam('customer_id', 0);
28  if (!$customerId) {
29  $resultRedirect->setPath('customer/index');
30  return $resultRedirect;
31  }
32 
33  try {
34  $customer = $this->_customerRepository->getById($customerId);
35  $this->customerAccountManagement->initiatePasswordReset(
36  $customer->getEmail(),
38  $customer->getWebsiteId()
39  );
40  $this->messageManager->addSuccess(__('The customer will receive an email with a link to reset password.'));
41  } catch (NoSuchEntityException $exception) {
42  $resultRedirect->setPath('customer/index');
43  return $resultRedirect;
44  } catch (\Magento\Framework\Validator\Exception $exception) {
45  $messages = $exception->getMessages(\Magento\Framework\Message\MessageInterface::TYPE_ERROR);
46  if (!count($messages)) {
47  $messages = $exception->getMessage();
48  }
49  $this->_addSessionErrorMessages($messages);
50  } catch (SecurityViolationException $exception) {
51  $this->messageManager->addErrorMessage($exception->getMessage());
52  } catch (\Exception $exception) {
53  $this->messageManager->addException(
54  $exception,
55  __('Something went wrong while resetting customer password.')
56  );
57  }
58  $resultRedirect->setPath(
59  'customer/*/edit',
60  ['id' => $customerId, '_current' => true]
61  );
62  return $resultRedirect;
63  }
64 }
$customer
Definition: customers.php:11
__()
Definition: __.php:13