10
10
use Magento \Customer \Api \GroupManagementInterface ;
11
11
use Magento \Customer \Model \Config \Share ;
12
12
use Magento \Customer \Model \ResourceModel \Customer as ResourceCustomer ;
13
+ use Magento \Framework \App \ObjectManager ;
13
14
14
15
/**
15
16
* Customer session model
16
17
*
17
18
* @api
18
19
* @method string getNoReferer()
19
20
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
21
+ * @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
20
22
* @since 100.0.2
21
23
*/
22
24
class Session extends \Magento \Framework \Session \SessionManager
@@ -107,6 +109,8 @@ class Session extends \Magento\Framework\Session\SessionManager
107
109
protected $ response ;
108
110
109
111
/**
112
+ * Session constructor.
113
+ *
110
114
* @param \Magento\Framework\App\Request\Http $request
111
115
* @param \Magento\Framework\Session\SidResolverInterface $sidResolver
112
116
* @param \Magento\Framework\Session\Config\ConfigInterface $sessionConfig
@@ -118,7 +122,7 @@ class Session extends \Magento\Framework\Session\SessionManager
118
122
* @param \Magento\Framework\App\State $appState
119
123
* @param Share $configShare
120
124
* @param \Magento\Framework\Url\Helper\Data $coreUrl
121
- * @param \Magento\Customer\Model\ Url $customerUrl
125
+ * @param Url $customerUrl
122
126
* @param ResourceCustomer $customerResource
123
127
* @param CustomerFactory $customerFactory
124
128
* @param \Magento\Framework\UrlFactory $urlFactory
@@ -128,6 +132,7 @@ class Session extends \Magento\Framework\Session\SessionManager
128
132
* @param CustomerRepositoryInterface $customerRepository
129
133
* @param GroupManagementInterface $groupManagement
130
134
* @param \Magento\Framework\App\Response\Http $response
135
+ * @param AccountConfirmation $accountConfirmation
131
136
* @throws \Magento\Framework\Exception\SessionException
132
137
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
133
138
*/
@@ -152,18 +157,20 @@ public function __construct(
152
157
\Magento \Framework \App \Http \Context $ httpContext ,
153
158
CustomerRepositoryInterface $ customerRepository ,
154
159
GroupManagementInterface $ groupManagement ,
155
- \Magento \Framework \App \Response \Http $ response
160
+ \Magento \Framework \App \Response \Http $ response ,
161
+ AccountConfirmation $ accountConfirmation = null
156
162
) {
157
- $ this ->_coreUrl = $ coreUrl ;
158
- $ this ->_customerUrl = $ customerUrl ;
159
163
$ this ->_configShare = $ configShare ;
164
+ $ this ->_coreUrl = $ coreUrl ;
160
165
$ this ->_customerResource = $ customerResource ;
166
+ $ this ->_customerUrl = $ customerUrl ;
161
167
$ this ->_customerFactory = $ customerFactory ;
162
- $ this ->_urlFactory = $ urlFactory ;
163
- $ this ->_session = $ session ;
164
- $ this ->customerRepository = $ customerRepository ;
165
168
$ this ->_eventManager = $ eventManager ;
166
169
$ this ->_httpContext = $ httpContext ;
170
+ $ this ->_session = $ session ;
171
+ $ this ->_urlFactory = $ urlFactory ;
172
+ $ this ->customerRepository = $ customerRepository ;
173
+
167
174
parent ::__construct (
168
175
$ request ,
169
176
$ sidResolver ,
@@ -175,9 +182,11 @@ public function __construct(
175
182
$ cookieMetadataFactory ,
176
183
$ appState
177
184
);
185
+ $ this ->_eventManager ->dispatch ('customer_session_init ' , ['customer_session ' => $ this ]);
186
+ $ this ->accountConfirmation = $ accountConfirmation ?: ObjectManager::getInstance ()
187
+ ->get (AccountConfirmation::class);
178
188
$ this ->groupManagement = $ groupManagement ;
179
189
$ this ->response = $ response ;
180
- $ this ->_eventManager ->dispatch ('customer_session_init ' , ['customer_session ' => $ this ]);
181
190
}
182
191
183
192
/**
@@ -216,6 +225,8 @@ public function setCustomerData(CustomerData $customer)
216
225
* Retrieve customer model object
217
226
*
218
227
* @return CustomerData
228
+ * @throws \Magento\Framework\Exception\LocalizedException
229
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
219
230
*/
220
231
public function getCustomerData ()
221
232
{
@@ -266,7 +277,12 @@ public function setCustomer(Customer $customerModel)
266
277
\Magento \Customer \Model \Group::NOT_LOGGED_IN_ID
267
278
);
268
279
$ this ->setCustomerId ($ customerModel ->getId ());
269
- if (!$ customerModel ->isConfirmationRequired () && $ customerModel ->getConfirmation ()) {
280
+ $ accountConfirmationRequired = $ this ->accountConfirmation ->isConfirmationRequired (
281
+ $ customerModel ->getWebsiteId (),
282
+ $ customerModel ->getId (),
283
+ $ customerModel ->getEmail ()
284
+ );
285
+ if (!$ accountConfirmationRequired && $ customerModel ->getConfirmation ()) {
270
286
$ customerModel ->setConfirmation (null )->save ();
271
287
}
272
288
@@ -354,10 +370,11 @@ public function setCustomerGroupId($id)
354
370
}
355
371
356
372
/**
357
- * Get customer group id
358
- * If customer is not logged in system, 'not logged in' group id will be returned
373
+ * Get customer group id. If customer is not logged in system, 'not logged in' group id will be returned.
359
374
*
360
- * @return int
375
+ * @return int|null
376
+ * @throws \Magento\Framework\Exception\LocalizedException
377
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
361
378
*/
362
379
public function getCustomerGroupId ()
363
380
{
@@ -407,6 +424,8 @@ public function checkCustomerId($customerId)
407
424
}
408
425
409
426
/**
427
+ * Sets customer as logged in
428
+ *
410
429
* @param Customer $customer
411
430
* @return $this
412
431
*/
@@ -420,6 +439,8 @@ public function setCustomerAsLoggedIn($customer)
420
439
}
421
440
422
441
/**
442
+ * Sets customer data as logged in
443
+ *
423
444
* @param CustomerData $customer
424
445
* @return $this
425
446
*/
@@ -521,6 +542,8 @@ protected function _setAuthUrl($key, $url)
521
542
* Logout without dispatching event
522
543
*
523
544
* @return $this
545
+ * @throws \Magento\Framework\Exception\LocalizedException
546
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
524
547
*/
525
548
protected function _logout ()
526
549
{
@@ -567,6 +590,8 @@ public function regenerateId()
567
590
}
568
591
569
592
/**
593
+ * Creates URL factory
594
+ *
570
595
* @return \Magento\Framework\UrlInterface
571
596
*/
572
597
protected function _createUrl ()
0 commit comments