Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,85 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account;
use DateTime;
use PrestaShop\Module\PsAccounts\Http\Resource\Resource;
use PrestaShop\Module\PsAccounts\Service\Accounts\Resource\ShopStatus;
class CachedShopStatus extends Resource
{
/**
* @var ShopStatus
*/
public $shopStatus;
/**
* @var bool
*/
public $isValid = false;
/**
* @var DateTime|null
*/
public $updatedAt;
// /**
// * @var string[]
// */
// protected $required = [
// 'shopStatus',
// ];
public function __construct($values = [])
{
$this->castDateTime($values, [
'updatedAt',
]);
$this->castBool($values, [
'isValid',
]);
$this->castChildResource($values, ShopStatus::class, [
'shopStatus',
]);
parent::__construct($values);
}
/**
* @param bool $all
*
* @return array
*/
public function toArray($all = true)
{
$array = parent::toArray($all);
$this->uncastChildResource($array, ShopStatus::class, [
'shopStatus',
], $all);
$this->uncastDateTime($array, [
'updatedAt',
]);
return $array;
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
class CleanupIdentityCommand
{
/**
* @var int|null
*/
public $shopId;
/**
* @param int|null $shopId
*/
public function __construct($shopId = null)
{
$this->shopId = $shopId ?: \Shop::getContextShopID(true);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
use PrestaShop\Module\PsAccounts\Traits\WithOriginAndSourceTrait;
class CreateIdentitiesCommand
{
use withOriginAndSourceTrait;
public function __construct()
{
$this->resetProperties();
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
use PrestaShop\Module\PsAccounts\Traits\WithOriginAndSourceTrait;
class CreateIdentityCommand
{
use WithOriginAndSourceTrait;
/**
* @var int|null
*/
public $shopId;
/**
* @var bool
*/
public $renew;
/**
* @param int|null $shopId
* @param bool $renew
*/
public function __construct($shopId, $renew = false
) {
$this->shopId = $shopId;
$this->renew = $renew;
$this->resetProperties();
}
}

View File

@@ -0,0 +1,53 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\AccessToken;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\UserInfo;
use PrestaShop\Module\PsAccounts\Traits\WithOriginAndSourceTrait;
class IdentifyContactCommand
{
use WithOriginAndSourceTrait;
/**
* @var AccessToken
*/
public $accessToken;
/**
* @var UserInfo
*/
public $userInfo;
/**
* @param AccessToken $accessToken
* @param UserInfo $userInfo
*/
public function __construct($accessToken, $userInfo)
{
$this->accessToken = $accessToken;
$this->userInfo = $userInfo;
$this->resetProperties();
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
use PrestaShop\Module\PsAccounts\Traits\WithOriginAndSourceTrait;
class MigrateOrCreateIdentitiesV8Command
{
use WithOriginAndSourceTrait;
public function __construct()
{
$this->resetProperties();
}
}

View File

@@ -0,0 +1,44 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
use PrestaShop\Module\PsAccounts\Traits\WithOriginAndSourceTrait;
class MigrateOrCreateIdentityV8Command
{
use WithOriginAndSourceTrait;
/**
* @var int|null
*/
public $shopId;
/**
* @param int|null $shopId
*/
public function __construct($shopId)
{
$this->shopId = $shopId;
$this->resetProperties();
}
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
use PrestaShop\Module\PsAccounts\Traits\WithOriginAndSourceTrait;
class RestoreIdentityCommand
{
use WithOriginAndSourceTrait;
/**
* @var int|null
*/
public $shopId;
/**
* @var string
*/
public $cloudShopId;
/**
* @var string
*/
public $clientId;
/**
* @var string
*/
public $clientSecret;
/**
* @var bool
*/
public $verify;
/**
* @var bool
*/
public $migrate;
/**
* @var string|null
*/
public $migrateFrom;
/**
* @param string $cloudShopId
* @param string $clientId
* @param string $clientSecret
* @param bool $verify
* @param bool $migrate
* @param string $migrateFrom
*/
public function __construct(
$cloudShopId,
$clientId,
$clientSecret,
$verify = false,
$migrate = false,
$migrateFrom = null
) {
$this->cloudShopId = $cloudShopId;
$this->clientId = $clientId;
$this->clientSecret = $clientSecret;
$this->verify = $verify;
$this->migrate = $migrate;
$this->migrateFrom = $migrateFrom;
$this->resetProperties();
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
class UpdateBackOfficeUrlCommand
{
/**
* @var int
*/
public $shopId;
/**
* @param int $shopId
*/
public function __construct($shopId)
{
$this->shopId = $shopId;
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
class UpdateBackOfficeUrlsCommand
{
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
use PrestaShop\Module\PsAccounts\Traits\WithOriginAndSourceTrait;
class VerifyIdentitiesCommand
{
use WithOriginAndSourceTrait;
public function __construct()
{
$this->resetProperties();
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Command;
use PrestaShop\Module\PsAccounts\Traits\WithOriginAndSourceTrait;
class VerifyIdentityCommand
{
use WithOriginAndSourceTrait;
/**
* @var int|null
*/
public $shopId;
/**
* @var bool
*/
public $force;
/**
* @param int|null $shopId
* @param bool $force
*/
public function __construct($shopId, $force = false)
{
$this->shopId = $shopId;
$this->force = $force;
$this->resetProperties();
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,42 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use PrestaShop\Module\PsAccounts\Account\Command\CleanupIdentityCommand;
class CleanupIdentityHandler
{
/**
* @param CleanupIdentityCommand $command
*
* @return void
*/
public function handle(CleanupIdentityCommand $command)
{
$id_shop = $command->shopId;
\Db::getInstance()->execute(
'DELETE FROM `' . _DB_PREFIX_ . bqSQL('configuration') . '`'
. ' WHERE (name like \'PS_ACCOUNTS%\' or name = \'PSX_UUID_V4\' or name = \'PS_CHECKOUT_SHOP_UUID_V4\')'
. ' AND ' . ($id_shop ? 'id_shop = ' . (int) $id_shop : 'id_shop IS NULL')
);
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use PrestaShop\Module\PsAccounts\Account\Command\CreateIdentitiesCommand;
use PrestaShop\Module\PsAccounts\Account\Command\CreateIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
class CreateIdentitiesHandler extends MultiShopHandler
{
/**
* @param CreateIdentitiesCommand $command
*
* @return void
*/
public function handle(CreateIdentitiesCommand $command)
{
$this->handleMulti(function ($multiShopId) use ($command) {
try {
$this->commandBus->handle(
(new CreateIdentityCommand($multiShopId, false))
->withOrigin($command->origin)
->withSource($command->source)
);
} catch (RefreshTokenException $e) {
Logger::getInstance()->error($e->getMessage());
} catch (AccountsException $e) {
Logger::getInstance()->error($e->getMessage());
}
});
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use PrestaShop\Module\PsAccounts\Account\Command\CreateIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Command\VerifyIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Client;
class CreateIdentityHandler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var OAuth2Client
*/
private $oAuth2Client;
/**
* @var ShopProvider
*/
private $shopProvider;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var CommandBus
*/
private $commandBus;
/**
* @param AccountsService $accountsService
* @param ShopProvider $shopProvider
* @param OAuth2Client $oauth2Client
* @param StatusManager $shopStatus
* @param CommandBus $commandBus
*/
public function __construct(
AccountsService $accountsService,
ShopProvider $shopProvider,
OAuth2Client $oauth2Client,
StatusManager $shopStatus,
CommandBus $commandBus
) {
$this->accountsService = $accountsService;
$this->shopProvider = $shopProvider;
$this->oAuth2Client = $oauth2Client;
$this->statusManager = $shopStatus;
$this->commandBus = $commandBus;
}
/**
* @param CreateIdentityCommand $command
*
* @return void
*
* @throws RefreshTokenException
* @throws UnknownStatusException
* @throws AccountsException
*/
public function handle(CreateIdentityCommand $command)
{
if ($command->renew || !$this->isAlreadyCreated()) {
$shopId = $command->shopId;
$identityCreated = $this->accountsService
->withSource($command->source)
->withOrigin($command->origin)
->createShopIdentity(
$this->shopProvider->getUrl($shopId),
$this->shopProvider->getName($shopId)
);
$this->oAuth2Client->update(
$identityCreated->clientId,
$identityCreated->clientSecret
);
$this->statusManager->setCloudShopId($identityCreated->cloudShopId);
$this->statusManager->setIsVerified(false);
$this->statusManager->invalidateCache();
$this->commandBus->handle(
(new VerifyIdentityCommand($shopId, true))
->withOrigin($command->origin)
->withSource($command->source)
);
} else {
$this->commandBus->handle(
(new VerifyIdentityCommand($command->shopId))
->withOrigin($command->origin)
->withSource($command->source)
);
}
}
/**
* Idempotency check
*
* @return bool
*/
private function isAlreadyCreated()
{
// FIXME: define where this code belongs
return $this->oAuth2Client->exists() && $this->statusManager->identityCreated();
}
}

View File

@@ -0,0 +1,99 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use PrestaShop\Module\PsAccounts\Account\Command\IdentifyContactCommand;
use PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession;
use PrestaShop\Module\PsAccounts\Account\Session\ShopSession;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
class IdentifyContactHandler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var ShopSession
*/
private $shopSession;
/**
* @var OwnerSession
*/
private $ownerSession;
/**
* @param AccountsService $accountsService
* @param StatusManager $statusManager
* @param ShopSession $shopSession
* @param OwnerSession $ownerSession
*/
public function __construct(
AccountsService $accountsService,
StatusManager $statusManager,
ShopSession $shopSession,
OwnerSession $ownerSession
) {
$this->accountsService = $accountsService;
$this->statusManager = $statusManager;
$this->shopSession = $shopSession;
$this->ownerSession = $ownerSession;
}
/**
* @param IdentifyContactCommand $command
*
* @return void
*
* @throws AccountsException
*/
public function handle(IdentifyContactCommand $command)
{
$status = $this->statusManager->withSource($command->source)->getStatus();
if (!$status->isVerified) {
return;
}
$this->accountsService
->withSource($command->source)
->setPointOfContact(
$this->statusManager->getCloudShopId(),
$this->shopSession->getValidToken(),
$command->accessToken->access_token
);
// cleanup user token
$this->ownerSession->cleanup();
// optimistic update cached status
$this->statusManager->setPointOfContactUuid($command->userInfo->sub);
$this->statusManager->setPointOfContactEmail($command->userInfo->email);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use Exception;
use PrestaShop\Module\PsAccounts\Account\Command\MigrateOrCreateIdentitiesV8Command;
use PrestaShop\Module\PsAccounts\Account\Command\MigrateOrCreateIdentityV8Command;
use PrestaShop\Module\PsAccounts\Log\Logger;
class MigrateOrCreateIdentitiesV8Handler extends MultiShopHandler
{
/**
* @param MigrateOrCreateIdentitiesV8Command $command
*
* @return void
*/
public function handle(MigrateOrCreateIdentitiesV8Command $command)
{
$this->handleMulti(function ($multiShopId) use ($command) {
try {
$this->commandBus->handle(
(new MigrateOrCreateIdentityV8Command($multiShopId))
->withOrigin($command->origin)
->withSource($command->source)
);
} catch (Exception $e) {
Logger::getInstance()->error($e->getMessage());
}
});
}
}

View File

@@ -0,0 +1,274 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use InvalidArgumentException;
use PrestaShop\Module\PsAccounts\Account\Command\CreateIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Command\MigrateOrCreateIdentityV8Command;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Account\ProofManager;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
use PrestaShop\Module\PsAccounts\Service\Accounts\Exception\StoreLegacyNotFoundException;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Exception;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Service;
use PrestaShop\Module\PsAccounts\Service\UpgradeService;
class MigrateOrCreateIdentityV8Handler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var OAuth2Service
*/
protected $oAuth2Service;
/**
* @var ShopProvider
*/
private $shopProvider;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var ProofManager
*/
protected $proofManager;
/**
* @var ConfigurationRepository
*/
private $configurationRepository;
/**
* @var CommandBus
*/
private $commandBus;
/**
* @var UpgradeService
*/
private $upgradeService;
/**
* @param AccountsService $accountsService
* @param OAuth2Service $oAuth2Service
* @param ShopProvider $shopProvider
* @param StatusManager $shopStatus
* @param ProofManager $proofManager
* @param ConfigurationRepository $configurationRepository
* @param CommandBus $commandBus
* @param UpgradeService $upgradeService
*/
public function __construct(
AccountsService $accountsService,
OAuth2Service $oAuth2Service,
ShopProvider $shopProvider,
StatusManager $shopStatus,
ProofManager $proofManager,
ConfigurationRepository $configurationRepository,
CommandBus $commandBus,
UpgradeService $upgradeService
) {
$this->accountsService = $accountsService;
$this->oAuth2Service = $oAuth2Service;
$this->shopProvider = $shopProvider;
$this->statusManager = $shopStatus;
$this->proofManager = $proofManager;
$this->configurationRepository = $configurationRepository;
$this->commandBus = $commandBus;
$this->upgradeService = $upgradeService;
}
/**
* @param MigrateOrCreateIdentityV8Command $command
*
* @return void
*
* @throws AccountsException
* @throws RefreshTokenException
* @throws UnknownStatusException
*/
public function handle(MigrateOrCreateIdentityV8Command $command)
{
$shopId = $command->shopId;
$shopUuid = $this->configurationRepository->getShopUuid();
// FIXME: command can hold that property depending on context
$fromVersion = $this->upgradeService->getRegisteredVersion();
$migratedToV8 = version_compare($fromVersion, '8', '>=');
$notIdentified = !$shopUuid;
// FIXME: shouldn't this condition be a specific flag
if ($notIdentified || $migratedToV8) {
$this->registerLatestVersion();
$this->createOrVerifyIdentity($command);
return;
}
try {
// Register cloudShopId locally
$this->statusManager->setCloudShopId($shopUuid);
$identityCreated = $this->accountsService
->withSource($command->source)
->migrateShopIdentity(
$shopUuid,
$this->getTokenV6OrV7($shopUuid),
$this->shopProvider->getUrl($shopId),
$this->shopProvider->getName($shopId),
$fromVersion,
$this->proofManager->generateProof()
);
if (!empty($identityCreated->clientId) &&
!empty($identityCreated->clientSecret)) {
$this->oAuth2Service->getOAuth2Client()->update(
$identityCreated->clientId,
$identityCreated->clientSecret
);
}
$this->clearTokens();
$this->statusManager->invalidateCache();
$this->registerLatestVersion();
} catch (StoreLegacyNotFoundException $e) {
if ($command->origin !== AccountsService::ORIGIN_ADVANCED_SETTINGS) {
$this->registerLatestVersion();
$this->cleanupIdentity();
$this->createOrVerifyIdentity($command);
return;
} else {
throw $e;
}
}
}
/**
* @param string $shopUuid
*
* @return string
*
* @throws OAuth2Exception
*/
private function getAccessTokenV7($shopUuid)
{
return $this->oAuth2Service->getAccessTokenByClientCredentials([], [
// audience v7
'shop_' . $shopUuid,
])->access_token;
}
/**
* @param string $shopUuid
*
* @return string
*
* @throws AccountsException
* @throws InvalidArgumentException
*/
private function getFirebaseTokenV6($shopUuid)
{
return $this->accountsService->refreshShopToken(
$this->configurationRepository->getFirebaseRefreshToken(),
$shopUuid
)->token;
}
/**
* @param string $shopUuid
*
* @return string
*
* @throws AccountsException
*/
private function getTokenV6OrV7($shopUuid)
{
try {
return $this->getAccessTokenV7($shopUuid);
} catch (OAuth2Exception $e) {
return $this->getFirebaseTokenV6($shopUuid);
}
}
/**
* @return void
*/
private function cleanupIdentity()
{
// Will trigger reset banner
//$this->upgradeService->setVersion('');
$this->statusManager->clearStatus();
$this->oAuth2Service->getOAuth2Client()->delete();
$this->clearTokens();
}
/**
* Create Or Verify Or Do Nothing
*
* @param MigrateOrCreateIdentityV8Command $command
*
* @return void
*
* @throws RefreshTokenException
* @throws UnknownStatusException
* @throws AccountsException
*/
private function createOrVerifyIdentity(MigrateOrCreateIdentityV8Command $command)
{
$this->commandBus->handle(
(new CreateIdentityCommand($command->shopId, false))
->withOrigin($command->origin)
->withSource($command->source)
);
}
/**
* @return void
*/
private function clearTokens()
{
$this->configurationRepository->updateAccessToken('');
$this->configurationRepository->updateFirebaseIdAndRefreshTokens('', '');
$this->configurationRepository->updateUserFirebaseIdAndRefreshToken('', '');
}
/**
* @return void
*/
private function registerLatestVersion()
{
$this->upgradeService->setVersion();
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use PrestaShop\Module\PsAccounts\Context\ShopContext;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
abstract class MultiShopHandler
{
/**
* @var ShopContext
*/
protected $shopContext;
/**
* @var CommandBus
*/
protected $commandBus;
public function __construct(
ShopContext $shopContext,
CommandBus $commandBus
) {
$this->shopContext = $shopContext;
$this->commandBus = $commandBus;
}
/**
* @param \Closure $handler
*
* @return void
*/
protected function handleMulti($handler)
{
foreach ($this->getShopIds() as $multiShopId) {
$this->shopContext->execInShopContext($multiShopId, function () use ($handler, $multiShopId) {
$handler($multiShopId);
});
}
}
/**
* @return int[]
*/
protected function getShopIds()
{
if ($this->shopContext->isMultishopActive()) {
return $this->shopContext->getMultiShopIds();
}
//return [\Shop::getContextShopID(true)];
return [\Shop::getContextShopID()];
}
}

View File

@@ -0,0 +1,158 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use Exception;
use PrestaShop\Module\PsAccounts\Account\Command\MigrateOrCreateIdentityV8Command;
use PrestaShop\Module\PsAccounts\Account\Command\RestoreIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Command\VerifyIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Service\Accounts\Resource\ShopStatus;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Client;
use PrestaShop\Module\PsAccounts\Service\UpgradeService;
use Throwable;
class RestoreIdentityHandler
{
/**
* @var OAuth2Client
*/
private $oAuth2Client;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var UpgradeService
*/
private $upgradeService;
/**
* @var CommandBus
*/
private $commandBus;
/**
* @param OAuth2Client $oauth2Client
* @param StatusManager $shopStatus
* @param UpgradeService $upgradeService
* @param CommandBus $commandBus
*/
public function __construct(
OAuth2Client $oauth2Client,
StatusManager $shopStatus,
UpgradeService $upgradeService,
CommandBus $commandBus
) {
$this->oAuth2Client = $oauth2Client;
$this->statusManager = $shopStatus;
$this->upgradeService = $upgradeService;
$this->commandBus = $commandBus;
}
/**
* @param RestoreIdentityCommand $command
*
* @return void
*
* @throws Exception|Throwable
*/
public function handle(RestoreIdentityCommand $command)
{
try {
$currentStatus = $this->statusManager->getStatus(true);
} catch (UnknownStatusException $e) {
$currentStatus = null;
}
$registeredVersion = $this->upgradeService->getRegisteredVersion();
$shopId = $command->shopId ?: \Shop::getContextShopID();
try {
$this->statusManager->clearStatus();
// Update OAuth client
$this->oAuth2Client->update(
$command->clientId,
$command->clientSecret ?: $this->oAuth2Client->getClientSecret()
);
// Update cloudShopId
$this->statusManager->setCloudShopId($command->cloudShopId);
// Fix version number when not set
$this->upgradeService->setVersion();
if ($command->migrate) {
// this will trigger migration
$this->upgradeService->setVersion($command->migrateFrom);
}
$this->commandBus->handle(
// FIXME: $cloudShopId (should not be necessary to read it from db)
(new MigrateOrCreateIdentityV8Command($shopId))
->withOrigin($command->origin)
->withSource($command->source)
);
if ($command->verify) {
// force verify
$this->commandBus->handle(
(new VerifyIdentityCommand($shopId, true))
->withOrigin($command->origin)
->withSource($command->source)
);
}
//$this->statusManager->invalidateCache();
} catch (Exception $e) {
$this->handleError($currentStatus, $registeredVersion, $e);
} catch (Throwable $e) {
$this->handleError($currentStatus, $registeredVersion, $e);
}
}
/**
* @param ShopStatus|null $currentStatus
* @param string $registeredVersion
* @param Exception|Throwable $e
*
* @return void
*
* @throws Exception|Throwable
*/
private function handleError($currentStatus, $registeredVersion, $e)
{
if (isset($currentStatus)) {
$this->statusManager->restoreStatus($currentStatus);
}
$this->upgradeService->setVersion($registeredVersion);
Logger::getInstance()->error($e);
throw $e;
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use PrestaShop\Module\PsAccounts\Account\Command\UpdateBackOfficeUrlCommand;
use PrestaShop\Module\PsAccounts\Account\Session\ShopSession;
use PrestaShop\Module\PsAccounts\Account\ShopUrl;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
class UpdateBackOfficeUrlHandler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var ShopProvider
*/
private $shopProvider;
/**
* @var ShopSession
*/
private $shopSession;
/**
* @var ConfigurationRepository
*/
private $configurationRepository;
/**
* @param AccountsService $accountsService
* @param StatusManager $statusManager
* @param ShopProvider $shopProvider
* @param ShopSession $shopSession
* @param ConfigurationRepository $configurationRepository
*/
public function __construct(
AccountsService $accountsService,
StatusManager $statusManager,
ShopProvider $shopProvider,
ShopSession $shopSession,
ConfigurationRepository $configurationRepository
) {
$this->accountsService = $accountsService;
$this->statusManager = $statusManager;
$this->shopProvider = $shopProvider;
$this->shopSession = $shopSession;
$this->configurationRepository = $configurationRepository;
}
/**
* @param UpdateBackOfficeUrlCommand $command
*
* @return void
*/
public function handle(UpdateBackOfficeUrlCommand $command)
{
// On disconnected context with single shop mode, the contextual shop id is not defined.
$shopId = $command->shopId ?: $this->configurationRepository->getMainShopId();
// TODO: rework parameters priority
$status = $this->statusManager->withSource('ps_accounts')->getStatus();
$cloudShopUrl = ShopUrl::createFromStatus($status, $shopId);
$localShopUrl = $this->shopProvider->getUrl($shopId);
try {
// Check if BO url changed and urls aren't empty
if (!$cloudShopUrl->backOfficeUrlEquals($localShopUrl)) {
$this->accountsService->updateBackOfficeUrl(
$status->cloudShopId,
$this->shopSession->getValidToken(),
$localShopUrl
);
}
} catch (\InvalidArgumentException $e) {
Logger::getInstance()->error($e->getMessage());
}
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use Exception;
use PrestaShop\Module\PsAccounts\Account\Command\UpdateBackOfficeUrlCommand;
use PrestaShop\Module\PsAccounts\Account\Command\UpdateBackOfficeUrlsCommand;
use PrestaShop\Module\PsAccounts\Log\Logger;
use Throwable;
class UpdateBackOfficeUrlsHandler extends MultiShopHandler
{
/**
* @param UpdateBackOfficeUrlsCommand $command
*
* @return void
*/
public function handle(UpdateBackOfficeUrlsCommand $command)
{
$this->handleMulti(function ($multiShopId) {
try {
$updateBackOfficeUrlCommand = new UpdateBackOfficeUrlCommand($multiShopId);
$this->commandBus->handle($updateBackOfficeUrlCommand);
} catch (Exception $e) {
Logger::getInstance()->error($e->getMessage());
} catch (Throwable $e) {
Logger::getInstance()->error($e->getMessage());
}
});
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use PrestaShop\Module\PsAccounts\Account\Command\VerifyIdentitiesCommand;
use PrestaShop\Module\PsAccounts\Account\Command\VerifyIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
class VerifyIdentitiesHandler extends MultiShopHandler
{
/**
* @param VerifyIdentitiesCommand $command
*
* @return void
*/
public function handle(VerifyIdentitiesCommand $command)
{
$this->handleMulti(function ($multiShopId) use ($command) {
try {
$this->commandBus->handle(
(new VerifyIdentityCommand($multiShopId, false))
->withOrigin($command->origin)
->withSource($command->source)
);
} catch (RefreshTokenException $e) {
Logger::getInstance()->error($e->getMessage());
} catch (AccountsException $e) {
Logger::getInstance()->error($e->getMessage());
} catch (UnknownStatusException $e) {
Logger::getInstance()->error($e->getMessage());
}
});
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\CommandHandler;
use PrestaShop\Module\PsAccounts\Account\Command\VerifyIdentityCommand;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Account\ProofManager;
use PrestaShop\Module\PsAccounts\Account\Session\ShopSession;
use PrestaShop\Module\PsAccounts\Account\ShopUrl;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
class VerifyIdentityHandler
{
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var StatusManager
*/
private $statusManager;
/**
* @var ShopProvider
*/
private $shopProvider;
/**
* @var ShopSession
*/
private $shopSession;
/**
* @var ProofManager
*/
private $proofManager;
/**
* @param AccountsService $accountsService
* @param ShopProvider $shopProvider
* @param StatusManager $statusManager
* @param ShopSession $shopSession
* @param ProofManager $proofManager
*/
public function __construct(
AccountsService $accountsService,
ShopProvider $shopProvider,
StatusManager $statusManager,
ShopSession $shopSession,
ProofManager $proofManager
) {
$this->accountsService = $accountsService;
$this->shopProvider = $shopProvider;
$this->statusManager = $statusManager;
$this->shopSession = $shopSession;
$this->proofManager = $proofManager;
}
/**
* @param VerifyIdentityCommand $command
*
* @return void
*
* @throws RefreshTokenException
* @throws UnknownStatusException
* @throws AccountsException
*/
public function handle(VerifyIdentityCommand $command)
{
$shopId = $command->shopId;
$status = $this->statusManager->withSource($command->source)->getStatus();
$cloudShopUrl = ShopUrl::createFromStatus($status, $shopId);
if (!$command->force && $status->isVerified) {
return;
}
try {
if (!$command->force && !$cloudShopUrl->frontendUrlEquals($this->shopProvider->getUrl($shopId))) {
return;
}
} catch (\InvalidArgumentException $e) {
Logger::getInstance()->error($e->getMessage());
return;
}
$this->accountsService
->withOrigin($command->origin)
->withSource($command->source)
->verifyShopIdentity(
$this->statusManager->getCloudShopId(),
$this->shopSession->getValidToken(),
$this->shopProvider->getUrl($shopId),
$this->shopProvider->getName($shopId),
$this->proofManager->generateProof()
);
$this->statusManager->invalidateCache();
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,75 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Dto;
use PrestaShop\Module\PsAccounts\Type\Dto;
class Shop extends Dto
{
/** @var int */
public $id;
/** @var string */
public $name;
/** @var string */
public $domain;
/** @var string */
public $domainSsl;
/** @var string */
public $physicalUri;
/** @var string */
public $virtualUri;
/** @var string */
public $frontUrl;
/** @var string */
public $uuid;
/** @var string */
public $publicKey;
/** @var string */
public $employeeId;
/** @var User */
public $user;
/** @var string */
public $url;
/** @var bool */
public $isLinkedV4;
/** @var bool */
public $unlinkedAuto;
public function __construct($values = [])
{
if (isset($values['user']) && is_array($values['user'])) {
$values['user'] = new User($values['user']);
} else {
$values['user'] = new User();
}
parent::__construct($values);
}
/**
* @return array|mixed
*/
public function jsonSerialize()
{
return array_merge(parent::jsonSerialize(), [
'user' => $this->user->jsonSerialize(),
]);
}
}

View File

@@ -0,0 +1,74 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Dto;
use PrestaShop\Module\PsAccounts\Type\Dto;
class UpdateShop extends Dto
{
/**
* @var string
*/
public $shopId;
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $virtualUri;
/**
* @var string
*/
public $physicalUri;
/**
* @var string
*/
public $domain;
/**
* @var string
*/
public $sslDomain;
/**
* @var string
*/
public $boBaseUrl;
/**
* @var string[]
*/
public $required = [
'shopId',
'name',
'virtualUri',
'physicalUri',
'domain',
'sslDomain',
'boBaseUrl',
];
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Dto;
use PrestaShop\Module\PsAccounts\Type\Dto;
class User extends Dto
{
/** @var string */
public $email;
/** @var bool */
public $emailIsValidated;
/** @var string */
public $uuid;
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Exception;
class RefreshTokenException extends \PrestaShop\Module\PsAccounts\Exception\RefreshTokenException
{
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Exception;
class UnknownStatusException extends \Exception
{
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,70 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
class ProofManager
{
/**
* @var ConfigurationRepository
*/
private $configuration;
/**
* ManageProof constructor.
*
* @param ConfigurationRepository $configuration
*/
public function __construct(
ConfigurationRepository $configuration
) {
$this->configuration = $configuration;
}
/**
* @return string
*/
public function generateProof()
{
$proof = bin2hex(openssl_random_pseudo_bytes(32));
$this->configuration->updateShopProof($proof);
return $proof;
}
/**
* @return string|null
*/
public function getProof()
{
return $this->configuration->getShopProof();
}
/**
* @return void
*/
public function deleteProof()
{
$this->configuration->updateShopProof(null);
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Query;
class GetContextQuery
{
/**
* @var string|null
*/
public $source;
/**
* @var int
*/
public $contextType;
/**
* @var int|null
*/
public $contextId;
/**
* @var bool
*/
public $refresh;
/**
* @param string|null $source
* @param int|null $contextType
* @param int|null $contextId
* @param bool $refresh
*/
public function __construct($source = null, $contextType = \Shop::CONTEXT_ALL, $contextId = null, $refresh = false)
{
$this->source = $source;
$this->contextType = $contextType;
$this->contextId = $contextId;
$this->refresh = $refresh;
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,73 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\QueryHandler;
use PrestaShop\Module\PsAccounts\Account\Query\GetContextQuery;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\UpgradeService;
class GetContextHandler
{
/**
* @var ShopProvider
*/
private $shopProvider;
/**
* @var UpgradeService
*/
private $upgradeService;
/**
* @param ShopProvider $shopProvider
*/
public function __construct(
ShopProvider $shopProvider,
UpgradeService $upgradeService
) {
$this->shopProvider = $shopProvider;
$this->upgradeService = $upgradeService;
}
/**
* @param GetContextQuery $query
*
* @return array
*
* @throws AccountsException
*/
public function handle(GetContextQuery $query)
{
return [
'ps_accounts' => [
'last_succeeded_upgrade_version' => $this->upgradeService->getVersion(),
'module_version_from_files' => \Ps_accounts::VERSION,
],
'groups' => $this->shopProvider->getShops(
$query->source,
$query->contextType,
$query->contextId,
$query->refresh
),
];
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,131 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Session\Firebase;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Session\Firebase;
use PrestaShop\Module\PsAccounts\Account\Session\Session;
use PrestaShop\Module\PsAccounts\Account\Session\SessionInterface;
use PrestaShop\Module\PsAccounts\Account\Session\ShopSession;
use PrestaShop\Module\PsAccounts\Account\Token\Token;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
abstract class FirebaseSession extends Session implements SessionInterface
{
/**
* @var ShopSession
*/
protected $shopSession;
public function __construct(ShopSession $shopSession)
{
parent::__construct();
$this->shopSession = $shopSession;
}
/**
* @return AccountsService
*/
public function getAccountsService()
{
return $this->module->getService(AccountsService::class);
}
/**
* @return Firebase\OwnerSession
*/
public function getOwnerSession()
{
return $this->module->getService(Firebase\OwnerSession::class);
}
/**
* @return Firebase\ShopSession
*/
public function getShopSession()
{
return $this->module->getService(Firebase\ShopSession::class);
}
/**
* @param string $refreshToken
* @param array $scope
* @param array $audience
*
* @return Token
*
* @throws RefreshTokenException
*/
public function refreshToken($refreshToken = null, array $scope = [], array $audience = [])
{
try {
$token = $this->shopSession->getValidToken();
$cloudShopId = $this->getStatusManager()->getCloudShopId();
$this->refreshFirebaseTokens($cloudShopId, $token);
} catch (RefreshTokenException $e) {
Logger::getInstance()->error('Unable to get or refresh owner/shop token : ' . $e->getMessage());
throw $e;
}
return $this->getToken();
}
/**
* @param string $cloudShopId
* @param Token $token
*
* @return void
*
* @throws RefreshTokenException
*/
protected function refreshFirebaseTokens($cloudShopId, $token)
{
try {
$firebaseTokens = $this->getAccountsService()->firebaseTokens($cloudShopId, $token);
} catch (AccountsException $e) {
throw new RefreshTokenException($e->getMessage());
}
$shopToken = new Token(
$firebaseTokens->shop->token,
$firebaseTokens->shop->refreshToken
);
$pointOfContactToken = null;
if (isset($firebaseTokens->pointOfContact->token) && isset($firebaseTokens->pointOfContact->refreshToken)) {
$pointOfContactToken = new Token(
$firebaseTokens->pointOfContact->token,
$firebaseTokens->pointOfContact->refreshToken
);
}
// saving both tokens here
$this->getShopSession()->setToken((string) $shopToken->getJwt(), $shopToken->getRefreshToken());
if (isset($pointOfContactToken)) {
$this->getOwnerSession()->setToken((string) $pointOfContactToken->getJwt(), $pointOfContactToken->getRefreshToken());
}
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Session\Firebase;
use PrestaShop\Module\PsAccounts\Account\Session\SessionInterface;
use PrestaShop\Module\PsAccounts\Account\Token\Token;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
class OwnerSession extends FirebaseSession implements SessionInterface
{
/**
* @var ConfigurationRepository
*/
protected $configurationRepository;
/**
* @param ConfigurationRepository $configurationRepository
* @param \PrestaShop\Module\PsAccounts\Account\Session\ShopSession $shopSession
*/
public function __construct(
ConfigurationRepository $configurationRepository,
\PrestaShop\Module\PsAccounts\Account\Session\ShopSession $shopSession
) {
$this->configurationRepository = $configurationRepository;
parent::__construct($shopSession);
}
/**
* @return Token
*/
public function getToken()
{
return new Token(
$this->configurationRepository->getUserFirebaseIdToken(),
$this->configurationRepository->getUserFirebaseRefreshToken()
);
}
/**
* @return void
*/
public function cleanup()
{
$this->configurationRepository->updateUserFirebaseIdToken('');
}
/**
* @param string $token
* @param string $refreshToken
*
* @return void
*/
public function setToken($token, $refreshToken = null)
{
$this->configurationRepository->updateUserFirebaseIdAndRefreshToken($token, $refreshToken);
}
}

View File

@@ -0,0 +1,76 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Session\Firebase;
use PrestaShop\Module\PsAccounts\Account\Session\SessionInterface;
use PrestaShop\Module\PsAccounts\Account\Token\Token;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
class ShopSession extends FirebaseSession implements SessionInterface
{
/**
* @var ConfigurationRepository
*/
protected $configurationRepository;
/**
* @param ConfigurationRepository $configurationRepository
* @param \PrestaShop\Module\PsAccounts\Account\Session\ShopSession $shopSession
*/
public function __construct(
ConfigurationRepository $configurationRepository,
\PrestaShop\Module\PsAccounts\Account\Session\ShopSession $shopSession
) {
$this->configurationRepository = $configurationRepository;
parent::__construct($shopSession);
}
/**
* @return Token
*/
public function getToken()
{
return new Token(
$this->configurationRepository->getFirebaseIdToken(),
$this->configurationRepository->getFirebaseRefreshToken()
);
}
/**
* @return void
*/
public function cleanup()
{
$this->configurationRepository->updateFirebaseIdAndRefreshTokens('', '');
}
/**
* @param string $token
* @param string $refreshToken
*
* @return void
*/
public function setToken($token, $refreshToken = null)
{
$this->configurationRepository->updateFirebaseIdAndRefreshTokens($token, $refreshToken);
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,161 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Session;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\StatusManager;
use PrestaShop\Module\PsAccounts\Account\Token\NullToken;
use PrestaShop\Module\PsAccounts\Account\Token\Token;
use PrestaShop\Module\PsAccounts\Log\Logger;
abstract class Session implements SessionInterface
{
/**
* @var array
*/
protected $refreshTokenErrors = [];
/**
* @var \Ps_accounts
*/
protected $module;
public function __construct()
{
/* @phpstan-ignore-next-line */
$this->module = \Module::getInstanceByName('ps_accounts');
}
/**
* @deprecated use getValidToken instead
*
* @param bool $forceRefresh
*
* @return Token
*/
public function getOrRefreshToken($forceRefresh = false)
{
return $this->getValidToken($forceRefresh, false);
}
/**
* @param bool $forceRefresh
* @param bool $throw
* @param array $scope
* @param array $audience
*
* @return Token
*
* @throws RefreshTokenException
*/
public function getValidToken($forceRefresh = false, $throw = true, array $scope = [], array $audience = [])
{
/*
* Avoid multiple refreshToken calls in the same runtime:
* if it fails once, it will subsequently fail
*/
if ($e = $this->getRefreshTokenError(static::class)) {
$this->setToken('');
if ($throw) {
throw $e;
}
return $this->getToken();
}
if (true === $forceRefresh || false === $this->getToken()->isValid($scope, $audience)) {
try {
$this->refreshToken(null, $scope, $audience);
} catch (RefreshTokenException $e) {
$this->setToken('');
$this->setRefreshTokenError(static::class, $e);
if ($throw) {
throw $e;
}
Logger::getInstance()->error($e->getMessage());
}
}
return $this->getToken();
}
/**
* @return bool
*
* @deprecated since v8.0.0
*/
public function isEmailVerified()
{
try {
$jwt = $this->getToken()->getJwt();
// FIXME : just query sso api and don't refresh token everytime
if (!$jwt instanceof NullToken &&
!$jwt->claims()->get('email_verified')
) {
$jwt = $this->getValidToken(true)->getJwt();
}
return (bool) $jwt->claims()->get('email_verified');
} catch (RefreshTokenException $e) {
return false;
}
}
/**
* @param string $className
*
* @return RefreshTokenException|false
*/
public function getRefreshTokenError($className)
{
return isset($this->refreshTokenErrors[$className]) ? $this->refreshTokenErrors[$className] : false;
}
/**
* @return void
*/
public function resetRefreshTokenErrors()
{
$this->refreshTokenErrors = [];
}
/**
* @param string $className
* @param RefreshTokenException $e
*
* @return void
*/
protected function setRefreshTokenError($className, RefreshTokenException $e)
{
$this->refreshTokenErrors[$className] = $e;
}
/**
* @return StatusManager
*/
protected function getStatusManager()
{
return $this->module->getService(StatusManager::class);
}
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Session;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Token\Token;
interface SessionInterface
{
/**
* @return Token
*/
public function getToken();
/**
* @param string $token
* @param string $refreshToken
*
* @return void
*/
public function setToken($token, $refreshToken = null);
/**
* Refreshes and saves refreshed token
*
* @param string|null $refreshToken
* @param array $scope
* @param array $audience
*
* @return Token
*
* @throws RefreshTokenException
*/
public function refreshToken($refreshToken = null, array $scope = [], array $audience = []);
/**
* @deprecated use getValidToken instead
*
* Get or refreshes and saves token
*
* @param bool $forceRefresh
*
* @return Token
*/
public function getOrRefreshToken($forceRefresh = false);
/**
* Get or refreshes and saves token
*
* @param bool $forceRefresh
* @param bool $throw
* @param array $scope
* @param array $audience
*
* @return Token
*
* @throws RefreshTokenException
*/
public function getValidToken($forceRefresh = false, $throw = true, array $scope = [], array $audience = []);
/**
* @return void
*/
public function cleanup();
}

View File

@@ -0,0 +1,196 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Session;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Token\Token;
use PrestaShop\Module\PsAccounts\Hook\ActionShopAccessTokenRefreshAfter;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Exception\InvalidScopeException;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Exception;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2ServerException;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Service;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\AccessToken;
class ShopSession extends Session implements SessionInterface
{
/**
* @var ConfigurationRepository
*/
protected $configurationRepository;
/**
* @var OAuth2Service
*/
protected $oAuth2Service;
/**
* @var string
*/
protected $tokenAudience;
/**
* @param ConfigurationRepository $configurationRepository
* @param OAuth2Service $oAuth2Service
* @param string $tokenAudience
*/
public function __construct(
ConfigurationRepository $configurationRepository,
OAuth2Service $oAuth2Service,
$tokenAudience
) {
parent::__construct();
$this->configurationRepository = $configurationRepository;
$this->oAuth2Service = $oAuth2Service;
$this->tokenAudience = $tokenAudience;
}
/**
* @param bool $forceRefresh
* @param bool $throw
* @param array|null $scope
* @param array|null $audience
*
* @return Token
*
* @throws RefreshTokenException
*/
public function getValidToken($forceRefresh = false, $throw = true, array $scope = null, array $audience = null)
{
if ($scope === null) {
$scope = ($this->getStatusManager()->identityVerified() ? [
'shop.verified',
] : []);
}
if ($audience === null) {
$audience = [
'store/' . $this->getStatusManager()->getCloudShopId(),
$this->tokenAudience,
];
}
return parent::getValidToken($forceRefresh, $throw, $scope, $audience);
}
/**
* @param string $refreshToken
* @param array $scope
* @param array $audience
*
* @return Token
*
* @throws RefreshTokenException
*/
public function refreshToken($refreshToken = null, array $scope = [], array $audience = [])
{
try {
try {
$accessToken = $this->getAccessToken($scope, $audience);
} catch (InvalidScopeException $e) {
$accessToken = $this->fallbackRefresh($e, 'shop.verified', $scope, $audience);
}
$this->setToken(
$accessToken->access_token,
$accessToken->refresh_token
);
$token = $this->getToken();
\Hook::exec(ActionShopAccessTokenRefreshAfter::getName(), ['token' => $token]);
return $token;
} catch (OAuth2Exception $e) {
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
throw new RefreshTokenException('Unable to refresh shop token : ' . $e->getMessage(), 0, $e);
}
/**
* @return Token
*/
public function getToken()
{
return new Token($this->configurationRepository->getAccessToken());
}
/**
* @param string $token
* @param string $refreshToken
*
* @return void
*/
public function setToken($token, $refreshToken = null)
{
$this->configurationRepository->updateAccessToken($token);
}
/**
* @return void
*/
public function cleanup()
{
$this->configurationRepository->updateAccessToken('');
}
/**
* @param array $scope
* @param array $audience
*
* @return AccessToken
*
* @throws OAuth2Exception
*/
protected function getAccessToken(array $scope = [], array $audience = [])
{
return $this->oAuth2Service->getAccessTokenByClientCredentials($scope, $audience);
}
/**
* @param OAuth2ServerException $e
* @param string $filterScope
* @param array $scope
* @param array $audience
*
* @return AccessToken
*
* @throws OAuth2Exception
*/
protected function fallbackRefresh($e, $filterScope, array $scope, array $audience)
{
if (in_array($filterScope, $scope) &&
str_contains($e->getMessage(), $filterScope)
) {
$this->getStatusManager()->setIsVerified(false);
$this->resetRefreshTokenErrors();
$accessToken = $this->getAccessToken(array_filter($scope, function ($scp) use ($filterScope) {
return $scp !== $filterScope;
}), $audience);
} else {
throw $e;
}
return $accessToken;
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,161 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account;
use PrestaShop\Module\PsAccounts\Service\Accounts\Resource\ShopStatus;
class ShopUrl
{
/**
* @var string
*/
private $backOfficeUrl;
/**
* @var string
*/
private $frontendUrl;
/**
* @var int
*/
private $multiShopId;
/**
* ShopUrl constructor.
*
* @param string $backOfficeUrl
* @param string $frontendUrl
* @param int $multiShopId
*/
public function __construct($backOfficeUrl, $frontendUrl, $multiShopId)
{
$this->backOfficeUrl = $backOfficeUrl;
$this->frontendUrl = $frontendUrl;
$this->multiShopId = $multiShopId;
}
/**
* @param array $shop
*
* @return ShopUrl
*/
public static function createFromShopData($shop)
{
$backOfficeUrl = explode('/index.php', $shop['url'])[0];
$frontendUrl = rtrim($shop['frontUrl'], '/');
$multiShopId = (int) $shop['id'];
return new ShopUrl($backOfficeUrl, $frontendUrl, $multiShopId);
}
/**
* @return string
*/
public function getBackOfficeUrl()
{
return $this->backOfficeUrl;
}
/**
* @return string
*/
public function getFrontendUrl()
{
return $this->frontendUrl;
}
/**
* @return int
*/
public function getMultiShopId()
{
return $this->multiShopId;
}
/**
* Check if the frontend URL has changed compared to the remote status
*
* @param ShopUrl $shopUrl
*
* @return bool
*
* @throws \InvalidArgumentException
*/
public function frontendUrlEquals(ShopUrl $shopUrl)
{
$cloudFrontendUrl = rtrim($this->frontendUrl, '/');
$localFrontendUrl = rtrim($shopUrl->getFrontendUrl(), '/');
if (empty($cloudFrontendUrl) || empty($localFrontendUrl)) {
throw new \InvalidArgumentException('Frontend URL cannot be empty');
}
return $cloudFrontendUrl === $localFrontendUrl;
}
/**
* Check if the backOffice URL has changed compared to the remote status
* Returns true if backOfficeUrl changed
*
* @param ShopUrl $shopUrl
*
* @return bool
*
* @throws \InvalidArgumentException
*/
public function backOfficeUrlEquals(ShopUrl $shopUrl)
{
$cloudBackOfficeUrl = rtrim($this->getBackOfficeUrl(), '/');
$localBackOfficeUrl = rtrim($shopUrl->getBackOfficeUrl(), '/');
if (empty($cloudBackOfficeUrl) || empty($localBackOfficeUrl)) {
throw new \InvalidArgumentException('BackOffice URL cannot be empty');
}
return $cloudBackOfficeUrl === $localBackOfficeUrl;
}
/**
* @return ShopUrl
*/
public function trimmed()
{
return new ShopUrl(
rtrim($this->getBackOfficeUrl(), '/'),
rtrim($this->getFrontendUrl(), '/'),
$this->getMultiShopId()
);
}
/**
* Create a new ShopUrl from the status
*
* @param ShopStatus $status
* @param int $multiShopId
*
* @return ShopUrl
*/
public static function createFromStatus(ShopStatus $status, $multiShopId)
{
return new ShopUrl($status->backOfficeUrl, $status->frontendUrl, $multiShopId);
}
}

View File

@@ -0,0 +1,408 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account;
use DateTime;
use PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException;
use PrestaShop\Module\PsAccounts\Account\Exception\UnknownStatusException;
use PrestaShop\Module\PsAccounts\Account\Session\ShopSession;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsException;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
use PrestaShop\Module\PsAccounts\Service\Accounts\Resource\ShopStatus;
use PrestaShop\Module\PsAccounts\Traits\WithOriginAndSourceTrait;
/**
* @method $this withThrowException(bool $throwException)
* @method bool getThrowException(bool $restoreDefault = true)
* @method void resetThrowException()
*/
class StatusManager
{
use WithOriginAndSourceTrait {
getDefaults as WithOriginAndSourceTrait_getDefaults;
}
/**
* Status Cache TTL in seconds
*/
const CACHE_TTL = 30;
/**
* Infinite Status Cache
*/
const CACHE_TTL_INFINITE = -1;
/**
* @var ConfigurationRepository
*/
private $repository;
/**
* @var ShopSession
*/
private $shopSession;
/**
* @var AccountsService
*/
private $accountsService;
/**
* @var bool
*/
private $throwException;
/**
* @param ShopSession $shopSession
* @param AccountsService $accountsService
* @param ConfigurationRepository $repository
*/
public function __construct(
ShopSession $shopSession,
AccountsService $accountsService,
ConfigurationRepository $repository
) {
$this->repository = $repository;
$this->shopSession = $shopSession;
$this->accountsService = $accountsService;
$this->resetProperties();
}
/**
* @return array
*/
public function getDefaults()
{
return array_merge($this->WithOriginAndSourceTrait_getDefaults(), [
'throwException' => false,
]);
}
/**
* @return bool
*/
public function identityCreated()
{
return !empty($this->getCloudShopId());
}
/**
* @param bool $cachedStatus
*
* @return bool
*/
public function identityVerified($cachedStatus = true)
{
try {
return $this->getStatus($cachedStatus)->isVerified;
} catch (UnknownStatusException $e) {
return false;
}
}
/**
* @param bool $cachedOnly
* @param int $cacheTtl
*
* @return ShopStatus
*
* @throws AccountsException
* @throws RefreshTokenException
* @throws UnknownStatusException
*/
public function getStatus($cachedOnly = false, $cacheTtl = self::CACHE_TTL)
{
$handleException = function ($e) {
Logger::getInstance()->error($e->getMessage());
if ($this->getThrowException(false)) {
throw $e;
}
};
if (!$cachedOnly) {
try {
$cachedShopStatus = $this->getCachedStatus();
} catch (UnknownStatusException $e) {
$cachedShopStatus = null;
}
if (!$cachedShopStatus ||
$this->cacheInvalidated($cachedShopStatus) ||
$this->cacheExpired($cachedShopStatus, $cacheTtl)
) {
try {
$this->upsetCachedStatus(new CachedShopStatus([
'isValid' => true,
'updatedAt' => date('Y-m-d H:i:s'),
'shopStatus' => $this->accountsService
->withSource($this->getSource())
->shopStatus(
$this->getCloudShopId(),
$this->shopSession->getValidToken()
),
]));
} catch (AccountsException $e) {
$handleException($e);
} catch (RefreshTokenException $e) {
$handleException($e);
}
}
}
return $this->getCachedStatus()->shopStatus;
}
/**
* @return void
*/
public function invalidateCache()
{
$this->upsetCachedStatus(new CachedShopStatus([
'isValid' => false,
]));
}
/**
* @param CachedShopStatus $cachedStatus
*
* @return bool
*/
public function cacheInvalidated(CachedShopStatus $cachedStatus = null)
{
try {
$cachedStatus = $cachedStatus ?: $this->getCachedStatus();
$isValid = $cachedStatus->isValid;
} catch (UnknownStatusException $e) {
$isValid = false;
}
return !$isValid;
}
/**
* @param CachedShopStatus $cachedStatus
* @param int $cacheTtl
*
* @return bool
*/
public function cacheExpired(CachedShopStatus $cachedStatus = null, $cacheTtl = self::CACHE_TTL)
{
try {
//$dateUpd = $this->getCacheDateUpd();
$cachedStatus = $cachedStatus ?: $this->getCachedStatus();
$dateUpd = $cachedStatus->updatedAt;
return $dateUpd instanceof DateTime &&
$cacheTtl != self::CACHE_TTL_INFINITE &&
time() - $dateUpd->getTimestamp() >= $cacheTtl;
} catch (UnknownStatusException $e) {
return true;
}
}
// /**
// * @return \DateTime|null
// */
// public function getCacheDateUpd()
// {
// return $this->repository->getCachedShopStatusDateUpd();
// }
/**
* @param bool $cachedStatus
*
* @return string|null
*/
public function getCloudShopId($cachedStatus = true)
{
try {
return $this->getStatus($cachedStatus)->cloudShopId;
} catch (UnknownStatusException $e) {
return null;
}
}
/**
* @param string $cloudShopId
*
* @return void
*/
public function setCloudShopId($cloudShopId)
{
$this->upsetCachedStatus(new CachedShopStatus([
'shopStatus' => [
'cloudShopId' => $cloudShopId,
],
]));
}
/**
* @param bool $cachedStatus
*
* @return string|null
*/
public function getPointOfContactUuid($cachedStatus = true)
{
try {
return $this->getStatus($cachedStatus)->pointOfContactUuid;
} catch (UnknownStatusException $e) {
return null;
}
}
/**
* @param string $pointOfContactUuid
*
* @return void
*/
public function setPointOfContactUuid($pointOfContactUuid)
{
$this->upsetCachedStatus(new CachedShopStatus([
'shopStatus' => [
'pointOfContactUuid' => $pointOfContactUuid,
],
]));
}
/**
* @param bool $cachedStatus
*
* @return string|null
*/
public function getPointOfContactEmail($cachedStatus = true)
{
try {
return $this->getStatus($cachedStatus)->pointOfContactEmail;
} catch (UnknownStatusException $e) {
return null;
}
}
/**
* @param string $pointOfContactEmail
*
* @return void
*/
public function setPointOfContactEmail($pointOfContactEmail)
{
$this->upsetCachedStatus(new CachedShopStatus([
'shopStatus' => [
'pointOfContactEmail' => $pointOfContactEmail,
],
]));
}
/**
* @param bool $isVerified
*
* @return void
*/
public function setIsVerified($isVerified)
{
$this->upsetCachedStatus(new CachedShopStatus([
'shopStatus' => [
'isVerified' => (bool) $isVerified,
],
]));
}
/**
* @param ShopStatus $status
*
* @return void
*/
public function restoreStatus(ShopStatus $status)
{
$this->upsetCachedStatus(new CachedShopStatus([
'isValid' => true,
'updatedAt' => date('Y-m-d H:i:s'),
'shopStatus' => $status,
]));
}
/**
* @return void
*/
public function clearStatus()
{
$this->upsetCachedStatus(new CachedShopStatus([
'shopStatus' => [
'isVerified' => false,
'cloudShopId' => '',
'pointOfContactUuid' => '',
'pointOfContactEmail' => '',
'frontendUrl' => '',
'backOfficeUrl' => '',
'shopVerificationErrorCode' => '',
],
]));
$this->invalidateCache();
}
/**
* @return CachedShopStatus
*
* @throws UnknownStatusException
*/
protected function getCachedStatus()
{
$status = $this->repository->getCachedShopStatus();
if (!$status) {
throw new UnknownStatusException('Unknown status');
}
return new CachedShopStatus(json_decode($status, true));
}
/**
* @param CachedShopStatus $cachedShopStatus
*
* @return void
*/
protected function setCachedStatus(CachedShopStatus $cachedShopStatus)
{
$this->repository->updateCachedShopStatus(json_encode($cachedShopStatus->toArray()) ?: null);
$this->repository->updateShopUuid($cachedShopStatus->shopStatus->cloudShopId);
}
/**
* @param CachedShopStatus $cachedShopStatus
* @param bool $all all fields or only explicitly initialized fields
*
* @return void
*/
protected function upsetCachedStatus(CachedShopStatus $cachedShopStatus, $all = false)
{
try {
$this->setCachedStatus(new CachedShopStatus(array_replace_recursive(
$this->getCachedStatus()->toArray(),
$cachedShopStatus->toArray($all)
)));
} catch (UnknownStatusException $e) {
$this->setCachedStatus($cachedShopStatus);
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Token;
class NullToken extends \PrestaShop\Module\PsAccounts\Vendor\Lcobucci\JWT\Token
{
/**
* @return string
*/
public function toString()
{
return '';
}
}

View File

@@ -0,0 +1,192 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Account\Token;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Vendor\Lcobucci\JWT\Parser;
use PrestaShop\Module\PsAccounts\Vendor\Lcobucci\JWT\Token\InvalidTokenStructure;
class Token
{
const ID_OWNER_CLAIM = 'sub';
/**
* @var string
*/
private $token;
/**
* @var string
*/
private $refreshToken;
/**
* @param string $token
* @param string $refreshToken
*/
public function __construct($token, $refreshToken = null)
{
$this->token = $token;
$this->refreshToken = $refreshToken;
}
/**
* @return NullToken|\PrestaShop\Module\PsAccounts\Vendor\Lcobucci\JWT\Token
*/
public function getJwt()
{
return $this->parseToken($this->token);
}
/**
* @return string
*/
public function getRefreshToken()
{
return $this->refreshToken;
}
/**
* @return bool
*/
public function isExpired()
{
$token = $this->getJwt();
return $token->isExpired(new \DateTime());
}
/**
* @param array $scope
*
* @return bool
*/
public function hasScope(array $scope)
{
if ($scope === []) {
return true;
}
$claims = $this->getJwt()->claims();
if (!$claims->has('scp')) {
return false;
}
$scp = $claims->get('scp');
return count(array_intersect($scope, $scp)) == count($scope);
}
/**
* @param array $audience
*
* @return bool
*/
public function hasAudience(array $audience)
{
if ($audience === []) {
return true;
}
$claims = $this->getJwt()->claims();
if (!$claims->has('aud')) {
return false;
}
$aud = $claims->get('aud');
return count(array_intersect($audience, $aud)) == count($audience);
}
/**
* @param array $scope
* @param array $audience
*
* @return bool
*/
public function isValid(array $scope, array $audience)
{
$isValid = true;
if ($this->isExpired()) {
Logger::getInstance()->info(__METHOD__ . ': token isExpired ');
$isValid = false;
}
if ($isValid && !$this->hasScope($scope)) {
Logger::getInstance()->info(__METHOD__ . ': token scope invalid ');
$isValid = false;
}
if ($isValid && !$this->hasAudience($audience)) {
Logger::getInstance()->info(__METHOD__ . ': token audience invalid ');
$isValid = false;
}
return $isValid;
}
/**
* @return string|null
*/
public function getUuid()
{
return $this->getJwt()->claims()->get(static::ID_OWNER_CLAIM);
}
/**
* @return string|null
*/
public function getEmail()
{
// return $this->configuration->getFirebaseEmail();
return $this->getJwt()->claims()->get('email');
}
/**
* @return string
*/
public function __toString()
{
return (string) $this->token;
}
/**
* @param string $token
*
* @return \PrestaShop\Module\PsAccounts\Vendor\Lcobucci\JWT\Token
*/
protected function parseToken($token)
{
try {
return (new Parser())->parse((string) $token);
} catch (InvalidTokenStructure $e) {
return $this->getNullToken();
}
}
/**
* @return \PrestaShop\Module\PsAccounts\Vendor\Lcobucci\JWT\Token
*/
protected function getNullToken()
{
//return new \Lcobucci\JWT\Token([], ['exp' => new \DateTime()]);
return new NullToken([], ['exp' => new \DateTime()]);
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,67 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\AccountLogin\Exception;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\UserInfo;
class AccountLoginException extends \Exception
{
/**
* @var UserInfo|null
*/
protected $user;
/**
* @var string
*/
protected $type = 'error_other';
/**
* @param string $message
* @param UserInfo|null $user
* @param \Exception $previous
*/
public function __construct(
$message = '',
UserInfo $user = null,
\Exception $previous = null
) {
parent::__construct($message, 0, $previous);
$this->user = $user;
}
/**
* @return UserInfo|null
*/
public function getUser()
{
return $this->user;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\AccountLogin\Exception;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\UserInfo;
class EmailNotVerifiedException extends AccountLoginException
{
/**
* @param string $message
* @param UserInfo|null $user
* @param \Exception $previous
*/
public function __construct(
$message = 'Your account email is not verified',
UserInfo $user = null,
\Exception $previous = null
) {
parent::__construct($message, $user, $previous);
$this->type = 'email_not_verified';
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\AccountLogin\Exception;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\UserInfo;
class EmployeeNotFoundException extends AccountLoginException
{
/**
* @param string $message
* @param UserInfo|null $user
* @param \Exception $previous
*/
public function __construct(
$message = 'The email address is not associated to a PrestaShop backoffice account.',
UserInfo $user = null,
\Exception $previous = null
) {
parent::__construct($message, $user, $previous);
$this->type = 'employee_not_found';
}
}

View File

@@ -0,0 +1,41 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\AccountLogin\Exception;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\UserInfo;
class Oauth2LoginException extends AccountLoginException
{
/**
* @param string $message
* @param UserInfo|null $user
* @param \Exception $previous
*/
public function __construct(
$message = 'OAuth2 error',
UserInfo $user = null,
\Exception $previous = null
) {
parent::__construct($message, $user, $previous);
$this->type = 'error_from_hydra';
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,131 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\AccountLogin\Middleware;
use Exception;
use PrestaShop\Module\PsAccounts\AccountLogin\OAuth2LogoutTrait;
use PrestaShop\Module\PsAccounts\AccountLogin\OAuth2Session;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Client;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Service;
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
use Ps_accounts;
class Oauth2Middleware
{
use OAuth2LogoutTrait;
/**
* @var PsAccountsService
*/
private $psAccountsService;
/**
* @var OAuth2Session
*/
private $oAuth2Session;
/**
* @var OAuth2Service
*/
private $oAuth2Service;
public function __construct(Ps_accounts $module)
{
$this->psAccountsService = $module->getService(PsAccountsService::class);
$this->oAuth2Session = $module->getService(OAuth2Session::class);
$this->oAuth2Service = $module->getService(OAuth2Service::class);
}
/**
* @return void
*
* @deprecated since v7.1.2
*/
public function execute()
{
try {
if (isset($_GET['logout'])) {
$this->executeLogout();
}
} catch (Exception $e) {
Logger::getInstance()->err($e->getMessage());
}
}
/**
* @return void
*/
public function handleLogout()
{
try {
if (isset($_GET['logout'])) {
$this->executeLogout();
}
} catch (Exception $e) {
Logger::getInstance()->err($e->getMessage());
}
}
/**
* @return void
*
* @throws Exception
*/
public function executeLogout()
{
if ($this->psAccountsService->getLoginActivated() &&
!isset($_GET[OAuth2Client::getQueryLogoutCallbackParam()])) {
$this->oauth2Logout();
}
$this->getOauth2Session()->clear();
}
/**
* @return OAuth2Service
*/
protected function getOAuth2Service()
{
return $this->oAuth2Service;
}
/**
* @return OAuth2Session
*
* @throws Exception
*/
protected function getOauth2Session()
{
return $this->oAuth2Session;
}
/**
* @return bool
*
* @throws Exception
*/
protected function isOauth2LogoutEnabled()
{
// return $this->module->hasParameter('ps_accounts.oauth2_url_session_logout');
// FIXME
return true;
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,448 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\AccountLogin;
use Employee;
use PrestaShop\Module\PsAccounts\AccountLogin\Exception\AccountLoginException;
use PrestaShop\Module\PsAccounts\AccountLogin\Exception\EmailNotVerifiedException;
use PrestaShop\Module\PsAccounts\AccountLogin\Exception\EmployeeNotFoundException;
use PrestaShop\Module\PsAccounts\AccountLogin\Exception\Oauth2LoginException;
use PrestaShop\Module\PsAccounts\Context\ShopContext;
use PrestaShop\Module\PsAccounts\Entity\EmployeeAccount;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Repository\EmployeeAccountRepository;
use PrestaShop\Module\PsAccounts\Service\AnalyticsService;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Exception;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Service;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\AccessToken;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\UserInfo;
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Tools;
trait OAuth2LoginTrait
{
/**
* @return OAuth2Service
*/
abstract protected function getOAuth2Service();
/**
* @param AccessToken $accessToken
*
* @return bool
*/
abstract protected function initUserSession(AccessToken $accessToken);
/**
* @return mixed
*/
abstract protected function redirectAfterLogin();
/**
* @return mixed
*/
abstract protected function logout();
/**
* @return mixed
*/
abstract protected function onLoginFailedRedirect();
/**
* @return SessionInterface
*/
abstract protected function getSession();
/**
* @return OAuth2Session
*/
abstract protected function getOauth2Session();
/**
* @return AnalyticsService
*/
abstract protected function getAnalyticsService();
/**
* @return PsAccountsService
*/
abstract protected function getPsAccountsService();
/**
* @return string
*/
abstract protected function getSignupUrl();
/**
* @return mixed
*
* @throws EmailNotVerifiedException
* @throws EmployeeNotFoundException
* @throws Oauth2LoginException
* @throws \Exception
*/
public function oauth2Login()
{
$shopId = Tools::getValue('shop_id', $this->getShopId() ?: \Context::getContext()->shop->id);
/** @var ShopContext $shopContext */
$shopContext = $this->module->getService(ShopContext::class);
return $shopContext->execInShopContext($shopId, function () use ($shopId) {
// FIXME: rework multishop context management
//\Shop::setContext(\Shop::CONTEXT_SHOP, $shopId);
$apiClient = $this->getOAuth2Service();
//$this->getSession()->start();
$session = $this->getSession();
$oauth2Session = $this->getOauth2Session();
$returnTo = Tools::getValue($this->getReturnToParam());
$error = Tools::getValue('error', '');
$state = Tools::getValue('state', '');
$code = Tools::getValue('code', '');
$action = Tools::getValue('action', 'login');
$source = Tools::getValue('source', 'ps_accounts');
$forceSignup = Tools::getValue('forceSignup', false);
if (!empty($error)) {
// Got an error, probably user denied access
throw new \Exception('Got error: ' . $error);
// If we don't have an authorization code then get one
} elseif (empty($code)) {
// cleanup existing accessToken
$oauth2Session->clear();
$this->setReturnTo($returnTo);
$this->setOAuthAction($action);
$this->setSource($source);
$this->setShopId($shopId);
$this->setForceSignup($forceSignup);
$this->oauth2Redirect(Tools::getValue('locale', 'en'), $shopId);
// Check given state against previously stored one to mitigate CSRF attack
} elseif (empty($state) || ($session->has('oauth2state') && $state !== $session->get('oauth2state'))) {
$session->remove('oauth2state');
throw new \Exception('Invalid state');
} else {
$this->assertValidCode($code);
try {
$accessToken = $apiClient->getAccessTokenByAuthorizationCode(
$code,
$this->getSession()->get('oauth2pkceCode'),
[],
[],
$shopId
);
} catch (OAuth2Exception $e) {
throw new Oauth2LoginException($e->getMessage(), null, $e);
}
if ($this->initUserSession($accessToken)) {
return $this->redirectAfterLogin();
}
}
});
}
/**
* @param string $locale
* @param int|null $shopId
*
* @return void
*
* @throws \Exception
*/
private function oauth2Redirect($locale, $shopId)
{
$apiClient = $this->getOAuth2Service();
$state = $apiClient->getRandomState();
$pkceCode = $apiClient->getRandomPkceCode();
$this->getSession()->set('oauth2state', $state);
$this->getSession()->set('oauth2pkceCode', $pkceCode);
$authorizationUrl = $apiClient->getAuthorizationUri(
$state,
$pkceCode,
'S256',
$locale,
'',
'login',
$shopId
);
// Redirect the user to the authorization URL.
header('Location: ' . $authorizationUrl);
exit;
}
/**
* @param string $code
*
* @return void
*/
private function assertValidCode($code)
{
if (!preg_match('/^[^\s\"\';\(\)]+$/', $code)) {
throw new \InvalidArgumentException('Invalid code');
}
}
/**
* @param string $msg
*
* @return void
*
* @throws \Exception
*/
private function oauth2ErrorLog($msg)
{
Logger::getInstance()->error('[OAuth2] ' . $msg);
}
/**
* @return string
*
* @throws \Exception
*/
private function getReturnTo()
{
return $this->getSession()->get($this->getReturnToParam(), '');
}
/**
* @param string $returnTo
*
* @return void
*
* @throws \Exception
*/
private function setReturnTo($returnTo)
{
$this->getSession()->set($this->getReturnToParam(), $returnTo);
}
/**
* @return string
*/
private function getReturnToParam()
{
return 'return_to';
}
/**
* @return string
*/
private function getOAuthAction()
{
return $this->getSession()->get('oauth2action');
}
/**
* @param string $action
*
* @return void
*/
private function setOAuthAction($action)
{
$this->getSession()->set('oauth2action', $action);
}
/**
* @return string
*/
private function getSource()
{
return $this->getSession()->get('source');
}
/**
* @param string $source
*
* @return void
*/
private function setSource($source)
{
$this->getSession()->set('source', $source);
}
/**
* @return string
*/
private function getShopId()
{
return $this->getSession()->get('shopId');
}
/**
* @param string $shopId
*
* @return void
*/
private function setShopId($shopId)
{
$this->getSession()->set('shopId', $shopId);
}
/**
* @return bool
*/
private function getForceSignup()
{
return (bool) $this->getSession()->get('forceSignup', false);
}
/**
* @param bool $forceSignup
*
* @return void
*/
private function setForceSignup($forceSignup)
{
$this->getSession()->set('forceSignup', $forceSignup);
}
/**
* @param string $uid
* @param string $email
*
* @return Employee
*/
protected function getEmployeeByUidOrEmail($uid, $email)
{
$repository = new EmployeeAccountRepository();
try {
$employeeAccount = $repository->findByUid($uid);
/* @phpstan-ignore-next-line */
if ($employeeAccount) {
$employee = new Employee($employeeAccount->getEmployeeId());
} else {
$employeeAccount = new EmployeeAccount();
$employee = new Employee();
if (Employee::employeeExists($email)) {
$employee->getByEmail($email);
}
}
// Update account
if ($employee->id) {
$repository->upsert(
$employeeAccount
->setEmployeeId($employee->id)
->setUid($uid)
->setEmail($email)
);
}
} catch (\Exception $e) {
$employee = new Employee();
$employee->getByEmail($email);
}
return $employee;
}
/**
* @param AccountLoginException $e
*
* @return mixed
*/
protected function onLoginFailed(AccountLoginException $e)
{
if ($this->module->isShopEdition() && (
$e instanceof EmployeeNotFoundException ||
$e instanceof EmailNotVerifiedException
)) {
$this->trackEditionLoginFailedEvent($e);
}
$this->oauth2ErrorLog($e->getMessage());
$this->setLoginError($e->getType());
return $this->onLoginFailedRedirect();
}
/**
* @param mixed $error
*
* @return void
*/
protected function setLoginError($error)
{
$this->getSession()->set('loginError', $error);
}
/**
* @param UserInfo $user
*
* @return void
*/
protected function trackEditionLoginEvent(UserInfo $user)
{
if ($this->module->isShopEdition()) {
$this->getAnalyticsService()->identify(
$user->sub,
$user->name,
$user->email
);
$this->getAnalyticsService()->group(
$user->sub,
(string) $this->getPsAccountsService()->getShopUuid()
);
$this->getAnalyticsService()->trackUserSignedIntoApp(
$user->sub,
'smb-edition'
);
}
}
/**
* @param EmployeeNotFoundException|EmailNotVerifiedException $e
*
* @return void
*/
protected function trackEditionLoginFailedEvent($e)
{
$user = $e->getUser();
$this->getAnalyticsService()->identify(
$user->sub,
$user->name,
$user->email
);
$this->getAnalyticsService()->group(
$user->sub,
(string) $this->getPsAccountsService()->getShopUuid()
);
$this->getAnalyticsService()->trackBackOfficeSSOSignInFailed(
$user->sub,
$e->getType(),
$e->getMessage()
);
}
}

View File

@@ -0,0 +1,69 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\AccountLogin;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Service;
trait OAuth2LogoutTrait
{
/**
* @return OAuth2Service
*/
abstract protected function getOAuth2Service();
/**
* @return OAuth2Session
*/
abstract protected function getOauth2Session();
/**
* @return bool
*/
abstract protected function isOauth2LogoutEnabled();
/**
* @return void
*
* @throws \Exception
*/
public function oauth2Logout()
{
if (!$this->isOauth2LogoutEnabled()) {
return;
}
$idToken = $this->getOauth2Session()->getIdToken();
if (empty($idToken)) {
return;
}
$OAuth2Service = $this->getOAuth2Service();
$logoutUrl = $OAuth2Service->getLogoutUri(
$OAuth2Service->getOAuth2Client()->getPostLogoutRedirectUri(),
$idToken
);
header('Location: ' . $logoutUrl);
exit;
}
}

View File

@@ -0,0 +1,144 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\AccountLogin;
use PrestaShop\Module\PsAccounts\Account\Token\Token;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Client;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Exception;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Service;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\AccessToken;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\UserInfo;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class OAuth2Session
{
const TOKEN_NAME = 'accessToken';
/**
* @var SessionInterface|mixed
*/
private $session;
/**
* @var OAuth2Service
*/
private $oAuth2Service;
/**
* @var OAuth2Client
*/
private $oauth2Client;
/**
* @param mixed $session
* @param OAuth2Service $oAuth2Service
* @param OAuth2Client $oauth2Client
*/
public function __construct($session, OAuth2Service $oAuth2Service, OAuth2Client $oauth2Client)
{
$this->session = $session;
$this->oAuth2Service = $oAuth2Service;
$this->oauth2Client = $oauth2Client;
}
/**
* @return string|null
*/
public function getOrRefreshAccessToken()
{
$token = $this->getTokenProvider();
if ($token instanceof AccessToken && (new Token($token->access_token))->isExpired()) {
try {
$token = $this->oAuth2Service->refreshAccessToken($token->refresh_token);
$this->setTokenProvider($token);
} catch (OAuth2Exception $e) {
}
}
return $this->getAccessToken();
}
/**
* @return string|null
*/
public function getIdToken()
{
$token = $this->getTokenProvider();
return ($token instanceof AccessToken) ? $token->id_token : null;
}
/**
* @return string|null
*/
public function getAccessToken()
{
$token = $this->getTokenProvider();
return ($token instanceof AccessToken) ? $token->access_token : null;
}
/**
* @param AccessToken $token
*
* @return void
*/
public function setTokenProvider(AccessToken $token)
{
$this->session->set(self::TOKEN_NAME, $token);
}
/**
* @return bool
*/
public function isAuthenticated()
{
return $this->session->has(self::TOKEN_NAME);
}
/**
* @return UserInfo
*/
public function getUserInfo()
{
return $this->oAuth2Service->getUserInfo($this->getAccessToken());
}
/**
* @return void
*/
public function clear()
{
$this->session->remove(self::TOKEN_NAME);
}
/**
* @return AccessToken|null
*/
private function getTokenProvider()
{
if (!$this->oauth2Client->exists()) {
$this->clear();
}
return $this->session->get(self::TOKEN_NAME);
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,289 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Adapter;
use PrestaShop\Module\PsAccounts\Log\Logger;
class Configuration
{
/**
* @var int
*/
private $idShop = null;
/**
* @var int
*/
private $idShopGroup = null;
/**
* @var int
*/
private $idLang = null;
/**
* Configuration constructor.
*
* @param \Context $context
*/
public function __construct(\Context $context)
{
$this->setIdShop((int) $context->shop->id);
$this->setIdShopGroup((int) $context->shop->id_shop_group);
//$this->setIdLang((int) $context->language->id);
}
/**
* @return int
*/
public function getIdShop()
{
return $this->idShop;
}
/**
* @param int $idShop
*
* @return void
*/
public function setIdShop($idShop)
{
$this->idShop = $idShop;
}
/**
* @return int
*/
public function getIdShopGroup()
{
return $this->idShopGroup;
}
/**
* @param int $idShopGroup
*
* @return void
*/
public function setIdShopGroup($idShopGroup)
{
$this->idShopGroup = $idShopGroup;
}
/**
* @return int
*/
public function getIdLang()
{
return $this->idLang;
}
/**
* @param int $idLang
*
* @return void
*/
public function setIdLang($idLang)
{
$this->idLang = $idLang;
}
/**
* @param string $key
* @param string|bool $default
* @param bool $cached
*
* @return mixed
*
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function get($key, $default = false, $cached = true)
{
if ($cached) {
return $this->getRaw($key, $this->idLang, $this->idShopGroup, $this->idShop, $default);
} else {
// FIXME: idLang ??
// FIXME: beware in single shop context idShop must be set
return $this->getUncached($key, $this->idShopGroup, $this->idShop, $default);
}
}
/**
* @param string $key
* @param int|null $idLang
* @param int|null $idShopGroup
* @param int|null $idShop
* @param string|bool $default
*
* @return mixed
*/
protected function getRaw($key, $idLang = null, $idShopGroup = null, $idShop = null, $default = false)
{
$value = \Configuration::get($key, $idLang, $idShopGroup, $idShop);
return $value ?: ($default !== false ? $default : $value);
}
/**
* @param string $key
* @param string|array $values
* @param bool $html
*
* @return mixed
*/
public function set($key, $values, $html = false)
{
return $this->setRaw($key, $values, $html, $this->idShopGroup, $this->idShop);
}
/**
* @param string $key
* @param string|array $values
* @param bool $html
* @param int|null $idShopGroup
* @param int|null $idShop
*
* @return bool
*/
protected function setRaw($key, $values, $html = false, $idShopGroup = null, $idShop = null)
{
return \Configuration::updateValue($key, $values, $html, $idShopGroup, $idShop);
}
/**
* @param string $key
*
* @return mixed
*/
public function getGlobal($key)
{
return \Configuration::getGlobalValue($key);
}
/**
* @param string $key
* @param string|array $values
* @param bool $html
*
* @return void
*/
public function setGlobal($key, $values, $html = false)
{
\Configuration::updateGlobalValue($key, $values, $html);
}
/**
* @param string $key
* @param int|null $idShopGroup
* @param int|null $idShop
* @param string|bool $default
*
* @return mixed
*/
public function getUncached($key, $idShopGroup = null, $idShop = null, $default = false)
{
try {
return $this->getUncachedConfiguration($key, $idShopGroup, $idShop)->value;
} catch (\Exception $e) {
Logger::getInstance()->error(__METHOD__ . ': ' . $e->getMessage());
return $default;
}
}
/**
* @param string $key
* @param int|null $idShopGroup
* @param int|null $idShop
*
* @return \Configuration
*
* @throw \Exception
*/
public function getUncachedConfiguration($key, $idShopGroup = null, $idShop = null)
{
if (!$this->isMultishopActive()) {
// To avoid making 3 calls to the database in the single shop context
$idShopGroup = $idShop = null;
$id = \Configuration::getIdByName($key, $idShopGroup, $idShop);
} else {
// mimic the condition of the original \Configuration::get method
$id = \Configuration::getIdByName($key, 0, $idShop);
if (!$id) {
$id = \Configuration::getIdByName($key, $idShopGroup, 0);
}
if (!$id) {
$id = \Configuration::getIdByName($key, 0, 0);
}
}
if ($id > 0) {
$found = (new \Configuration($id));
$found->clearCache();
return $found;
}
throw new \Exception('Configuration entry not found: ' . $key . '|grp:' . $idShopGroup . '|shop:' . $idShop);
}
/**
* @param string $key
*
* @return \DateTime|null
*/
public function getDateUpd($key)
{
try {
$entry = $this->getUncachedConfiguration(
$key,
$this->getIdShopGroup(),
$this->getIdShop()
);
return new \DateTime($entry->date_upd);
} catch (\Exception $e) {
Logger::getInstance()->error(__METHOD__ . ': ' . $e->getMessage());
return null;
}
}
/**
* is multi-shop active "right now"
*
* @return bool
*/
public function isMultishopActive()
{
//return \Shop::isFeatureActive();
return \Db::getInstance()->getValue('SELECT value FROM `' . _DB_PREFIX_ . 'configuration` WHERE `name` = "PS_MULTISHOP_FEATURE_ACTIVE"')
&& (\Db::getInstance()->getValue('SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'shop') > 1);
}
/**
* @return int
*/
public function getMainShopId()
{
return (int) \Db::getInstance()->getValue('SELECT value FROM ' . _DB_PREFIX_ . "configuration WHERE name = 'PS_SHOP_DEFAULT'");
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Adapter;
use PrestaShop\Module\PsAccounts\Type\Enum;
class ConfigurationKeys extends Enum
{
const PSX_UUID_V4 = 'PSX_UUID_V4';
const PS_ACCOUNTS_LOGIN_ENABLED = 'PS_ACCOUNTS_LOGIN_ENABLED';
const PS_ACCOUNTS_OAUTH2_CLIENT_ID = 'PS_ACCOUNTS_OAUTH2_CLIENT_ID';
const PS_ACCOUNTS_OAUTH2_CLIENT_SECRET = 'PS_ACCOUNTS_OAUTH2_CLIENT_SECRET';
const PS_ACCOUNTS_ACCESS_TOKEN = 'PS_ACCOUNTS_ACCESS_TOKEN';
const PS_ACCOUNTS_LAST_UPGRADE = 'PS_ACCOUNTS_LAST_UPGRADE';
const PS_ACCOUNTS_SHOP_PROOF = 'PS_ACCOUNTS_SHOP_PROOF';
const PS_ACCOUNTS_CACHED_SHOP_STATUS = 'PS_ACCOUNTS_SHOP_STATUS';
const PS_ACCOUNTS_VALIDATION_LEEWAY = 'PS_ACCOUNTS_VALIDATION_LEEWAY';
/** @deprecated */
const PS_ACCOUNTS_FIREBASE_ID_TOKEN = 'PS_ACCOUNTS_FIREBASE_ID_TOKEN';
/* @deprecated */
const PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN = 'PS_ACCOUNTS_FIREBASE_REFRESH_TOKEN';
/* @deprecated */
const PS_ACCOUNTS_USER_FIREBASE_ID_TOKEN = 'PS_ACCOUNTS_USER_FIREBASE_ID_TOKEN';
/* @deprecated */
const PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN = 'PS_ACCOUNTS_USER_FIREBASE_REFRESH_TOKEN';
/* @deprecated */
const PS_ACCOUNTS_USER_FIREBASE_UUID = 'PS_ACCOUNTS_USER_FIREBASE_UUID';
/* @deprecated */
const PS_ACCOUNTS_FIREBASE_EMAIL = 'PS_ACCOUNTS_FIREBASE_EMAIL';
/* @deprecated */
const PS_ACCOUNTS_EMPLOYEE_ID = 'PS_ACCOUNTS_EMPLOYEE_ID';
/* @deprecated */
const PS_CHECKOUT_SHOP_UUID_V4 = 'PS_CHECKOUT_SHOP_UUID_V4';
/* @deprecated */
const PS_PSX_FIREBASE_ID_TOKEN = 'PS_PSX_FIREBASE_ID_TOKEN';
/* @deprecated */
const PS_PSX_FIREBASE_REFRESH_TOKEN = 'PS_PSX_FIREBASE_REFRESH_TOKEN';
/* @deprecated */
const PS_PSX_FIREBASE_REFRESH_DATE = 'PS_PSX_FIREBASE_REFRESH_DATE';
/* @deprecated */
const PS_PSX_FIREBASE_EMAIL = 'PS_PSX_FIREBASE_EMAIL';
}

View File

@@ -0,0 +1,227 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Adapter;
use PrestaShop\Module\PsAccounts\Context\ShopContext;
/**
* Link adapter
*/
class Link
{
/**
* @var ShopContext
*/
private $shopContext;
/**
* Link object
*
* @var \Link
*/
private $link;
/**
* @param ShopContext $shopContext
* @param \Link|null $link
*/
public function __construct(
ShopContext $shopContext,
\Link $link = null
) {
if (null === $link) {
$link = new \Link();
}
$this->shopContext = $shopContext;
$this->link = $link;
}
/**
* Adapter for getAdminLink from prestashop link class
*
* @param string $controller controller name
* @param bool $withToken include or not the token in the url
* @param array $sfRouteParams
* @param array $params
* @param int|null $shopId generate uri for a specific multishop id
*
* @return string
*/
public function getAdminLink($controller, $withToken = true, $sfRouteParams = [], $params = [], $shopId = null)
{
// Cannot generate admin link from front
if (!defined('_PS_ADMIN_DIR_')) {
return '';
}
if ($this->shopContext->isShop17()) {
$uri = $this->link->getAdminLink($controller, $withToken, $sfRouteParams, $params);
} else {
$uri = $this->getAdminLink16($controller, $withToken, $params);
}
if (!$withToken) {
// FIXME: getAdminLink still adds the token (sometimes)
$uri = preg_replace('/&_token=[^&]*/', '', $uri);
}
if ($shopId) {
$uri = $this->fixVirtualUri($uri, $shopId);
}
return $uri;
}
/**
* @param int|null $shopId
* @param bool|null $ssl
* @param bool $relativeProtocol
*
* @return string
*/
public function getAdminBaseLink($shopId = null, $ssl = null, $relativeProtocol = false)
{
/* @phpstan-ignore-next-line */
if (method_exists($this->link, 'getAdminBaseLink')) {
return $this->link->getAdminBaseLink($shopId, $ssl, $relativeProtocol);
} else {
return $this->getAdminBaseLink16($shopId, $ssl, $relativeProtocol);
}
}
/**
* @param string $controller
* @param bool $withToken
* @param array $params
* @param int $shopId
*
* @return string
*/
public function getAdminLink16($controller, $withToken, array $params, $shopId = null)
{
$paramsAsString = '';
foreach ($params as $key => $value) {
$paramsAsString .= "&$key=$value";
}
return $this->getAdminBaseLink16($shopId) .
basename(_PS_ADMIN_DIR_) . '/' . // admin path
$this->link->getAdminLink($controller, $withToken) .
$paramsAsString;
}
/**
* @param int|null $shopId
* @param bool|null $ssl
* @param bool $relativeProtocol
*
* @return string
*/
public function getAdminBaseLink16($shopId = null, $ssl = null, $relativeProtocol = false)
{
$path = __PS_BASE_URI__; // physical + virtual
if ($shopId) {
$shop = new \Shop($shopId);
$path = $shop->physical_uri . $shop->virtual_uri;
}
return \Tools::getShopDomainSsl(true) . $path;
}
/**
* @return \Link
*/
public function getLink()
{
return $this->link;
}
/**
* @param bool $withToken
*
* @return string
*/
public function getDashboardLink($withToken = false)
{
return $this->getAdminLink('AdminDashboard', false);
}
/**
* @param int $shopId
* @param bool $withToken
* @param string $moduleName
*
* @return string
*/
public function getModuleContentsLink($shopId, $withToken = false, $moduleName = 'ps_accounts')
{
return $this->getAdminLink(
'AdminModules',
$withToken,
[],
[
'configure' => $moduleName,
'setShopContext' => 's-' . $shopId,
]
);
}
/**
* @param string $link
*
* @return string
*/
public function cleanSlashes($link)
{
$link = preg_replace('@^(http|https)://@', '\1:SCHEME_SLASHES', $link);
$link = preg_replace('/\/+/', '/', $link);
return preg_replace('@^(http|https):SCHEME_SLASHES@', '\1://', $link);
}
/**
* @param string $link
*
* @return string
*/
public function getTrailingSlash($link)
{
return preg_match('/\/(\?|$)/', $link) ? '/' : '';
}
/**
* @param string $uri
* @param int $shopId
*
* @return string
*/
private function fixVirtualUri($uri, $shopId)
{
$shop = new \Shop($shopId);
return preg_replace(
'@^(https://[^/]+)' . preg_quote($shop->physical_uri, '@') . '.*' . preg_quote(basename(_PS_ADMIN_DIR_), '@') . '@',
//'$1' . $shop->physical_uri . basename(_PS_ADMIN_DIR_),
'https://' . $shop->domain_ssl . $shop->physical_uri . basename(_PS_ADMIN_DIR_),
$uri
);
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,52 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Api\Client;
use PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService;
/**
* @deprecated since v8.0.0 in favor of PrestaShop\Module\PsAccounts\Service\Accounts\AccountsService
*/
class AccountsClient
{
/**
* @var AccountsService
*/
protected $accountsService;
/**
* @param AccountsService $accountService
*/
public function __construct(AccountsService $accountService)
{
$this->accountsService = $accountService;
}
/**
* @param string $idToken
*
* @return array
*/
public function verifyToken($idToken)
{
return $this->accountsService->verifyToken($idToken)->toLegacy();
}
}

View File

@@ -0,0 +1,93 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Api\Client;
use PrestaShop\Module\PsAccounts\Http\Client\ClientConfig;
use PrestaShop\Module\PsAccounts\Http\Client\Curl\Client;
use PrestaShop\Module\PsAccounts\Http\Client\Factory;
use PrestaShop\Module\PsAccounts\Http\Client\Response;
class ExternalAssetsClient
{
/**
* @var \Ps_accounts
*/
private $module;
/**
* @var Client
*/
private $client;
/**
* @var array
*/
protected $clientConfig;
/**
* @param array $config
*/
public function __construct(array $config)
{
/** @var \Ps_accounts $module */
$module = \Module::getInstanceByName('ps_accounts');
$this->module = $module;
$this->clientConfig = array_merge([
ClientConfig::NAME => static::class,
ClientConfig::HEADERS => $this->getHeaders(),
], $config);
}
/**
* @return Client
*/
private function getClient()
{
if (null === $this->client) {
$this->client = (new Factory())->create($this->clientConfig);
}
return $this->client;
}
/**
* @param array $additionalHeaders
*
* @return array
*/
private function getHeaders($additionalHeaders = [])
{
return array_merge([
'Accept' => 'application/json',
], $additionalHeaders);
}
/**
* @return Response
*/
public function getTestimonials()
{
return $this->getClient()->get(
$this->module->getParameter('ps_accounts.testimonials_url')
);
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Api\Client;
use PrestaShop\Module\PsAccounts\Http\Client\ClientConfig;
use PrestaShop\Module\PsAccounts\Http\Client\Curl\Client;
use PrestaShop\Module\PsAccounts\Http\Client\Factory;
use PrestaShop\Module\PsAccounts\Http\Client\Request;
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
/**
* Handle call api Services
*
* @deprecated since v7.0.0
*/
class ServicesBillingClient
{
/**
* @var Client
*/
private $client;
/**
* ServicesBillingClient constructor.
*
* @param string $apiUrl
* @param PsAccountsService $psAccountsService
* @param ShopProvider $shopProvider
* @param Client|null $client
*
* @throws \PrestaShopException
*/
public function __construct(
$apiUrl,
PsAccountsService $psAccountsService,
ShopProvider $shopProvider,
Client $client = null
) {
$shopId = $shopProvider->getCurrentShop()['id'];
$token = $psAccountsService->getOrRefreshToken();
// Client can be provided for tests
if (null === $client) {
$client = (new Factory())->create([
ClientConfig::BASE_URI => $apiUrl,
ClientConfig::NAME => static::class,
ClientConfig::HEADERS => [
// Commented, else does not work anymore with API.
//'Content-Type' => 'application/vnd.accounts.v1+json', // api version to use
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . (string) $token,
'Shop-Id' => $shopId,
'Module-Version' => \Ps_accounts::VERSION, // version of the module
'Prestashop-Version' => _PS_VERSION_, // prestashop version
],
ClientConfig::TIMEOUT => 20,
ClientConfig::SSL_CHECK => true,
]);
}
$this->client = $client;
}
/**
* @param mixed $shopUuidV4
*
* @return array
*/
public function getBillingCustomer($shopUuidV4)
{
return $this->client->get('/shops/' . $shopUuidV4)
->toLegacy();
}
/**
* @param mixed $shopUuidV4
* @param array $bodyHttp
*
* @return array
*/
public function createBillingCustomer($shopUuidV4, $bodyHttp)
{
return $this->client->post(
'/shops/' . $shopUuidV4,
[
Request::FORM => $bodyHttp,
]
)->toLegacy();
}
/**
* @param mixed $shopUuidV4
* @param string $module
*
* @return array
*/
public function getBillingSubscriptions($shopUuidV4, $module)
{
return $this->client->get('/shops/' . $shopUuidV4 . '/subscriptions/' . $module)
->toLegacy();
}
/**
* @param mixed $shopUuidV4
* @param string $module
* @param array $bodyHttp
*
* @return array
*/
public function createBillingSubscriptions($shopUuidV4, $module, $bodyHttp)
{
return $this->client->post(
'/shops/' . $shopUuidV4 . '/subscriptions/' . $module,
[
Request::FORM => $bodyHttp,
]
)->toLegacy();
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,219 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Context;
use Context;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
/**
* Get the shop context
*/
class ShopContext
{
/**
* @var ConfigurationRepository
*/
private $configuration;
/**
* @var Context
*/
private $context;
/**
* ShopContext constructor.
*
* @param ConfigurationRepository $configuration
* @param Context $context
*/
public function __construct(
ConfigurationRepository $configuration,
Context $context
) {
$this->configuration = $configuration;
$this->context = $context;
}
/**
* @return bool
*/
public function isShop17()
{
return version_compare(_PS_VERSION_, '1.7.0.0', '>=');
}
/**
* @return bool
*/
public function isShop173()
{
return version_compare(_PS_VERSION_, '1.7.3.0', '>=');
}
/**
* @return int
*/
public function getShopContext()
{
return \Shop::getContext();
}
/**
* ID of shop or group
*
* @return int|null
*/
public function getShopContextId()
{
if (\Shop::getContext() == \Shop::CONTEXT_SHOP) {
return \Shop::getContextShopID();
}
if (\Shop::getContext() == \Shop::CONTEXT_GROUP) {
return \Shop::getContextShopGroupID();
}
return null;
}
/**
* @return bool
*/
public function isShopContext()
{
if ($this->isMultishopActive() && \Shop::getContext() !== \Shop::CONTEXT_SHOP) {
return false;
}
return true;
}
/**
* @param int $idShopUrl
*
* @return int
*/
public function getShopIdFromShopUrlId($idShopUrl)
{
return (int) \Db::getInstance()->getValue('SELECT id_shop FROM `' . _DB_PREFIX_ . 'shop_url` WHERE `id_shop_url` = ' . (int) $idShopUrl);
}
/**
* is multi-shop active "right now"
*
* @return bool
*/
public function isMultishopActive()
{
//return \Shop::isFeatureActive();
return $this->configuration->isMultishopActive();
}
/**
* @return bool
*/
public function sslEnabled()
{
return $this->configuration->sslEnabled();
}
/**
* @return string
*/
public function getProtocol()
{
return !$this->sslEnabled() ? 'http' : 'https';
}
/**
* @return Context
*/
public function getContext()
{
return $this->context;
}
/**
* @return ConfigurationRepository
*/
public function getConfiguration()
{
return $this->configuration;
}
/**
* @param int|null $shopId
* @param \Closure $closure
*
* @return mixed
*/
public function execInShopContext($shopId, $closure)
{
$backup = $this->configuration->getShopId();
$this->configuration->setShopId($shopId);
$exception = null;
$result = null;
try {
$result = $closure();
} catch (\Throwable $exception) {
/* @phpstan-ignore-next-line */
} catch (\Exception $exception) {
}
$this->configuration->setShopId($backup);
if (null !== $exception) {
throw $exception;
}
return $result;
}
/**
* @return int[]
*/
public function getMultiShopIds()
{
$shops = [];
$db = \Db::getInstance();
try {
$result = $db->query('SELECT id_shop FROM ' . _DB_PREFIX_ . 'shop');
while ($row = $db->nextRow($result)) {
/* @phpstan-ignore-next-line */
$shops[] = $row['id_shop'];
}
} catch (\Throwable $e) {
Logger::getInstance()->error(__METHOD__ . ': ' . $e->getMessage());
return [];
/* @phpstan-ignore-next-line */
} catch (\Exception $e) {
Logger::getInstance()->error(__METHOD__ . ': ' . $e->getMessage());
return [];
}
return $shops;
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,357 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Controller\Admin;
//use PrestaShopBundle\Controller\Admin\PrestaShopAdminController;
use Doctrine\ORM\EntityManagerInterface;
use PrestaShop\Module\PsAccounts\Account\Command\IdentifyContactCommand;
use PrestaShop\Module\PsAccounts\AccountLogin\Exception\AccountLoginException;
use PrestaShop\Module\PsAccounts\AccountLogin\Exception\EmailNotVerifiedException;
use PrestaShop\Module\PsAccounts\AccountLogin\Exception\EmployeeNotFoundException;
use PrestaShop\Module\PsAccounts\AccountLogin\OAuth2LoginTrait;
use PrestaShop\Module\PsAccounts\AccountLogin\OAuth2Session;
use PrestaShop\Module\PsAccounts\Adapter\Link;
use PrestaShop\Module\PsAccounts\Api\Client\ExternalAssetsClient;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
use PrestaShop\Module\PsAccounts\Log\Logger;
use PrestaShop\Module\PsAccounts\Service\AnalyticsService;
use PrestaShop\Module\PsAccounts\Service\OAuth2\OAuth2Service;
use PrestaShop\Module\PsAccounts\Service\OAuth2\Resource\AccessToken;
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;
use PrestaShopBundle\Entity\Employee\Employee as EmployeeEntity;
use Ps_accounts;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
class OAuth2Controller extends FrameworkBundleAdminController
{
use OAuth2LoginTrait;
/**
* @var Ps_accounts
*/
private $module;
/**
* @var AnalyticsService
*/
private $analyticsService;
/**
* @var PsAccountsService
*/
private $psAccountsService;
/**
* @var Link
*/
private $link;
/**
* @var SessionInterface
*/
private $session;
/**
* @var Security
*/
private $security;
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var ExternalAssetsClient
*/
private $externalAssetsClient;
/**
* @var RedirectResponse
*/
private $redirectResponse;
/**
* @var CommandBus
*/
private $commandBus;
public function __construct()
{
/** @var Ps_accounts $module */
$module = \Module::getInstanceByName('ps_accounts');
$this->module = $module;
$this->link = $this->module->getService(Link::class);
$this->analyticsService = $this->module->getService(AnalyticsService::class);
$this->psAccountsService = $this->module->getService(PsAccountsService::class);
$this->externalAssetsClient = $this->module->getService(ExternalAssetsClient::class);
$this->commandBus = $this->module->getService(CommandBus::class);
}
/**
* @param Request $request
* @param Security $security
* @param EntityManagerInterface $entityManager
*
* @return RedirectResponse
*/
public function initOAuth2FlowAction(
Request $request,
Security $security,
EntityManagerInterface $entityManager
) {
$this->security = $security;
$this->entityManager = $entityManager;
$this->session = $request->getSession();
try {
return $this->oauth2Login();
} catch (AccountLoginException $e) {
return $this->onLoginFailed($e);
} catch (\Exception $e) {
return $this->onLoginFailed(new AccountLoginException($e->getMessage(), null, $e));
}
}
/**
* @param Request $request
*
* @return Response|null
*
* @throws \PrestaShopException
*/
public function displayLoginAction(Request $request)
{
$isoCode = $this->getContext()->getCurrentLocale()->getCode();
// FIXME: extends login layout
return $this->render('@Modules/ps_accounts/templates/admin/login.html.twig', [
/* @phpstan-ignore-next-line */
'shopUrl' => $this->getContext()->shop->getBaseUrl(true),
//'oauthRedirectUri' => $this->generateUrl('ps_accounts_oauth2'),
'oauthRedirectUri' => $this->getOAuth2Service()->getOAuth2Client()->getRedirectUri(),
'legacyLoginUri' => $this->generateUrl('admin_login', [
'mode' => 'local',
]),
'isoCode' => substr($isoCode, 0, 2),
'locale' => substr($isoCode, 0, 2),
'defaultIsoCode' => 'en',
'testimonials' => $this->getTestimonials(),
'loginError' => $request->getSession()->remove('loginError'),
'meta_title' => '',
'ssoResendVerificationEmail' => $this->module->getParameter(
'ps_accounts.sso_resend_verification_email_url'
),
// FIXME: get intended redirect uri
'redirect' => '',
// FIXME: integration with the appropriate login layout & blocks
'linkCss' => $this->module->getPathUri() . '/views/css/login.css' .
'?v=' . urlencode($this->module->version),
'linkJs' => $this->module->getPathUri() . '/views/js/login.js' .
'?v=' . urlencode($this->module->version),
]);
}
/**
* @return OAuth2Service
*/
protected function getOAuth2Service()
{
return $this->module->getService(OAuth2Service::class);
}
/**
* @param AccessToken $accessToken
*
* @return bool
*
* @throws EmailNotVerifiedException
* @throws EmployeeNotFoundException
*/
protected function initUserSession(AccessToken $accessToken)
{
$user = $this->getOAuth2Service()->getUserInfo($accessToken->access_token);
Logger::getInstance()->info(
'[OAuth2] ' . (string) json_encode($user->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
);
if ($this->getOAuthAction() === 'identifyPointOfContact') {
$this->commandBus->handle(
(new IdentifyContactCommand($accessToken, $user))
->withSource($this->getSource())
);
return true;
}
$this->getOauth2Session()->setTokenProvider($accessToken);
//$user = $oauth2Session->getUserInfo();
//$context = $this->context;
/** @var \Context $context */
$context = $this->module->getService('ps_accounts.context');
$emailVerified = $user->email_verified;
$context->employee = $this->getEmployeeByUidOrEmail($user->sub, $user->email);
if (!$context->employee->id || empty($emailVerified)) {
if ($context->employee->isLoggedBack()) {
//$context->employee->logout();
$this->security->logout();
}
if (empty($emailVerified)) {
throw new EmailNotVerifiedException('Your account email is not verified', $user);
}
throw new EmployeeNotFoundException('The email address is not associated to a PrestaShop backoffice account.', $user);
}
$authenticator = 'security.authenticator.form_login.main';
$employeeRepository = $this->entityManager->getRepository(EmployeeEntity::class);
$employeeEntity = $employeeRepository->findById($context->employee->id)[0];
$response = $this->security->login($employeeEntity, $authenticator);
// FIXME: what if no redirect response ?
if ($response instanceof RedirectResponse) {
$this->redirectResponse = $response;
}
$this->trackEditionLoginEvent($user);
return true;
}
/**
* @return Response
*/
protected function redirectAfterLogin()
{
if ($this->getOAuthAction() === 'identifyPointOfContact') {
return $this->closePopup($this->getForceSignup());
}
return $this->redirectResponse;
}
/**
* @return RedirectResponse
*/
protected function logout()
{
return $this->redirect(
$this->link->getAdminLink('AdminLogin', true, [], [
'logout' => 1,
])
);
}
/**
* @return RedirectResponse|Response
*/
protected function onLoginFailedRedirect()
{
if ($this->getOAuthAction() === 'identifyPointOfContact') {
return $this->closePopup();
}
return $this->redirect(
$this->getReturnTo() ?:
$this->link->getAdminLink('AdminDashboard')
);
}
/**
* @return SessionInterface
*/
protected function getSession()
{
return $this->session;
}
/**
* @return OAuth2Session
*/
protected function getOauth2Session()
{
return $this->module->getService(OAuth2Session::class);
}
/**
* @return AnalyticsService
*/
protected function getAnalyticsService()
{
return $this->analyticsService;
}
/**
* @return PsAccountsService
*/
protected function getPsAccountsService()
{
return $this->psAccountsService;
}
/**
* @param bool $forceSignup
*
* @return Response
*/
protected function closePopup($forceSignup = false)
{
if ($forceSignup) {
return new RedirectResponse($this->getSignupUrl());
} else {
return (new Response())->setContent('
<script type="text/javascript">
window.close();
</script>
');
}
}
/**
* @return string
*/
protected function getSignupUrl()
{
return $this->module->getParameter('ps_accounts.accounts_ui_url') .
'?signupContext=popup';
}
/**
* @return array
*/
private function getTestimonials()
{
$res = $this->externalAssetsClient->getTestimonials();
return $res->isSuccessful ? $res->body : [];
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,68 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Cqrs;
abstract class Bus
{
/**
* @var \Ps_accounts
*/
protected $module;
/**
* @param \Ps_accounts $module
*/
public function __construct(\Ps_accounts $module)
{
$this->module = $module;
}
/**
* @param string $className
*
* @return string
*/
abstract public function resolveHandlerClass($className);
/**
* @param mixed $command
*
* @return mixed
*
* @throws \Exception
*/
public function handle($command)
{
$this->module->getLogger()->debug('resolving handler : ' . get_class($command));
$handler = $this->module->getService($this->resolveHandlerClass((string) get_class($command)));
if ($handler && method_exists($handler, 'handle')) {
/* @phpstan-ignore-next-line */
$this->module->getLogger()->debug('handling : ' . get_class($handler));
$this->module->getLogger()->debug('with data : ' . json_encode($command));
/* @phpstan-ignore-next-line */
return $handler->handle($command);
}
throw new \Exception('handle method not found');
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Cqrs;
class CommandBus extends Bus
{
/**
* @param string $className
*
* @return string
*/
public function resolveHandlerClass($className)
{
return preg_replace(
'/((Command)(\\\\([^\\\\]*?)(Command)?$))/',
'${2}Handler\\\\${4}Handler',
$className, 1);
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Cqrs;
class QueryBus extends Bus
{
/**
* @param string $className
*
* @return string
*/
public function resolveHandlerClass($className)
{
return preg_replace(
'/((Query)(\\\\([^\\\\]*?)(Query)?$))/',
'${2}Handler\\\\${4}Handler',
$className, 1);
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,222 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Entity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* EmployeeAccount.
*
* @ORM\Table()
* @ORM\Entity()
* @ORM\HasLifecycleCallbacks
*/
class EmployeeAccount
{
/**
* @var int
*
* @ORM\Id
* @ORM\Column(name="id_employee_account", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var int
*
* @ORM\Column(name="id_employee", type="integer")
*/
private $employeeId;
/**
* @var string
*
* @ORM\Column(name="email", type="string", length=64)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="uid", type="string", length=64)
*/
private $uid;
/**
* @var \DateTime
*
* @ORM\Column(name="date_add", type="datetime")
*/
private $dateAdd;
/**
* @var \DateTime
*
* @ORM\Column(name="date_upd", type="datetime")
*/
private $dateUpd;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return int
*/
public function getEmployeeId()
{
return $this->employeeId;
}
/**
* @param int $employeeId
*
* @return EmployeeAccount
*/
public function setEmployeeId($employeeId)
{
$this->employeeId = $employeeId;
return $this;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
*
* @return EmployeeAccount
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* @return string
*/
public function getUid()
{
return $this->uid;
}
/**
* @param string $uid
*
* @return EmployeeAccount
*/
public function setUid($uid)
{
$this->uid = $uid;
return $this;
}
/**
* @return \DateTime
*/
public function getDateAdd()
{
return $this->dateAdd;
}
/**
* Date is stored in UTC timezone
*
* @param \DateTime $dateAdd
*
* @return EmployeeAccount
*/
public function setDateAdd($dateAdd)
{
$this->dateAdd = $dateAdd;
return $this;
}
/**
* @return \DateTime
*/
public function getDateUpd()
{
return $this->dateUpd;
}
/**
* Date is stored in UTC timezone
*
* @param \DateTime $dateUpd
*
* @return EmployeeAccount
*/
public function setDateUpd(DateTime $dateUpd)
{
$this->dateUpd = $dateUpd;
return $this;
}
/**
* Now we tell doctrine that before we persist or update we call the updatedTimestamps() function.
*
* @ORM\PrePersist
* @ORM\PreUpdate
*
* @return void
*/
public function updatedTimestamps()
{
$this->setDateUpd(new DateTime());
if ($this->getDateAdd() == null) {
$this->setDateAdd(new DateTime());
}
}
/**
* @return array
*/
public function toArray()
{
return [
'id_employee' => $this->getEmployeeId(),
'id_employee_account' => $this->getId(),
'email' => $this->getEmail(),
'uid' => $this->getUid(),
'date_add' => $this->getDateAdd(),
'date_upd' => $this->getDateUpd(),
];
}
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Exception;
class BillingException extends \Exception
{
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Exception;
class DtoException extends \Exception
{
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Exception;
/**
* @deprecated Replaced by \PrestaShop\Module\PsAccounts\Account\Exception\RefreshTokenException
*/
class RefreshTokenException extends \Exception
{
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Exception;
class SshKeysNotFoundException extends \Exception
{
}

View File

@@ -0,0 +1,11 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
/**
* @deprecated
*/
class ActionAdminControllerInitBefore extends Hook
{
/**
* @param array $params
*
* @return string
*/
public function execute(array $params = [])
{
return '';
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
class ActionAdminControllerSetMedia extends Hook
{
/**
* @return void
*/
public function execute(array $params = [])
{
}
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
use Exception;
use PrestaShop\Module\PsAccounts\Service\AnalyticsService;
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
class ActionAdminLoginControllerLoginAfter extends Hook
{
/**
* @param array $params
*
* @return void
*
* @throws Exception
*/
public function execute(array $params = [])
{
if ($this->module->isShopEdition()) {
$this->trackLoginEvent($params['employee']);
}
}
/**
* @param \Employee $employee
*
* @return void
*
* @throws Exception
*/
protected function trackLoginEvent(\Employee $employee)
{
/** @var AnalyticsService $analyticsService */
$analyticsService = $this->module->getService(AnalyticsService::class);
/** @var PsAccountsService $psAccountsService */
$psAccountsService = $this->module->getService(PsAccountsService::class);
$account = $psAccountsService->getEmployeeAccount();
$uid = null;
if ($account) {
$uid = $account->getUid();
$email = $account->getEmail();
} else {
$email = $employee->email;
}
$analyticsService->identify($uid, null, $email);
$analyticsService->group($uid, (string) $psAccountsService->getShopUuid());
$analyticsService->trackUserSignedIntoBackOfficeLocally($uid, $email);
}
}

View File

@@ -0,0 +1,157 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
use AdminLoginPsAccountsController;
use Exception;
use PrestaShop\Module\PsAccounts\Account\Command\UpdateBackOfficeUrlsCommand;
use PrestaShop\Module\PsAccounts\Adapter\Link;
use PrestaShop\Module\PsAccounts\Service\AnalyticsService;
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
use Tools;
class ActionAdminLoginControllerSetMedia extends Hook
{
/**
* @return void
*
* @throws Exception
*/
public function execute(array $params = [])
{
// Check and update URL if admin url changed (before login)
// Only check before login form is being submitted
$this->checkAndUpdateBackofficeUrl();
if (defined('_PS_VERSION_') &&
version_compare(_PS_VERSION_, '8', '>=')) {
if (version_compare(_PS_VERSION_, '9', '<')) {
$this->executeV8();
} else {
$this->executeV9();
}
}
}
/**
* @return void
*
* @throws Exception
*/
protected function executeV8()
{
$local = $this->isLocalLogin();
$this->trackEditionLoginPage($local);
if (!$local) {
$this->redirectLegacyAccountLoginController();
}
}
/**
* @return void
*
* @throws Exception
*/
protected function executeV9()
{
$local = $this->isLocalLogin();
$this->trackEditionLoginPage($local);
if (!$local) {
$this->redirectSymfonyAccountLoginController();
}
}
/**
* @return bool
*/
protected function isLocalLogin()
{
/** @var PsAccountsService $psAccountsService */
$psAccountsService = $this->module->getService(PsAccountsService::class);
return Tools::getValue('mode') === AdminLoginPsAccountsController::PARAM_MODE_LOCAL ||
!empty(Tools::getValue('reset_token')) ||
!$psAccountsService->getLoginActivated();
}
/**
* @return void
*/
protected function redirectLegacyAccountLoginController()
{
// /** @var Link $link */
// $link = $this->module->getService(Link::class);
// Tools::redirectLink($link->getAdminLink('AdminLoginPsAccounts', false));
(new AdminLoginPsAccountsController())->run();
exit;
}
/**
* @return void
*/
protected function redirectSymfonyAccountLoginController()
{
/** @var Link $link */
$link = $this->module->getService(Link::class);
header('Location: ' . $link->getAdminLink('SfAdminLoginPsAccounts', false));
exit;
}
/**
* @param bool $local
*
* @return void
*
* @throws Exception
*/
protected function trackEditionLoginPage($local = false)
{
if ($this->module->isShopEdition()) {
/** @var PsAccountsService $psAccountsService */
$psAccountsService = $this->module->getService(PsAccountsService::class);
$account = $psAccountsService->getEmployeeAccount();
$userId = $account ? $account->getUid() : null;
/** @var AnalyticsService $analytics */
$analytics = $this->module->getService(AnalyticsService::class);
if (!$local) {
$analytics->pageAccountsBoLogin($userId);
} else {
$analytics->pageLocalBoLogin($userId);
}
}
}
/**
* Check if admin URL changed and update if needed
*
* @return void
*/
protected function checkAndUpdateBackofficeUrl()
{
$this->commandBus->handle(new UpdateBackOfficeUrlsCommand());
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
use PrestaShop\Module\PsAccounts\Repository\EmployeeAccountRepository;
class ActionObjectEmployeeDeleteAfter extends Hook
{
/**
* @param array $params
*
* @return void
*
* @throws \Exception
*/
public function execute(array $params = [])
{
try {
/** @var \Employee $employee */
$employee = $params['object'];
$repository = new EmployeeAccountRepository();
$employeeAccount = $repository->findByEmployeeId($employee->id);
if ($employeeAccount) {
$repository->delete($employeeAccount);
}
} catch (\Exception $e) {
} catch (\Throwable $e) {
}
}
}

View File

@@ -0,0 +1,43 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
use Exception;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
class ActionObjectShopAddAfter extends Hook
{
/**
* @param array $params
*
* @return bool
*
* @throws Exception
*/
public function execute(array $params = [])
{
/** @var ConfigurationRepository $configurationRepository */
$configurationRepository = $this->module->getService(ConfigurationRepository::class);
$configurationRepository->fixMultiShopConfig();
return true;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
use Exception;
use PrestaShop\Module\PsAccounts\Account\Command\CleanupIdentityCommand;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
class ActionObjectShopDeleteAfter extends Hook
{
/**
* @param array $params
*
* @return bool
*
* @throws Exception
*/
public function execute(array $params = [])
{
/** @var ConfigurationRepository $configurationRepository */
$configurationRepository = $this->module->getService(ConfigurationRepository::class);
$configurationRepository->fixMultiShopConfig();
$this->commandBus->handle((new CleanupIdentityCommand($params['object']->id)));
return true;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
/**
* @deprecated
*/
class ActionObjectShopDeleteBefore extends Hook
{
/**
* @param array $params
*
* @return bool
*/
public function execute(array $params = [])
{
return true;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
/**
* @deprecated
*/
class ActionObjectShopUpdateAfter extends Hook
{
/**
* @param array $params
*
* @return bool
*/
public function execute(array $params = [])
{
return true;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsAccounts\Hook;
/**
* @deprecated
*/
class ActionObjectShopUrlUpdateAfter extends ActionObjectShopUpdateAfter
{
/**
* @param array $params
*
* @return bool
*/
public function execute(array $params = [])
{
return true;
}
}

Some files were not shown because too many files have changed in this diff Show More