first commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?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\Presenter;
|
||||
|
||||
use Module;
|
||||
use PrestaShop\Module\PsAccounts\Installer\Installer;
|
||||
use Ps_accounts;
|
||||
|
||||
class DependenciesPresenter implements PresenterInterface
|
||||
{
|
||||
/**
|
||||
* @var Installer
|
||||
*/
|
||||
private $installer;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
/** @var Ps_accounts $psAccounts */
|
||||
$psAccounts = Module::getInstanceByName('ps_accounts');
|
||||
|
||||
$this->installer = $psAccounts->getService(Installer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $psxName
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function present($psxName = 'ps_accounts')
|
||||
{
|
||||
$module = 'ps_eventbus';
|
||||
|
||||
return [
|
||||
'dependencies' => [
|
||||
$module => [
|
||||
'isInstalled' => $this->installer->isInstalled($module),
|
||||
'installLink' => $this->installer->getInstallUrl($module, $psxName),
|
||||
|
||||
'isEnabled' => $this->installer->isEnabled($module),
|
||||
'enableLink' => $this->installer->getEnableUrl($module, $psxName),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
34
modules/ps_accounts/classes/Presenter/PresenterInterface.php
Normal file
34
modules/ps_accounts/classes/Presenter/PresenterInterface.php
Normal 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\Presenter;
|
||||
|
||||
/**
|
||||
* Interface StorePresenter defines methods for store presenter.
|
||||
*/
|
||||
interface PresenterInterface
|
||||
{
|
||||
/**
|
||||
* Present store
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function present();
|
||||
}
|
||||
161
modules/ps_accounts/classes/Presenter/PsAccountsPresenter.php
Normal file
161
modules/ps_accounts/classes/Presenter/PsAccountsPresenter.php
Normal 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\Presenter;
|
||||
|
||||
use Module;
|
||||
use PrestaShop\Module\PsAccounts\Handler\Error\Sentry;
|
||||
use PrestaShop\Module\PsAccounts\Installer\Installer;
|
||||
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
|
||||
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
|
||||
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
|
||||
use PrestaShop\Module\PsAccounts\Service\ShopLinkAccountService;
|
||||
use PrestaShop\Module\PsAccounts\Service\SsoService;
|
||||
|
||||
/**
|
||||
* Construct the psaccounts module.
|
||||
*/
|
||||
class PsAccountsPresenter implements PresenterInterface
|
||||
{
|
||||
/**
|
||||
* @var ShopProvider
|
||||
*/
|
||||
protected $shopProvider;
|
||||
|
||||
/**
|
||||
* @var ShopLinkAccountService
|
||||
*/
|
||||
protected $shopLinkAccountService;
|
||||
|
||||
/**
|
||||
* @var SsoService
|
||||
*/
|
||||
protected $ssoService;
|
||||
|
||||
/**
|
||||
* @var ConfigurationRepository
|
||||
*/
|
||||
protected $configuration;
|
||||
|
||||
/**
|
||||
* @var Installer
|
||||
*/
|
||||
private $installer;
|
||||
|
||||
/**
|
||||
* @var PsAccountsService
|
||||
*/
|
||||
private $psAccountsService;
|
||||
|
||||
/**
|
||||
* PsAccountsPresenter constructor.
|
||||
*
|
||||
* @param PsAccountsService $psAccountsService
|
||||
* @param ShopProvider $shopProvider
|
||||
* @param ShopLinkAccountService $shopLinkAccountService
|
||||
* @param SsoService $ssoService
|
||||
* @param Installer $installer
|
||||
* @param ConfigurationRepository $configuration
|
||||
*/
|
||||
public function __construct(
|
||||
PsAccountsService $psAccountsService,
|
||||
ShopProvider $shopProvider,
|
||||
ShopLinkAccountService $shopLinkAccountService,
|
||||
SsoService $ssoService,
|
||||
Installer $installer,
|
||||
ConfigurationRepository $configuration
|
||||
) {
|
||||
$this->psAccountsService = $psAccountsService;
|
||||
$this->shopProvider = $shopProvider;
|
||||
$this->shopLinkAccountService = $shopLinkAccountService;
|
||||
$this->ssoService = $ssoService;
|
||||
$this->installer = $installer;
|
||||
$this->configuration = $configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Present the PsAccounts module data for JS
|
||||
*
|
||||
* @param string $psxName
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function present($psxName = 'ps_accounts')
|
||||
{
|
||||
// FIXME : Do this elsewhere
|
||||
$this->shopLinkAccountService->manageOnboarding($psxName);
|
||||
|
||||
$shopContext = $this->shopProvider->getShopContext();
|
||||
|
||||
$isEnabled = $this->installer->isEnabled('ps_accounts');
|
||||
|
||||
try {
|
||||
return array_merge(
|
||||
[
|
||||
'psxName' => $psxName,
|
||||
'psIs17' => $shopContext->isShop17(),
|
||||
|
||||
/////////////////////////////
|
||||
// InstallerPresenter
|
||||
|
||||
'psAccountsIsInstalled' => true,
|
||||
'psAccountsInstallLink' => null,
|
||||
|
||||
'psAccountsIsEnabled' => true,
|
||||
'psAccountsEnableLink' => null,
|
||||
|
||||
'psAccountsIsUptodate' => true,
|
||||
'psAccountsUpdateLink' => null,
|
||||
|
||||
////////////////////////////
|
||||
// PsAccountsPresenter
|
||||
|
||||
'onboardingLink' => $this->shopLinkAccountService->getLinkAccountUrl($psxName),
|
||||
|
||||
// FIXME : Mix "SSO user" with "Backend user"
|
||||
'user' => [
|
||||
'email' => $this->configuration->getFirebaseEmail() ?: null,
|
||||
'emailIsValidated' => $this->configuration->firebaseEmailIsVerified(),
|
||||
'isSuperAdmin' => $shopContext->getContext()->employee->isSuperAdmin(),
|
||||
],
|
||||
|
||||
'currentShop' => $this->shopProvider->getCurrentShop($psxName),
|
||||
'isShopContext' => $shopContext->isShopContext(),
|
||||
'shops' => $this->shopProvider->getShopsTree($psxName),
|
||||
|
||||
'superAdminEmail' => $this->psAccountsService->getSuperAdminEmail(),
|
||||
|
||||
// FIXME : move into Vue components .env
|
||||
'ssoResendVerificationEmail' => $this->ssoService->getSsoResendVerificationEmailUrl(),
|
||||
'manageAccountLink' => $this->ssoService->getSsoAccountUrl(),
|
||||
|
||||
'adminAjaxLink' => $this->psAccountsService->getAdminAjaxUrl(),
|
||||
],
|
||||
(new DependenciesPresenter())->present($psxName)
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
Sentry::captureAndRethrow($e);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
<?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\Presenter\Store\Context;
|
||||
|
||||
use Context;
|
||||
use PrestaShop\Module\PsAccounts\Adapter\Link;
|
||||
use PrestaShop\Module\PsAccounts\Presenter\PresenterInterface;
|
||||
use PrestaShop\Module\PsAccounts\Provider\ShopProvider;
|
||||
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
|
||||
use Ps_accounts;
|
||||
|
||||
class ContextPresenter implements PresenterInterface
|
||||
{
|
||||
/**
|
||||
* @var Ps_accounts
|
||||
*/
|
||||
private $module;
|
||||
|
||||
/**
|
||||
* @var PsAccountsService
|
||||
*/
|
||||
private $psAccountsService;
|
||||
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
public function __construct(Ps_accounts $module, Context $context)
|
||||
{
|
||||
$this->module = $module;
|
||||
$this->context = $context;
|
||||
$this->psAccountsService = $this->module->getService(PsAccountsService::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the merchant is onboarded on ps accounts
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function psAccountsIsOnboarded()
|
||||
{
|
||||
if ($this->psAccountsService->getRefreshToken() && $this->psAccountsService->isEmailValidated()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Present the Context Vuex
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function present()
|
||||
{
|
||||
/** @var Link $linkAdapter */
|
||||
$linkAdapter = $this->module->getService(Link::class);
|
||||
|
||||
/** @var ShopProvider $shopProvider */
|
||||
$shopProvider = $this->module->getService(ShopProvider::class);
|
||||
|
||||
$currentShop = $shopProvider->getCurrentShop();
|
||||
|
||||
return [
|
||||
'context' => [
|
||||
'app' => $this->getCurrentVueApp(),
|
||||
'user' => [
|
||||
'psAccountsIsOnboarded' => $this->psAccountsIsOnboarded(),
|
||||
],
|
||||
'version_ps' => _PS_VERSION_,
|
||||
'version_module' => $this->module->version,
|
||||
'shopId' => $this->psAccountsService->getShopUuidV4(),
|
||||
'isShop17' => version_compare(_PS_VERSION_, '1.7.3.0', '>='),
|
||||
'configurationLink' => $linkAdapter->getAdminLink('AdminModules', true, [], ['configure' => $this->module->name]),
|
||||
'controllersLinks' => [
|
||||
'ajax' => $linkAdapter->getAdminLink('AdminAjaxPsAccounts'),
|
||||
],
|
||||
'i18n' => [
|
||||
'isoCode' => $this->context->language->iso_code,
|
||||
'languageLocale' => $this->context->language->language_code,
|
||||
'currencyIsoCode' => $this->context->currency->iso_code,
|
||||
],
|
||||
'shop' => [
|
||||
'domain' => $currentShop['domain'],
|
||||
'url' => $currentShop['url'],
|
||||
],
|
||||
'readmeUrl' => $this->getReadme(),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Vue App to use in terms of context Controller Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function getCurrentVueApp()
|
||||
{
|
||||
return 'settings';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the documentation url depending on the current language
|
||||
*
|
||||
* @return string path of the doc
|
||||
*/
|
||||
private function getReadme()
|
||||
{
|
||||
$isoCode = $this->context->language->iso_code;
|
||||
|
||||
if (!file_exists(_PS_ROOT_DIR_ . _MODULE_DIR_ . $this->module->name . '/docs/readme_' . $isoCode . '.pdf')) {
|
||||
$isoCode = 'en';
|
||||
}
|
||||
|
||||
return _MODULE_DIR_ . $this->module->name . '/docs/readme_' . $isoCode . '.pdf';
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
*/
|
||||
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;
|
||||
@@ -0,0 +1,92 @@
|
||||
<?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\Presenter\Store;
|
||||
|
||||
use Context;
|
||||
use PrestaShop\Module\PsAccounts\Presenter\PresenterInterface;
|
||||
use PrestaShop\Module\PsAccounts\Presenter\Store\Context\ContextPresenter;
|
||||
use PrestaShop\Module\PsAccounts\Translations\SettingsTranslations;
|
||||
|
||||
/**
|
||||
* Present the store to the vuejs app (vuex)
|
||||
*/
|
||||
class StorePresenter implements PresenterInterface
|
||||
{
|
||||
/**
|
||||
* @var \Ps_accounts
|
||||
*/
|
||||
private $module;
|
||||
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $store;
|
||||
|
||||
/**
|
||||
* @param \Ps_accounts $module
|
||||
* @param Context $context
|
||||
* @param array|null $store
|
||||
*/
|
||||
public function __construct(\Ps_accounts $module, Context $context, array $store = null)
|
||||
{
|
||||
// Allow to set a custom store for tests purpose
|
||||
if (null !== $store) {
|
||||
$this->store = $store;
|
||||
}
|
||||
|
||||
$this->module = $module;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the store required by vuex
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function present()
|
||||
{
|
||||
if (null !== $this->store) {
|
||||
return $this->store;
|
||||
}
|
||||
|
||||
$contextPresenter = (new ContextPresenter($this->module, $this->context))->present();
|
||||
|
||||
// Load a presenter depending on the application to load (dashboard | settings)
|
||||
$this->store = array_merge(
|
||||
$contextPresenter,
|
||||
[
|
||||
'settings' => [
|
||||
'faq' => false,
|
||||
'translations' => (new SettingsTranslations($this->module))->getTranslations(),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
return $this->store;
|
||||
}
|
||||
}
|
||||
28
modules/ps_accounts/classes/Presenter/Store/index.php
Normal file
28
modules/ps_accounts/classes/Presenter/Store/index.php
Normal 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
|
||||
*/
|
||||
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;
|
||||
28
modules/ps_accounts/classes/Presenter/index.php
Normal file
28
modules/ps_accounts/classes/Presenter/index.php
Normal 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
|
||||
*/
|
||||
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;
|
||||
Reference in New Issue
Block a user