Skip to content

Commit b94ba64

Browse files
AnshuMishra17gelanivishal
authored andcommitted
Changes as per comments on Github
1 parent 8749f69 commit b94ba64

File tree

3 files changed

+48
-36
lines changed

3 files changed

+48
-36
lines changed

app/code/Magento/User/Controller/Adminhtml/Auth.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@
88

99
use Magento\Framework\Encryption\Helper\Security;
1010
use Magento\Framework\App\ObjectManager;
11+
use Magento\Backend\App\AbstractAction;
12+
use Magento\Backend\App\Action\Context;
13+
use Magento\User\Model\UserFactory;
14+
use Magento\Backend\Helper\Data;
15+
use Magento\Framework\Exception\LocalizedException;
1116

1217
/**
1318
* \Magento\User Auth controller
1419
*/
15-
abstract class Auth extends \Magento\Backend\App\AbstractAction
20+
abstract class Auth extends AbstractAction
1621
{
1722
/**
1823
* User model factory
@@ -24,24 +29,23 @@ abstract class Auth extends \Magento\Backend\App\AbstractAction
2429
/**
2530
* @var \Magento\Backend\Helper\Data
2631
*/
27-
protected $_backendHelper;
32+
protected $_backendDataHelper;
2833

2934
/**
3035
* Construct
3136
*
32-
* @param \Magento\Backend\App\Action\Context $context
33-
* @param \Magento\User\Model\UserFactory $userFactory
34-
* @param \Magento\Backend\Helper\Data $backendHelper
37+
* @param Context $context
38+
* @param UserFactory $userFactory
39+
* @param Data $backendDataHelper
3540
*/
3641
public function __construct(
37-
\Magento\Backend\App\Action\Context $context,
38-
\Magento\User\Model\UserFactory $userFactory,
39-
\Magento\Backend\Helper\Data $backendHelper = null
42+
Context $context,
43+
UserFactory $userFactory,
44+
Data $backendDataHelper = null
4045
) {
4146
parent::__construct($context);
4247
$this->_userFactory = $userFactory;
43-
$this->_backendHelper = $backendHelper ?:
44-
ObjectManager::getInstance()->get(\Magento\Backend\Helper\Data::class);
48+
$this->_backendDataHelper = $backendDataHelper ?: ObjectManager::getInstance()->get(Data::class);
4549
}
4650

4751
/**
@@ -50,7 +54,7 @@ public function __construct(
5054
* @param int $userId
5155
* @param string $resetPasswordToken
5256
* @return void
53-
* @throws \Magento\Framework\Exception\LocalizedException
57+
* @throws LocalizedException
5458
*/
5559
protected function _validateResetPasswordLinkToken($userId, $resetPasswordToken)
5660
{
@@ -60,22 +64,20 @@ protected function _validateResetPasswordLinkToken($userId, $resetPasswordToken)
6064
$resetPasswordToken
6165
) || empty($resetPasswordToken) || empty($userId) || $userId < 0
6266
) {
63-
throw new \Magento\Framework\Exception\LocalizedException(
64-
__('The password reset token is incorrect. Verify the token and try again.')
65-
);
67+
throw new LocalizedException(__('Please correct the password reset token.'));
6668
}
6769

6870
/** @var $user \Magento\User\Model\User */
6971
$user = $this->_userFactory->create()->load($userId);
7072
if (!$user->getId()) {
71-
throw new \Magento\Framework\Exception\LocalizedException(
73+
throw new LocalizedException(
7274
__('Please specify the correct account and try again.')
7375
);
7476
}
7577

7678
$userToken = $user->getRpToken();
7779
if (!Security::compareStrings($userToken, $resetPasswordToken) || $user->isResetPasswordLinkTokenExpired()) {
78-
throw new \Magento\Framework\Exception\LocalizedException(__('Your password reset link has expired.'));
80+
throw new LocalizedException(__('Your password reset link has expired.'));
7981
}
8082
}
8183

app/code/Magento/User/Controller/Adminhtml/Auth/Forgotpassword.php

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88

99
use Magento\Security\Model\SecurityManager;
1010
use Magento\Framework\App\ObjectManager;
11+
use Magento\Backend\App\Action\Context;
12+
use Magento\User\Model\UserFactory;
13+
use Magento\Security\Model\SecurityManager;
14+
use Magento\User\Model\ResourceModel\User\CollectionFactory;
15+
use Magento\Framework\Validator\EmailAddress;
16+
use Magento\Security\Model\PasswordResetRequestEvent;
17+
use Magento\Framework\Exception\SecurityViolationException;
18+
use Magento\User\Controller\Adminhtml\Auth;
1119

12-
class Forgotpassword extends \Magento\User\Controller\Adminhtml\Auth
20+
class Forgotpassword extends Auth
1321
{
1422
/**
1523
* @var SecurityManager
@@ -19,26 +27,26 @@ class Forgotpassword extends \Magento\User\Controller\Adminhtml\Auth
1927
/**
2028
* User model factory
2129
*
22-
* @var \Magento\User\Model\ResourceModel\User\CollectionFactory
30+
* @var CollectionFactory
2331
*/
2432
private $userCollectionFactory;
2533

2634
/**
27-
* @param \Magento\Backend\App\Action\Context $context
28-
* @param \Magento\User\Model\UserFactory $userFactory
29-
* @param \Magento\Security\Model\SecurityManager $securityManager
30-
* @param \Magento\User\Model\ResourceModel\User\CollectionFactory $userCollectionFactory
35+
* @param Context $context
36+
* @param UserFactory $userFactory
37+
* @param SecurityManager $securityManager
38+
* @param CollectionFactory $userCollectionFactory
3139
*/
3240
public function __construct(
33-
\Magento\Backend\App\Action\Context $context,
34-
\Magento\User\Model\UserFactory $userFactory,
35-
\Magento\Security\Model\SecurityManager $securityManager,
36-
\Magento\User\Model\ResourceModel\User\CollectionFactory $userCollectionFactory = null
41+
Context $context,
42+
UserFactory $userFactory,
43+
SecurityManager $securityManager,
44+
CollectionFactory $userCollectionFactory = null
3745
) {
3846
parent::__construct($context, $userFactory);
3947
$this->securityManager = $securityManager;
4048
$this->userCollectionFactory = $userCollectionFactory ?:
41-
ObjectManager::getInstance()->get(\Magento\User\Model\ResourceModel\User\CollectionFactory::class);
49+
ObjectManager::getInstance()->get(CollectionFactory::class);
4250
}
4351

4452
/**
@@ -56,18 +64,18 @@ public function execute()
5664
$resultRedirect = $this->resultRedirectFactory->create();
5765
if (!empty($email) && !empty($params)) {
5866
// Validate received data to be an email address
59-
if (\Zend_Validate::is($email, \Magento\Framework\Validator\EmailAddress::class)) {
67+
if (\Zend_Validate::is($email, EmailAddress::class)) {
6068
try {
6169
$this->securityManager->performSecurityCheck(
62-
\Magento\Security\Model\PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST,
70+
PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST,
6371
$email
6472
);
65-
} catch (\Magento\Framework\Exception\SecurityViolationException $exception) {
73+
} catch (SecurityViolationException $exception) {
6674
$this->messageManager->addErrorMessage($exception->getMessage());
6775
return $resultRedirect->setPath('admin');
6876
}
69-
$collection = $this->userCollectionFactory->create();
7077
/** @var $collection \Magento\User\Model\ResourceModel\User\Collection */
78+
$collection = $this->userCollectionFactory->create();
7179
$collection->addFieldToFilter('email', $email);
7280
$collection->load(false);
7381

@@ -77,7 +85,7 @@ public function execute()
7785
/** @var \Magento\User\Model\User $user */
7886
$user = $this->_userFactory->create()->load($item->getId());
7987
if ($user->getId()) {
80-
$newPassResetToken = $this->_backendHelper->generateResetPasswordLinkToken();
88+
$newPassResetToken = $this->_backendDataHelper->generateResetPasswordLinkToken();
8189
$user->changeResetPasswordLinkToken($newPassResetToken);
8290
$user->save();
8391
$user->sendPasswordResetConfirmationEmail();
@@ -96,7 +104,7 @@ public function execute()
96104
$this->messageManager->addSuccess(__('We\'ll email you a link to reset your password.'));
97105
// @codingStandardsIgnoreEnd
98106
$this->getResponse()->setRedirect(
99-
$this->_backendHelper->getHomePageUrl()
107+
$this->_backendDataHelper->getHomePageUrl()
100108
);
101109
return;
102110
} else {

app/code/Magento/User/Controller/Adminhtml/Auth/ResetPasswordPost.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77
namespace Magento\User\Controller\Adminhtml\Auth;
88

9-
class ResetPasswordPost extends \Magento\User\Controller\Adminhtml\Auth
9+
use Magento\User\Controller\Adminhtml\Auth;
10+
11+
class ResetPasswordPost extends Auth
1012
{
1113
/**
1214
* Reset forgotten password
@@ -27,7 +29,7 @@ public function execute()
2729
} catch (\Exception $exception) {
2830
$this->messageManager->addError(__('Your password reset link has expired.'));
2931
$this->getResponse()->setRedirect(
30-
$this->_backendHelper->getHomePageUrl()
32+
$this->_backendDataHelper->getHomePageUrl()
3133
);
3234
return;
3335
}
@@ -53,7 +55,7 @@ public function execute()
5355
$user->save();
5456
$this->messageManager->addSuccess(__('You updated your password.'));
5557
$this->getResponse()->setRedirect(
56-
$this->_backendHelper->getHomePageUrl()
58+
$this->_backendDataHelper->getHomePageUrl()
5759
);
5860
}
5961
} catch (\Magento\Framework\Validator\Exception $exception) {

0 commit comments

Comments
 (0)