19
19
use Psr \Log \LoggerInterface ;
20
20
use Magento \LoginAsCustomer \Api \GetAuthenticationDataBySecretInterface ;
21
21
use Magento \LoginAsCustomer \Api \AuthenticateCustomerInterface ;
22
- use Magento \LoginAsCustomer \Api \DeleteSecretInterface ;
22
+ use Magento \LoginAsCustomer \Api \DeleteAuthenticationDataBySecretInterface ;
23
23
24
24
/**
25
25
* Login As Customer storefront login action
@@ -52,9 +52,9 @@ class Index implements HttpGetActionInterface
52
52
private $ authenticateCustomer ;
53
53
54
54
/**
55
- * @var DeleteSecretInterface
55
+ * @var DeleteAuthenticationDataBySecretInterface
56
56
*/
57
- private $ deleteSecretProcessor ;
57
+ private $ deleteAuthenticationDataBySecret ;
58
58
59
59
/**
60
60
* @var ManagerInterface
@@ -72,7 +72,7 @@ class Index implements HttpGetActionInterface
72
72
* @param CustomerRepositoryInterface $customerRepository
73
73
* @param GetAuthenticationDataBySecretInterface $getAuthenticateDataProcessor
74
74
* @param AuthenticateCustomerInterface $authenticateCustomerProcessor
75
- * @param DeleteSecretInterface $deleteSecretProcessor
75
+ * @param DeleteAuthenticationDataBySecretInterface $deleteSecretProcessor
76
76
* @param ManagerInterface $messageManager
77
77
* @param LoggerInterface $logger
78
78
*/
@@ -82,7 +82,7 @@ public function __construct(
82
82
CustomerRepositoryInterface $ customerRepository ,
83
83
GetAuthenticationDataBySecretInterface $ getAuthenticateDataProcessor ,
84
84
AuthenticateCustomerInterface $ authenticateCustomerProcessor ,
85
- DeleteSecretInterface $ deleteSecretProcessor ,
85
+ DeleteAuthenticationDataBySecretInterface $ deleteSecretProcessor ,
86
86
ManagerInterface $ messageManager ,
87
87
LoggerInterface $ logger
88
88
) {
@@ -91,7 +91,7 @@ public function __construct(
91
91
$ this ->customerRepository = $ customerRepository ;
92
92
$ this ->getAuthenticationDataBySecret = $ getAuthenticateDataProcessor ;
93
93
$ this ->authenticateCustomer = $ authenticateCustomerProcessor ;
94
- $ this ->deleteSecretProcessor = $ deleteSecretProcessor ;
94
+ $ this ->deleteAuthenticationDataBySecret = $ deleteSecretProcessor ;
95
95
$ this ->messageManager = $ messageManager ;
96
96
$ this ->logger = $ logger ;
97
97
}
@@ -108,30 +108,21 @@ public function execute(): ResultInterface
108
108
109
109
try {
110
110
$ secret = $ this ->request ->getParam ('secret ' );
111
- if (! $ secret || !is_string ($ secret )) {
111
+ if (empty ( $ secret) || !is_string ($ secret )) {
112
112
throw new LocalizedException (__ ('Cannot login to account. No secret key provided. ' ));
113
113
}
114
114
115
115
$ authenticateData = $ this ->getAuthenticationDataBySecret ->execute ($ secret );
116
116
117
- $ this ->deleteSecretProcessor ->execute ($ secret );
117
+ $ this ->deleteAuthenticationDataBySecret ->execute ($ secret );
118
118
119
119
try {
120
120
$ customer = $ this ->customerRepository ->getById ($ authenticateData ->getCustomerId ());
121
121
} catch (NoSuchEntityException $ e ) {
122
122
throw new LocalizedException (__ ('Customer are no longer exist. ' ));
123
123
}
124
124
125
- $ loggedIn = $ this ->authenticateCustomer ->execute (
126
- $ authenticateData ->getCustomerId (),
127
- $ authenticateData ->getAdminId ()
128
- );
129
-
130
-
131
- if (!$ loggedIn ) {
132
- throw new LocalizedException (__ ('Login was not successful. ' ));
133
- }
134
-
125
+ $ this ->authenticateCustomer ->execute ($ authenticateData );
135
126
136
127
$ this ->messageManager ->addSuccessMessage (
137
128
__ ('You are logged in as customer: %1 ' , $ customer ->getFirstname () . ' ' . $ customer ->getLastname ())
0 commit comments