7
7
namespace Magento \User \Controller \Adminhtml \Auth ;
8
8
9
9
use 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 ;
10
19
11
- class Forgotpassword extends \ Magento \ User \ Controller \ Adminhtml \ Auth
20
+ class Forgotpassword extends Auth
12
21
{
13
22
/**
14
23
* @var SecurityManager
15
24
*/
16
25
protected $ securityManager ;
17
26
18
27
/**
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
22
44
*/
23
45
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
27
51
) {
28
52
parent ::__construct ($ context , $ userFactory );
29
53
$ this ->securityManager = $ securityManager ;
54
+ $ this ->userCollectionFactory = $ userCollectionFactory ?:
55
+ ObjectManager::getInstance ()->get (CollectionFactory::class);
56
+ $ this ->backendDataHelper = $ backendDataHelper ?:
57
+ ObjectManager::getInstance ()->get (Data::class);
30
58
}
31
59
32
60
/**
@@ -44,18 +72,18 @@ public function execute()
44
72
$ resultRedirect = $ this ->resultRedirectFactory ->create ();
45
73
if (!empty ($ email ) && !empty ($ params )) {
46
74
// 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)) {
48
76
try {
49
77
$ this ->securityManager ->performSecurityCheck (
50
- \ Magento \ Security \ Model \ PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST ,
78
+ PasswordResetRequestEvent::ADMIN_PASSWORD_RESET_REQUEST ,
51
79
$ email
52
80
);
53
- } catch (\ Magento \ Framework \ Exception \ SecurityViolationException $ exception ) {
81
+ } catch (SecurityViolationException $ exception ) {
54
82
$ this ->messageManager ->addErrorMessage ($ exception ->getMessage ());
55
83
return $ resultRedirect ->setPath ('admin ' );
56
84
}
57
- $ collection = $ this ->_objectManager ->get (\Magento \User \Model \ResourceModel \User \Collection::class);
58
85
/** @var $collection \Magento\User\Model\ResourceModel\User\Collection */
86
+ $ collection = $ this ->userCollectionFactory ->create ();
59
87
$ collection ->addFieldToFilter ('email ' , $ email );
60
88
$ collection ->load (false );
61
89
@@ -65,9 +93,7 @@ public function execute()
65
93
/** @var \Magento\User\Model\User $user */
66
94
$ user = $ this ->_userFactory ->create ()->load ($ item ->getId ());
67
95
if ($ user ->getId ()) {
68
- $ newPassResetToken = $ this ->_objectManager ->get (
69
- \Magento \User \Helper \Data::class
70
- )->generateResetPasswordLinkToken ();
96
+ $ newPassResetToken = $ this ->backendDataHelper ->generateResetPasswordLinkToken ();
71
97
$ user ->changeResetPasswordLinkToken ($ newPassResetToken );
72
98
$ user ->save ();
73
99
$ user ->sendPasswordResetConfirmationEmail ();
@@ -86,7 +112,7 @@ public function execute()
86
112
$ this ->messageManager ->addSuccess (__ ('We \'ll email you a link to reset your password. ' ));
87
113
// @codingStandardsIgnoreEnd
88
114
$ this ->getResponse ()->setRedirect (
89
- $ this ->_objectManager -> get (\ Magento \ Backend \ Helper \Data::class) ->getHomePageUrl ()
115
+ $ this ->backendDataHelper ->getHomePageUrl ()
90
116
);
91
117
return ;
92
118
} else {
0 commit comments