65 lines
2.3 KiB
PHP
65 lines
2.3 KiB
PHP
<?php
|
|
|
|
|
|
namespace Stemcell\Customer\Controller\Account;
|
|
|
|
|
|
use Magento\Customer\Controller\Account;
|
|
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
|
|
|
|
use Magento\Framework\App\ObjectManager;
|
|
use Magento\Framework\Exception\InputException;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class ResetPasswordPost extends Account\ResetPasswordPost implements HttpPostActionInterface
|
|
{
|
|
public function execute()
|
|
{
|
|
$resultRedirect = $this->resultRedirectFactory->create();
|
|
$password = (string)$this->getRequest()->getPost('password');
|
|
$passwordConfirmation = (string)$this->getRequest()->getPost('password_confirmation');
|
|
|
|
if ($password !== $passwordConfirmation) {
|
|
$this->messageManager->addErrorMessage(__("New Password and Confirm New Password values didn't match."));
|
|
$resultRedirect->setPath('customer/account/forgotpassword');
|
|
|
|
return $resultRedirect;
|
|
}
|
|
|
|
if (iconv_strlen($password) <= 0) {
|
|
$this->messageManager->addErrorMessage(__('Please enter a new password.'));
|
|
$resultRedirect->setPath('customer/account/forgotpassword');
|
|
|
|
return $resultRedirect;
|
|
}
|
|
|
|
try {
|
|
$this->accountManagement->resetPassword(
|
|
$this->_request->getParam('email'),
|
|
null,
|
|
$password
|
|
);
|
|
// logout from current session if password changed.
|
|
if ($this->session->isLoggedIn()) {
|
|
$this->session->logout();
|
|
$this->session->start();
|
|
}
|
|
$this->session->unsRpToken();
|
|
$this->messageManager->addSuccessMessage(__('You updated your password.'));
|
|
$resultRedirect->setPath('customer/account/login');
|
|
|
|
return $resultRedirect;
|
|
} catch (InputException $e) {
|
|
$this->messageManager->addErrorMessage(__('Something went wrong while saving the new password.'));
|
|
foreach ($e->getErrors() as $error) {
|
|
$this->messageManager->addErrorMessage($error->getMessage());
|
|
}
|
|
} catch (\Exception $exception) {
|
|
$this->messageManager->addErrorMessage($exception->getMessage());
|
|
}
|
|
$resultRedirect->setPath('customer/account/forgotpassword');
|
|
|
|
return $resultRedirect;
|
|
}
|
|
}
|