Skip to content

Commit

Permalink
feat: new Token Management
Browse files Browse the repository at this point in the history
  • Loading branch information
hschoenenberger committed Feb 7, 2024
1 parent 691c8fa commit 623d83e
Show file tree
Hide file tree
Showing 60 changed files with 649 additions and 1,051 deletions.
2 changes: 1 addition & 1 deletion _dev/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ps_accounts",
"version": "6.4.0",
"version": "7.0.0",
"private": true,
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_accounts</name>
<displayName><![CDATA[PrestaShop Account]]></displayName>
<version><![CDATA[6.4.0]]></version>
<version><![CDATA[7.0.0]]></version>
<description><![CDATA[Link your store to your PrestaShop account to activate and manage your subscriptions in your back office. Do not uninstall this module if you have a current subscription.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
Expand Down
18 changes: 9 additions & 9 deletions config/command.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ services:
tags:
- { name: tactician.handler, command: 'PrestaShop\Module\PsAccounts\Domain\Shop\Command\LinkShopCommand' }
arguments:
- '@PrestaShop\Module\PsAccounts\Account\Session\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\OwnerSession'
- '@PrestaShop\Module\PsAccounts\Account\LinkShop'

PrestaShop\Module\PsAccounts\Account\CommandHandler\MigrateAndLinkV4ShopHandler:
class: PrestaShop\Module\PsAccounts\Account\CommandHandler\MigrateAndLinkV4ShopHandler
Expand All @@ -16,7 +15,7 @@ services:
arguments:
- '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient'
- '@PrestaShop\Module\PsAccounts\Context\ShopContext'
- '@PrestaShop\Module\PsAccounts\Account\Session\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession'

PrestaShop\Module\PsAccounts\Account\CommandHandler\DeleteUserShopHandler:
class: PrestaShop\Module\PsAccounts\Account\CommandHandler\DeleteUserShopHandler
Expand All @@ -26,23 +25,24 @@ services:
arguments:
- '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient'
- '@PrestaShop\Module\PsAccounts\Context\ShopContext'
- '@PrestaShop\Module\PsAccounts\Account\Session\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\OwnerSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession'

PrestaShop\Module\PsAccounts\Account\CommandHandler\UnlinkShopHandler:
class: PrestaShop\Module\PsAccounts\Account\CommandHandler\UnlinkShopHandler
public: true
tags:
- { name: tactician.handler, command: 'PrestaShop\Module\PsAccounts\Domain\Shop\Command\UnlinkShopCommand' }
arguments:
- '@PrestaShop\Module\PsAccounts\Service\ShopLinkAccountService'
- '@PrestaShop\Module\PsAccounts\Account\LinkShop'

PrestaShop\Module\PsAccounts\Account\CommandHandler\UpdateShopHandler:
class: PrestaShop\Module\PsAccounts\Account\CommandHandler\UpdateShopHandler
PrestaShop\Module\PsAccounts\Account\CommandHandler\UpdateUserShopHandler:
class: PrestaShop\Module\PsAccounts\Account\CommandHandler\UpdateUserShopHandler
public: true
tags:
- { name: tactician.handler, command: 'PrestaShop\Module\PsAccounts\Domain\Shop\Command\UpdateShopCommand' }
arguments:
- '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient'
- '@PrestaShop\Module\PsAccounts\Context\ShopContext'
- '@PrestaShop\Module\PsAccounts\Service\ShopLinkAccountService'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession'
57 changes: 25 additions & 32 deletions config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ services:
public: true
factory: [ 'PrestaShop\Module\PsAccounts\Factory\PsAccountsLogger', 'create' ]

PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopClientProvider:
class: PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopClientProvider
PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider:
class: PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider
public: true
factory: [ 'PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopClientProvider', 'create' ]
factory: [ 'PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider', 'create' ]

PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopSession:
class: PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopSession
Expand Down Expand Up @@ -72,17 +72,17 @@ services:
public: true
arguments:
- '@ps_accounts.module'
- '@PrestaShop\Module\PsAccounts\Account\Session\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\OwnerSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession'
- '@PrestaShop\Module\PsAccounts\Adapter\Link'

PrestaShop\Module\PsAccounts\Service\ShopLinkAccountService:
class: PrestaShop\Module\PsAccounts\Service\ShopLinkAccountService
PrestaShop\Module\PsAccounts\Account\LinkShop:
class: PrestaShop\Module\PsAccounts\Account\LinkShop
public: true
arguments:
- '@PrestaShop\Module\PsAccounts\Provider\RsaKeysProvider'
- '@PrestaShop\Module\PsAccounts\Account\Session\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\OwnerSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession'
- '@PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository'

PrestaShop\Module\PsAccounts\Service\PsBillingService:
Expand Down Expand Up @@ -125,7 +125,7 @@ services:
arguments:
- '%ps_accounts.sentry_credentials%'
- '%ps_accounts.environment%'
- '@PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository'
- '@ps_accounts.module'

###############
# api clients
Expand All @@ -135,15 +135,6 @@ services:
public: true
arguments:
- '%ps_accounts.accounts_api_url%'
- '@PrestaShop\Module\PsAccounts\Provider\ShopProvider'
- null
- 10

PrestaShop\Module\PsAccounts\Api\Client\SsoClient:
class: PrestaShop\Module\PsAccounts\Api\Client\SsoClient
public: true
arguments:
- '%ps_accounts.sso_api_url%'
- null
- 10

Expand All @@ -168,17 +159,24 @@ services:
class: PrestaShop\Module\PsAccounts\Account\Session\ShopSession
public: true
arguments:
- '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient'
- '@PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository'
- '@PrestaShop\Module\PsAccounts\Service\AnalyticsService'
- '@PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider'

PrestaShop\Module\PsAccounts\Account\Session\OwnerSession:
class: PrestaShop\Module\PsAccounts\Account\Session\OwnerSession
PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession:
class: PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession
public: true
arguments:
- '@PrestaShop\Module\PsAccounts\Api\Client\SsoClient'
- '@PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository'
- '@PrestaShop\Module\PsAccounts\Service\AnalyticsService'
- '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient'
- '@PrestaShop\Module\PsAccounts\Account\Session\ShopSession'

PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession:
class: PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession
public: true
arguments:
- '@PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository'
- '@PrestaShop\Module\PsAccounts\Api\Client\AccountsClient'
- '@PrestaShop\Module\PsAccounts\Account\Session\ShopSession'

PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository:
class: PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository
Expand All @@ -190,13 +188,13 @@ services:
class: PrestaShop\Module\PsAccounts\Repository\ShopTokenRepository
public: true
arguments:
- '@PrestaShop\Module\PsAccounts\Account\Session\ShopSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession'

PrestaShop\Module\PsAccounts\Repository\UserTokenRepository:
class: PrestaShop\Module\PsAccounts\Repository\UserTokenRepository
public: true
arguments:
- '@PrestaShop\Module\PsAccounts\Account\Session\OwnerSession'
- '@PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession'

#####################
# presenters
Expand All @@ -205,11 +203,6 @@ services:
class: PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter
public: true
arguments:
- '@PrestaShop\Module\PsAccounts\Service\PsAccountsService'
- '@PrestaShop\Module\PsAccounts\Provider\ShopProvider'
- '@PrestaShop\Module\PsAccounts\Service\ShopLinkAccountService'
- '@PrestaShop\Module\PsAccounts\Installer\Installer'
- '@PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository'
- '@ps_accounts.module'

#####################
Expand Down
13 changes: 7 additions & 6 deletions controllers/admin/AdminAjaxPsAccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
*/

use PrestaShop\Module\PsAccounts\Account\Command\DeleteUserShopCommand;
use PrestaShop\Module\PsAccounts\Account\Session\ShopSession;
use PrestaShop\Module\PsAccounts\Account\LinkShop;
use PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession;
use PrestaShop\Module\PsAccounts\Api\Client\IndirectChannelClient;
use PrestaShop\Module\PsAccounts\Cqrs\CommandBus;
use PrestaShop\Module\PsAccounts\Presenter\PsAccountsPresenter;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopSession;
use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
use PrestaShop\Module\PsAccounts\Service\SentryService;
use PrestaShop\Module\PsAccounts\Service\ShopLinkAccountService;

/**
* Controller for all ajax calls.
Expand Down Expand Up @@ -114,10 +115,10 @@ public function ajaxProcessUnlinkShop()
public function ajaxProcessResetLinkAccount()
{
try {
/** @var ShopLinkAccountService $shopLinkAccountService */
$shopLinkAccountService = $this->module->getService(ShopLinkAccountService::class);
/** @var LinkShop $linkShop */
$linkShop = $this->module->getService(LinkShop::class);

$shopLinkAccountService->resetLinkAccount();
$linkShop->delete();

header('Content-Type: text/json');

Expand Down Expand Up @@ -181,7 +182,7 @@ public function ajaxProcessGetInvitations()
try {
header('Content-Type: text/json');
$indirectsApi = $this->module->getService(
\PrestaShop\Module\PsAccounts\Api\Client\IndirectChannelClient::class
IndirectChannelClient::class
);
$response = $indirectsApi->getInvitations();

Expand Down
49 changes: 18 additions & 31 deletions controllers/admin/AdminDebugPsAccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\PsAccounts\Repository\ConfigurationRepository;
use PrestaShop\Module\PsAccounts\Account\Session\Firebase\OwnerSession;
use PrestaShop\Module\PsAccounts\Account\Session\Firebase\ShopSession;
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;

/**
Expand Down Expand Up @@ -46,29 +47,6 @@ class AdminDebugPsAccountsController extends ModuleAdminController
*/
public $module;

/**
* @var ConfigurationRepository
*/
private $configuration;

/**
* @var PsAccountsService
*/
private $psAccountsService;

/**
* AdminDebugController constructor.
*
* @throws Exception
*/
public function __construct()
{
parent::__construct();

$this->configuration = $this->module->getService(ConfigurationRepository::class);
$this->psAccountsService = $this->module->getService(PsAccountsService::class);
}

/**
* @return void
*
Expand All @@ -77,19 +55,28 @@ public function __construct()
*/
public function initContent()
{
/** @var OwnerSession $ownerSession */
$ownerSession = $this->module->getService(OwnerSession::class);

/** @var ShopSession $shopSession */
$shopSession = $this->module->getService(ShopSession::class);

/** @var PsAccountsService $psAccountsService */
$psAccountsService = $this->module->getService(PsAccountsService::class);

$this->context->smarty->assign([
'config' => [
'shopId' => (int) $this->context->shop->id,
'shopUuidV4' => $this->configuration->getShopUuid(),
'shopUuidV4' => $shopSession->getToken()->getUuid(),
'moduleVersion' => \Ps_accounts::VERSION,
'psVersion' => _PS_VERSION_,
'phpVersion' => phpversion(),
'firebase_email' => $this->configuration->getFirebaseEmail(),
'firebase_email_is_verified' => $this->configuration->firebaseEmailIsVerified(),
'firebase_id_token' => $this->configuration->getFirebaseIdToken(),
'firebase_refresh_token' => $this->configuration->getFirebaseRefreshToken(),
'adminAjaxUrl' => $this->psAccountsService->getAdminAjaxUrl(),
'isShopLinked' => $this->psAccountsService->isAccountLinked(),
'firebase_email' => $ownerSession->getToken()->getEmail(),
'firebase_email_is_verified' => $ownerSession->isEmailVerified(),
'firebase_id_token' => (string) $shopSession->getToken(),
'firebase_refresh_token' => '',
'adminAjaxUrl' => $psAccountsService->getAdminAjaxUrl(),
'isShopLinked' => $psAccountsService->isAccountLinked(),
],
]);
$this->content = $this->context->smarty->fetch($this->module->getLocalPath() . '/views/templates/admin/debug.tpl');
Expand Down
8 changes: 4 additions & 4 deletions controllers/admin/AdminLoginPsAccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

use PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopClientProvider;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider;

class AdminLoginPsAccountsController extends AdminLoginControllerCore
{
Expand Down Expand Up @@ -78,7 +78,7 @@ public function viewAccess($disable = false)
*/
public function setMedia($isNewTheme = false)
{
$this->addCss(_PS_MODULE_DIR_ . 'ps_accounts/views/css/login.css');
$this->addCss(_PS_MODULE_DIR_ . '/ps_accounts/views/css/login.css');
$this->addJS(_PS_MODULE_DIR_ . '/ps_accounts/views/js/login.js');
}

Expand All @@ -91,8 +91,8 @@ public function setMedia($isNewTheme = false)
*/
public function createTemplate($tpl_name)
{
/** @var PrestaShopClientProvider $provider */
$provider = $this->psAccounts->getService(PrestaShopClientProvider::class);
/** @var ShopProvider $provider */
$provider = $this->psAccounts->getService(ShopProvider::class);

$testimonials = $this->getTestimonials();

Expand Down
6 changes: 3 additions & 3 deletions controllers/admin/AdminOAuth2PsAccountsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
use PrestaShop\Module\PsAccounts\Exception\AccountLogin\EmployeeNotFoundException;
use PrestaShop\Module\PsAccounts\Exception\AccountLogin\Oauth2Exception;
use PrestaShop\Module\PsAccounts\Exception\AccountLogin\OtherErrorException;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopClientProvider;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopLoginTrait;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\PrestaShopSession;
use PrestaShop\Module\PsAccounts\Provider\OAuth2\ShopProvider;
use PrestaShop\Module\PsAccounts\Service\AnalyticsService;
use PrestaShop\Module\PsAccounts\Service\PsAccountsService;
use PrestaShop\OAuth2\Client\Provider\PrestaShopUser;
Expand Down Expand Up @@ -209,13 +209,13 @@ private function onLoginFailed(AccountLoginException $e)
}

/**
* @return PrestaShopClientProvider
* @return ShopProvider
*
* @throws Exception
*/
private function getProvider()
{
return $this->module->getService(PrestashopClientProvider::class);
return $this->module->getService(ShopProvider::class);
}

/**
Expand Down
Loading

0 comments on commit 623d83e

Please sign in to comment.