Skip to content

Commit 79a4111

Browse files
authored
Merge pull request #219 from Hlavtox/fix-sha
Fix sha1 deprecation
2 parents 6070d75 + 5a0915f commit 79a4111

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

psgdpr.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -737,31 +737,41 @@ public function hookDisplayGDPRConsent(array $params): string
737737
/** @var ConsentRepository $consentRepository */
738738
$consentRepository = $this->get('PrestaShop\Module\Psgdpr\Repository\ConsentRepository');
739739

740+
// If no information about a module requesting a consent checkbox was passed, nothing to do
740741
if (!isset($params['id_module'])) {
741742
return '';
742743
}
743744

744745
$moduleId = (int) $params['id_module'];
745746

747+
// If this module does not have a consent activated, nothing to do
746748
if (false === $consentRepository->findModuleConsentIsActive($moduleId)) {
747749
return '';
748750
}
749751

750752
$message = $consentRepository->findModuleConsentMessage($moduleId, $this->context->language->id);
751753
$url = $this->context->link->getModuleLink($this->name, 'FrontAjaxGdpr', [], true);
752754

753-
$customerId = $this->context->customer->id;
755+
/*
756+
* Prepare customer data. The tokens will be used to reverse validate the data in the AJAX request.
757+
* customer_token is used when the customer is logged in, guest_token when not. Even if both customer
758+
* and guest IDs are empty, we can still mark the consent by using the IP address.
759+
*/
754760
$guestId = 0;
755-
756-
if ($customerId == null) {
761+
$customerId = 0;
762+
$secureKey = '';
763+
if (!empty($this->context->customer->id)) {
764+
$customerId = $this->context->customer->id;
765+
$secureKey = $this->context->customer->secure_key;
766+
}
767+
if (!empty($this->context->cart->id_guest)) {
757768
$guestId = $this->context->cart->id_guest;
758-
$customerId = 0;
759769
}
760770

761771
$this->context->smarty->assign([
762772
'psgdpr_id_guest' => $guestId,
763773
'psgdpr_id_customer' => $customerId,
764-
'psgdpr_customer_token' => sha1($this->context->customer->secure_key),
774+
'psgdpr_customer_token' => sha1($secureKey),
765775
'psgdpr_guest_token' => sha1('psgdpr' . $guestId . $_SERVER['REMOTE_ADDR'] . date('Y-m-d')),
766776
'psgdpr_id_module' => $moduleId,
767777
'psgdpr_consent_message' => $message,

0 commit comments

Comments
 (0)