Skip to content

Commit

Permalink
Merge pull request #584 from magento-south/MAGETWO-38562
Browse files Browse the repository at this point in the history
[South] Customer - Inline editing + Bug fixes
  • Loading branch information
slavvka committed Sep 9, 2015
2 parents ae8c9cd + 00fecf4 commit 91eeac1
Show file tree
Hide file tree
Showing 32 changed files with 2,274 additions and 575 deletions.
83 changes: 47 additions & 36 deletions app/code/Magento/Customer/Controller/Account/EditPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,42 +70,23 @@ 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;
return $resultRedirect->setPath('*/*/edit');
}

if ($this->getRequest()->isPost()) {
$customerId = $this->_getSession()->getCustomerId();
$currentCustomer = $this->customerRepository->getById($customerId);

// Prepare new customer data
$customer = $this->customerExtractor->extract('customer_account_edit', $this->_request);
$customer->setId($customerId);
if ($customer->getAddresses() == null) {
$customer->setAddresses($this->customerRepository->getById($customerId)->getAddresses());
$customer->setAddresses($currentCustomer->getAddresses());
}

// Change customer password
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.'));
}
$this->changeCustomerPassword($currentCustomer->getEmail());
}

try {
Expand All @@ -115,24 +96,54 @@ public function execute()
} 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>'
);
$message = __('We can\'t save the customer.')
. $e->getMessage()
. '<pre>' . $e->getTraceAsString() . '</pre>';
$this->messageManager->addException($e, $message);
}

if ($this->messageManager->getMessages()->getCount() > 0) {
$this->_getSession()->setCustomerFormData($this->getRequest()->getPostValue());
$resultRedirect->setPath('*/*/edit');
return $resultRedirect;
return $resultRedirect->setPath('*/*/edit');
}

$this->messageManager->addSuccess(__('You saved the account information.'));
$resultRedirect->setPath('customer/account');
return $resultRedirect;
return $resultRedirect->setPath('customer/account');
}

return $resultRedirect->setPath('*/*/edit');
}

/**
* 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.'));
}

$resultRedirect->setPath('*/*/edit');
return $resultRedirect;
return $this;
}
}
42 changes: 28 additions & 14 deletions app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use Magento\Framework\Escaper;
use Magento\Framework\Exception\NoSuchEntityException;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ForgotPasswordPost extends \Magento\Customer\Controller\Account
{
/** @var AccountManagementInterface */
Expand Down Expand Up @@ -54,9 +57,8 @@ public function execute()
if ($email) {
if (!\Zend_Validate::is($email, 'EmailAddress')) {
$this->_getSession()->setForgottenEmail($email);
$this->messageManager->addError(__('Please correct the email address.'));
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
$this->messageManager->addErrorMessage(__('Please correct the email address.'));
return $resultRedirect->setPath('*/*/forgotpassword');
}

try {
Expand All @@ -67,19 +69,31 @@ public function execute()
} catch (NoSuchEntityException $e) {
// Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
} catch (\Exception $exception) {
$this->messageManager->addException($exception, __('We\'re unable to send the password reset email.'));
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
$this->messageManager->addExceptionMessage(
$exception,
__('We\'re unable to send the password reset email.')
);
return $resultRedirect->setPath('*/*/forgotpassword');
}
// @codingStandardsIgnoreStart
$this->messageManager->addSuccess(__('We\'ll email you a link to reset your password.'));
// @codingStandardsIgnoreEnd
$resultRedirect->setPath('*/*/');
return $resultRedirect;
$this->messageManager->addSuccessMessage($this->getSuccessMessage($email));
return $resultRedirect->setPath('*/*/');
} else {
$this->messageManager->addError(__('Please enter your email.'));
$resultRedirect->setPath('*/*/forgotpassword');
return $resultRedirect;
$this->messageManager->addErrorMessage(__('Please enter your email.'));
return $resultRedirect->setPath('*/*/forgotpassword');
}
}

/**
* Retrieve success message
*
* @param string $email
* @return \Magento\Framework\Phrase
*/
protected function getSuccessMessage($email)
{
return __(
'If there is an account associated with %1 you will receive an email with a link to reset your password.',
$this->escaper->escapeHtml($email)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class InvalidateToken extends \Magento\Customer\Controller\Adminhtml\Index
protected $tokenService;

/**
* @param CustomerTokenServiceInterface $tokenService
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
Expand All @@ -59,6 +58,7 @@ class InvalidateToken extends \Magento\Customer\Controller\Adminhtml\Index
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
* @param CustomerTokenServiceInterface $tokenService
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
Expand Down
Loading

0 comments on commit 91eeac1

Please sign in to comment.