Skip to content

Commit 91eeac1

Browse files
committed
Merge pull request #584 from magento-south/MAGETWO-38562
[South] Customer - Inline editing + Bug fixes
2 parents ae8c9cd + 00fecf4 commit 91eeac1

File tree

32 files changed

+2274
-575
lines changed

32 files changed

+2274
-575
lines changed

app/code/Magento/Customer/Controller/Account/EditPost.php

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -70,42 +70,23 @@ public function execute()
7070
/** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
7171
$resultRedirect = $this->resultRedirectFactory->create();
7272
if (!$this->formKeyValidator->validate($this->getRequest())) {
73-
$resultRedirect->setPath('*/*/edit');
74-
return $resultRedirect;
73+
return $resultRedirect->setPath('*/*/edit');
7574
}
7675

7776
if ($this->getRequest()->isPost()) {
7877
$customerId = $this->_getSession()->getCustomerId();
78+
$currentCustomer = $this->customerRepository->getById($customerId);
79+
80+
// Prepare new customer data
7981
$customer = $this->customerExtractor->extract('customer_account_edit', $this->_request);
8082
$customer->setId($customerId);
8183
if ($customer->getAddresses() == null) {
82-
$customer->setAddresses($this->customerRepository->getById($customerId)->getAddresses());
84+
$customer->setAddresses($currentCustomer->getAddresses());
8385
}
8486

87+
// Change customer password
8588
if ($this->getRequest()->getParam('change_password')) {
86-
$currPass = $this->getRequest()->getPost('current_password');
87-
$newPass = $this->getRequest()->getPost('password');
88-
$confPass = $this->getRequest()->getPost('password_confirmation');
89-
90-
if (strlen($newPass)) {
91-
if ($newPass == $confPass) {
92-
try {
93-
$customerEmail = $this->customerRepository->getById($customerId)->getEmail();
94-
$this->customerAccountManagement->changePassword($customerEmail, $currPass, $newPass);
95-
} catch (AuthenticationException $e) {
96-
$this->messageManager->addError($e->getMessage());
97-
} catch (\Exception $e) {
98-
$this->messageManager->addException(
99-
$e,
100-
__('Something went wrong while changing the password.')
101-
);
102-
}
103-
} else {
104-
$this->messageManager->addError(__('Confirm your new password.'));
105-
}
106-
} else {
107-
$this->messageManager->addError(__('Please enter new password.'));
108-
}
89+
$this->changeCustomerPassword($currentCustomer->getEmail());
10990
}
11091

11192
try {
@@ -115,24 +96,54 @@ public function execute()
11596
} catch (InputException $e) {
11697
$this->messageManager->addException($e, __('Invalid input'));
11798
} catch (\Exception $e) {
118-
$this->messageManager->addException(
119-
$e,
120-
__('We can\'t save the customer.') . $e->getMessage() . '<pre>' . $e->getTraceAsString() . '</pre>'
121-
);
99+
$message = __('We can\'t save the customer.')
100+
. $e->getMessage()
101+
. '<pre>' . $e->getTraceAsString() . '</pre>';
102+
$this->messageManager->addException($e, $message);
122103
}
123104

124105
if ($this->messageManager->getMessages()->getCount() > 0) {
125106
$this->_getSession()->setCustomerFormData($this->getRequest()->getPostValue());
126-
$resultRedirect->setPath('*/*/edit');
127-
return $resultRedirect;
107+
return $resultRedirect->setPath('*/*/edit');
128108
}
129109

130110
$this->messageManager->addSuccess(__('You saved the account information.'));
131-
$resultRedirect->setPath('customer/account');
132-
return $resultRedirect;
111+
return $resultRedirect->setPath('customer/account');
112+
}
113+
114+
return $resultRedirect->setPath('*/*/edit');
115+
}
116+
117+
/**
118+
* Change customer password
119+
*
120+
* @param string $email
121+
* @return $this
122+
*/
123+
protected function changeCustomerPassword($email)
124+
{
125+
$currPass = $this->getRequest()->getPost('current_password');
126+
$newPass = $this->getRequest()->getPost('password');
127+
$confPass = $this->getRequest()->getPost('password_confirmation');
128+
129+
if (!strlen($newPass)) {
130+
$this->messageManager->addError(__('Please enter new password.'));
131+
return $this;
132+
}
133+
134+
if ($newPass !== $confPass) {
135+
$this->messageManager->addError(__('Confirm your new password.'));
136+
return $this;
137+
}
138+
139+
try {
140+
$this->customerAccountManagement->changePassword($email, $currPass, $newPass);
141+
} catch (AuthenticationException $e) {
142+
$this->messageManager->addError($e->getMessage());
143+
} catch (\Exception $e) {
144+
$this->messageManager->addException($e, __('Something went wrong while changing the password.'));
133145
}
134146

135-
$resultRedirect->setPath('*/*/edit');
136-
return $resultRedirect;
147+
return $this;
137148
}
138149
}

app/code/Magento/Customer/Controller/Account/ForgotPasswordPost.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Magento\Framework\Escaper;
1515
use Magento\Framework\Exception\NoSuchEntityException;
1616

17+
/**
18+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19+
*/
1720
class ForgotPasswordPost extends \Magento\Customer\Controller\Account
1821
{
1922
/** @var AccountManagementInterface */
@@ -54,9 +57,8 @@ public function execute()
5457
if ($email) {
5558
if (!\Zend_Validate::is($email, 'EmailAddress')) {
5659
$this->_getSession()->setForgottenEmail($email);
57-
$this->messageManager->addError(__('Please correct the email address.'));
58-
$resultRedirect->setPath('*/*/forgotpassword');
59-
return $resultRedirect;
60+
$this->messageManager->addErrorMessage(__('Please correct the email address.'));
61+
return $resultRedirect->setPath('*/*/forgotpassword');
6062
}
6163

6264
try {
@@ -67,19 +69,31 @@ public function execute()
6769
} catch (NoSuchEntityException $e) {
6870
// Do nothing, we don't want anyone to use this action to determine which email accounts are registered.
6971
} catch (\Exception $exception) {
70-
$this->messageManager->addException($exception, __('We\'re unable to send the password reset email.'));
71-
$resultRedirect->setPath('*/*/forgotpassword');
72-
return $resultRedirect;
72+
$this->messageManager->addExceptionMessage(
73+
$exception,
74+
__('We\'re unable to send the password reset email.')
75+
);
76+
return $resultRedirect->setPath('*/*/forgotpassword');
7377
}
74-
// @codingStandardsIgnoreStart
75-
$this->messageManager->addSuccess(__('We\'ll email you a link to reset your password.'));
76-
// @codingStandardsIgnoreEnd
77-
$resultRedirect->setPath('*/*/');
78-
return $resultRedirect;
78+
$this->messageManager->addSuccessMessage($this->getSuccessMessage($email));
79+
return $resultRedirect->setPath('*/*/');
7980
} else {
80-
$this->messageManager->addError(__('Please enter your email.'));
81-
$resultRedirect->setPath('*/*/forgotpassword');
82-
return $resultRedirect;
81+
$this->messageManager->addErrorMessage(__('Please enter your email.'));
82+
return $resultRedirect->setPath('*/*/forgotpassword');
8383
}
8484
}
85+
86+
/**
87+
* Retrieve success message
88+
*
89+
* @param string $email
90+
* @return \Magento\Framework\Phrase
91+
*/
92+
protected function getSuccessMessage($email)
93+
{
94+
return __(
95+
'If there is an account associated with %1 you will receive an email with a link to reset your password.',
96+
$this->escaper->escapeHtml($email)
97+
);
98+
}
8599
}

app/code/Magento/Customer/Controller/Adminhtml/Customer/InvalidateToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class InvalidateToken extends \Magento\Customer\Controller\Adminhtml\Index
3333
protected $tokenService;
3434

3535
/**
36-
* @param CustomerTokenServiceInterface $tokenService
3736
* @param \Magento\Backend\App\Action\Context $context
3837
* @param \Magento\Framework\Registry $coreRegistry
3938
* @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory
@@ -59,6 +58,7 @@ class InvalidateToken extends \Magento\Customer\Controller\Adminhtml\Index
5958
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
6059
* @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory
6160
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
61+
* @param CustomerTokenServiceInterface $tokenService
6262
*
6363
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6464
*/

0 commit comments

Comments
 (0)