Skip to content

Commit

Permalink
Merge pull request #30 from yabid21/dev-5.x
Browse files Browse the repository at this point in the history
[TASK]New version to support V11 and V12
  • Loading branch information
yabid21 committed Sep 22, 2023
2 parents a17d739 + 86d5b0e commit 0999039
Show file tree
Hide file tree
Showing 59 changed files with 789 additions and 384 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
/Tests/Build/.phpunit.result.cache
/Libraries/vendor
/composer.lock
/rector.php
/.idea
6 changes: 3 additions & 3 deletions Classes/Command/CleanUpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
* Florian Wessels <f.wessels@Leuchtfeuer.com>, Leuchtfeuer Digital Marketing
*/

namespace Bitmotion\Auth0\Command;
namespace Leuchtfeuer\Auth0\Command;

use Auth0\SDK\Exception\ArgumentException;
use Auth0\SDK\Exception\NetworkException;
use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration;
use Bitmotion\Auth0\Factory\ApplicationFactory;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Exception;
use GuzzleHttp\Exception\GuzzleException;
use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration;
use Leuchtfeuer\Auth0\Factory\ApplicationFactory;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Symfony\Component\Console\Command\Command;
Expand Down
4 changes: 2 additions & 2 deletions Classes/Configuration/Auth0Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Florian Wessels <f.wessels@Leuchtfeuer.com>, Leuchtfeuer Digital Marketing
*/

namespace Bitmotion\Auth0\Configuration;
namespace Leuchtfeuer\Auth0\Configuration;

use Bitmotion\Auth0\Factory\ConfigurationFactory;
use Leuchtfeuer\Auth0\Factory\ConfigurationFactory;
use Symfony\Component\Yaml\Yaml;
use TYPO3\CMS\Core\Configuration\Loader\YamlFileLoader;
use TYPO3\CMS\Core\Core\Environment;
Expand Down
25 changes: 16 additions & 9 deletions Classes/Controller/ApplicationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
* Florian Wessels <f.wessels@Leuchtfeuer.com>, Leuchtfeuer Digital Marketing
*/

namespace Bitmotion\Auth0\Controller;
namespace Leuchtfeuer\Auth0\Controller;

use Bitmotion\Auth0\Domain\Model\Application;
use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration;
use Leuchtfeuer\Auth0\Domain\Model\Application;
use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration;
use Leuchtfeuer\Auth0\Utility\ModeUtility;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
Expand All @@ -23,27 +25,32 @@ class ApplicationController extends BackendController
/**
* @throws RouteNotFoundException
*/
public function listAction(): void
public function listAction(): ResponseInterface
{
$moduleTemplate = $this->initView();
$pid = $this->getStoragePage();
$this->view->assignMultiple([
'applications' => $this->applicationRepository->findAll(),
'pid' => $pid,
'directory' => BackendUtility::getRecord('pages', $pid),
'returnUrl' => $this->getModuleUrl(false),
]);
if (!ModeUtility::isTYPO3V12()) {
$this->view->assign('returnUrl', $this->getModuleUrl(false));
}
$moduleTemplate->setContent($this->view->render());

return $this->htmlResponse($moduleTemplate->renderContent());
}

/**
* @param Application $application
*
* @throws StopActionException
*/
public function deleteAction(Application $application): void
public function deleteAction(Application $application): ResponseInterface
{
$this->applicationRepository->remove($application);
$this->addFlashMessage($this->getTranslation('message.application.deleted.text'), $this->getTranslation('message.application.deleted.title'));
$this->redirect('list');

return $this->redirect('list');
}

protected function getStoragePage(): int
Expand Down
81 changes: 43 additions & 38 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,62 @@
* Florian Wessels <f.wessels@Leuchtfeuer.com>, Leuchtfeuer Digital Marketing
*/

namespace Bitmotion\Auth0\Controller;
namespace Leuchtfeuer\Auth0\Controller;

use Bitmotion\Auth0\Domain\Repository\ApplicationRepository;
use Leuchtfeuer\Auth0\Domain\Repository\ApplicationRepository;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException;
use TYPO3\CMS\Backend\Routing\UriBuilder as BackendUriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\View\BackendTemplateView;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;

class BackendController extends ActionController
{
/**
* @var BackendTemplateView
*/
protected $view;

protected $defaultViewObjectName = BackendTemplateView::class;

protected ApplicationRepository $applicationRepository;

public function __construct(ApplicationRepository $applicationRepository)
{
protected ModuleTemplateFactory $moduleTemplateFactory;
protected IconFactory $iconFactory;
protected BackendUriBuilder $backendUriBuilder;

public function __construct(
ApplicationRepository $applicationRepository,
ModuleTemplateFactory $moduleTemplateFactory,
IconFactory $iconFactory,
UriBuilder $uriBuilder,
BackendUriBuilder $backendUriBuilder
) {
$this->applicationRepository = $applicationRepository;
$this->moduleTemplateFactory = $moduleTemplateFactory;
$this->iconFactory = $iconFactory;
$this->uriBuilder = $uriBuilder;
$this->backendUriBuilder = $backendUriBuilder;
}

public function listAction(): void
public function listAction(): ResponseInterface
{
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
// Just an empty view
$moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($moduleTemplate->renderContent());
}

public function initializeView(ViewInterface $view): void
public function initView(): ModuleTemplate
{
parent::initializeView($view);
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$this->createMenu($moduleTemplate);
$this->createButtonBar($moduleTemplate);

if ($this->request->getControllerName() !== 'Backend' && $view instanceof BackendTemplateView) {
$view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
$this->createMenu();
$this->createButtonBar();
}
return $moduleTemplate;
}

protected function createMenu(): void
protected function createMenu(ModuleTemplate $moduleTemplate): void
{
$menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
$menu = $moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
$menu->setIdentifier('auth0');

$actions = [
Expand Down Expand Up @@ -92,28 +100,28 @@ protected function createMenu(): void
);
}

$this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
$moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
}

protected function createButtonBar(): void
protected function createButtonBar(ModuleTemplate $moduleTemplate): void
{
$buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();

$listButton = $buttonBar->makeLinkButton()
->setTitle($this->getTranslation('menu.button.overview'))
->setHref($this->getUriBuilder()->reset()->uriFor('list', [], 'Backend'))
->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon('actions-viewmode-tiles', Icon::SIZE_SMALL));
$buttonBar->addButton($listButton, ButtonBar::BUTTON_POSITION_LEFT);
->setIcon($this->iconFactory->getIcon('actions-viewmode-tiles', Icon::SIZE_SMALL));
$buttonBar->addButton($listButton);
}

protected function addButton(string $label, string $actionName, string $controllerName, string $icon): void
protected function addButton(string $label, string $actionName, string $controllerName, string $icon, ModuleTemplate $moduleTemplate): void
{
$buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar();

$linkButton = $buttonBar->makeLinkButton()
->setTitle($this->getTranslation($label))
->setHref($this->getUriBuilder()->reset()->uriFor($actionName, [], $controllerName))
->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon($icon, Icon::SIZE_SMALL));
->setIcon($this->iconFactory->getIcon($icon, Icon::SIZE_SMALL));

$buttonBar->addButton($linkButton, ButtonBar::BUTTON_POSITION_RIGHT);
}
Expand All @@ -123,26 +131,23 @@ protected function addButton(string $label, string $actionName, string $controll
*/
protected function getModuleUrl(bool $encoded = true, string $referenceType = BackendUriBuilder::ABSOLUTE_PATH): string
{
$backendUriBuilder = $this->objectManager->get(BackendUriBuilder::class);

$parameters = [
'tx_auth0_tools_auth0auth0' => [
'action' => $this->request->getControllerActionName(),
'controller' => $this->request->getControllerName(),
],
];

$uri = $backendUriBuilder->buildUriFromRoute('tools_Auth0Auth0', $parameters, $referenceType);
$uri = $this->backendUriBuilder->buildUriFromRoute('tools_Auth0Auth0', $parameters, $referenceType);

return $encoded ? rawurlencode($uri) : $uri;
}

protected function getUriBuilder(): UriBuilder
{
$uriBuilder = $this->objectManager->get(UriBuilder::class);
$uriBuilder->setRequest($this->request);
$this->uriBuilder->setRequest($this->request);

return $uriBuilder;
return $this->uriBuilder;
}

protected function getTranslation($key): string
Expand Down
20 changes: 11 additions & 9 deletions Classes/Controller/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@
* Florian Wessels <f.wessels@Leuchtfeuer.com>, Leuchtfeuer Digital Marketing
*/

namespace Bitmotion\Auth0\Controller;
namespace Leuchtfeuer\Auth0\Controller;

use Auth0\SDK\Auth0;
use Auth0\SDK\Exception\ConfigurationException;
use Bitmotion\Auth0\Domain\Repository\ApplicationRepository;
use Bitmotion\Auth0\Domain\Transfer\EmAuth0Configuration;
use Bitmotion\Auth0\Factory\ApplicationFactory;
use Bitmotion\Auth0\Middleware\CallbackMiddleware;
use Bitmotion\Auth0\Utility\ParametersUtility;
use Bitmotion\Auth0\Utility\RoutingUtility;
use Bitmotion\Auth0\Utility\TokenUtility;
use Leuchtfeuer\Auth0\Domain\Repository\ApplicationRepository;
use Leuchtfeuer\Auth0\Domain\Transfer\EmAuth0Configuration;
use Leuchtfeuer\Auth0\Factory\ApplicationFactory;
use Leuchtfeuer\Auth0\Middleware\CallbackMiddleware;
use Leuchtfeuer\Auth0\Utility\ParametersUtility;
use Leuchtfeuer\Auth0\Utility\RoutingUtility;
use Leuchtfeuer\Auth0\Utility\TokenUtility;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Context\Context;
Expand Down Expand Up @@ -62,7 +63,7 @@ public function initializeAction(): void
/**
* @throws AspectNotFoundException
*/
public function formAction(): void
public function formAction(): ResponseInterface
{
if (GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.user', 'isLoggedIn')) {
// Get Auth0 user from session storage
Expand All @@ -75,6 +76,7 @@ public function formAction(): void
'auth0Error' => $this->error,
'auth0ErrorDescription' => $this->errorDescription,
]);
return $this->htmlResponse();
}

/**
Expand Down
Loading

0 comments on commit 0999039

Please sign in to comment.