7
7
8
8
namespace Magento \TwoFactorAuth \Block ;
9
9
10
+ use Magento \Authorization \Model \UserContextInterface ;
10
11
use Magento \Backend \Block \Template ;
11
12
use Magento \Backend \Model \Auth \Session ;
12
- use Magento \TwoFactorAuth \Api \TfaSessionInterface ;
13
- use Magento \User \Model \User ;
14
13
use Magento \TwoFactorAuth \Api \TfaInterface ;
15
14
use Magento \TwoFactorAuth \Api \ProviderInterface ;
16
15
@@ -24,6 +23,11 @@ class ChangeProvider extends Template
24
23
*/
25
24
private $ tfa ;
26
25
26
+ /**
27
+ * @var UserContextInterface
28
+ */
29
+ private $ userContext ;
30
+
27
31
/**
28
32
* @var Session
29
33
*/
@@ -33,27 +37,29 @@ class ChangeProvider extends Template
33
37
* ChangeProvider constructor.
34
38
* @param Template\Context $context
35
39
* @param Session $session
40
+ * @param UserContextInterface $userContext
36
41
* @param TfaInterface $tfa
37
42
* @param array $data
38
43
*/
39
44
public function __construct (
40
45
Template \Context $ context ,
41
46
Session $ session ,
47
+ UserContextInterface $ userContext ,
42
48
TfaInterface $ tfa ,
43
49
array $ data = []
44
50
) {
45
51
parent ::__construct ($ context , $ data );
46
52
$ this ->tfa = $ tfa ;
47
53
$ this ->session = $ session ;
54
+ $ this ->userContext = $ userContext ;
48
55
}
49
56
50
57
/**
51
58
* @inheritDoc
52
59
*/
53
60
protected function _toHtml ()
54
61
{
55
- $ userId = (int )$ this ->session ->getUser ()->getId ();
56
- $ toActivate = $ this ->tfa ->getProvidersToActivate ($ userId );
62
+ $ toActivate = $ this ->tfa ->getProvidersToActivate ($ this ->userContext ->getUserId ());
57
63
58
64
foreach ($ toActivate as $ toActivateProvider ) {
59
65
if ($ toActivateProvider ->getCode () === $ this ->getData ('provider ' )) {
@@ -71,7 +77,7 @@ public function getJsLayout()
71
77
{
72
78
$ providers = [];
73
79
foreach ($ this ->getProvidersList () as $ provider ) {
74
- if (!$ provider ->isActive (( int ) $ this ->session -> getUser ()-> getId ())) {
80
+ if (!$ provider ->isActive ($ this ->userContext -> getUserId ())) {
75
81
continue ;
76
82
}
77
83
$ providers [] = [
@@ -89,15 +95,6 @@ public function getJsLayout()
89
95
return parent ::getJsLayout ();
90
96
}
91
97
92
- /**
93
- * Get user
94
- * @return User|null
95
- */
96
- private function getUser (): ?User
97
- {
98
- return $ this ->session ->getUser ();
99
- }
100
-
101
98
/**
102
99
* Get a list of available providers
103
100
* @return ProviderInterface[]
@@ -106,7 +103,7 @@ private function getProvidersList(): array
106
103
{
107
104
$ res = [];
108
105
109
- $ providers = $ this ->tfa ->getUserProviders ((int ) $ this ->getUser ()-> getId ());
106
+ $ providers = $ this ->tfa ->getUserProviders ((int ) $ this ->userContext -> getUserId ());
110
107
foreach ($ providers as $ provider ) {
111
108
if ($ provider ->getCode () !== $ this ->getData ('provider ' )) {
112
109
$ res [] = $ provider ;
0 commit comments