77namespace Magento \User \Controller \Adminhtml \Auth ;
88
99use Magento \Security \Model \SecurityManager ;
10+ use Magento \Framework \App \ObjectManager ;
11+ use Magento \Backend \App \Action \Context ;
12+ use Magento \User \Model \UserFactory ;
13+ use Magento \User \Model \ResourceModel \User \CollectionFactory ;
14+ use Magento \Framework \Validator \EmailAddress ;
15+ use Magento \Security \Model \PasswordResetRequestEvent ;
16+ use Magento \Framework \Exception \SecurityViolationException ;
17+ use Magento \User \Controller \Adminhtml \Auth ;
18+ use Magento \Backend \Helper \Data ;
1019
11- class Forgotpassword extends \ Magento \ User \ Controller \ Adminhtml \ Auth
20+ class Forgotpassword extends Auth
1221{
1322 /**
1423 * @var SecurityManager
1524 */
1625 protected $ securityManager ;
1726
1827 /**
19- * @param \Magento\Backend\App\Action\Context $context
20- * @param \Magento\User\Model\UserFactory $userFactory
21- * @param \Magento\Security\Model\SecurityManager $securityManager
28+ * User model factory
29+ *
30+ * @var CollectionFactory
31+ */
32+ private $ userCollectionFactory ;
33+
34+ /**
35+ * @var Data
36+ */
37+ private $ backendDataHelper ;
38+
39+ /**
40+ * @param Context $context
41+ * @param UserFactory $userFactory
42+ * @param SecurityManager $securityManager
43+ * @param CollectionFactory $userCollectionFactory
2244 */
2345 public function __construct (
24- \Magento \Backend \App \Action \Context $ context ,
25- \Magento \User \Model \UserFactory $ userFactory ,
26- \Magento \Security \Model \SecurityManager $ securityManager
46+ Context $ context ,
47+ UserFactory $ userFactory ,
48+ SecurityManager $ securityManager ,
49+ CollectionFactory $ userCollectionFactory = null ,
50+ Data $ backendDataHelper = null
2751 ) {
2852 parent ::__construct ($ context , $ userFactory );
2953 $ this ->securityManager = $ securityManager ;
54+ $ this ->userCollectionFactory = $ userCollectionFactory ?:
55+ ObjectManager::getInstance ()->get (CollectionFactory::class);
56+ $ this ->backendDataHelper = $ backendDataHelper ?:
57+ ObjectManager::getInstance ()->get (Data::class);
3058 }
3159
3260 /**
@@ -44,18 +72,18 @@ public function execute()
4472 $ resultRedirect = $ this ->resultRedirectFactory ->create ();
4573 if (!empty ($ email ) && !empty ($ params )) {
4674 // Validate received data to be an email address
47- if (\Zend_Validate::is ($ email , \ Magento \ Framework \ Validator \ EmailAddress::class)) {
75+ if (\Zend_Validate::is ($ email , EmailAddress::class)) {
4876 try {
4977 $ this ->securityManager ->performSecurityCheck (
50- \ Magento \ Security \ Model \ PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST ,
78+ PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST ,
5179 $ email
5280 );
53- } catch (\ Magento \ Framework \ Exception \ SecurityViolationException $ exception ) {
81+ } catch (SecurityViolationException $ exception ) {
5482 $ this ->messageManager ->addErrorMessage ($ exception ->getMessage ());
5583 return $ resultRedirect ->setPath ('admin ' );
5684 }
57- $ collection = $ this ->_objectManager ->get (\Magento \User \Model \ResourceModel \User \Collection::class);
5885 /** @var $collection \Magento\User\Model\ResourceModel\User\Collection */
86+ $ collection = $ this ->userCollectionFactory ->create ();
5987 $ collection ->addFieldToFilter ('email ' , $ email );
6088 $ collection ->load (false );
6189
@@ -65,9 +93,7 @@ public function execute()
6593 /** @var \Magento\User\Model\User $user */
6694 $ user = $ this ->_userFactory ->create ()->load ($ item ->getId ());
6795 if ($ user ->getId ()) {
68- $ newPassResetToken = $ this ->_objectManager ->get (
69- \Magento \User \Helper \Data::class
70- )->generateResetPasswordLinkToken ();
96+ $ newPassResetToken = $ this ->backendDataHelper ->generateResetPasswordLinkToken ();
7197 $ user ->changeResetPasswordLinkToken ($ newPassResetToken );
7298 $ user ->save ();
7399 $ user ->sendPasswordResetConfirmationEmail ();
@@ -86,7 +112,7 @@ public function execute()
86112 $ this ->messageManager ->addSuccess (__ ('We \'ll email you a link to reset your password. ' ));
87113 // @codingStandardsIgnoreEnd
88114 $ this ->getResponse ()->setRedirect (
89- $ this ->_objectManager -> get (\ Magento \ Backend \ Helper \Data::class) ->getHomePageUrl ()
115+ $ this ->backendDataHelper ->getHomePageUrl ()
90116 );
91117 return ;
92118 } else {
0 commit comments