Commit 49681637 authored by Thomas Löffler's avatar Thomas Löffler

Run Ajax login with middleware instead of eID

parent fca10206
......@@ -59,7 +59,7 @@ FlyOutAjaxLogin.prototype.authenticationRequest = function(event, form) {
FlyOutAjaxLogin.prototype.initMenuBar = function() {
const returnUrl = encodeURIComponent(window.location.href);
FlyOutAjaxLogin.callAjax('/index.php?eID=FlyOutAjaxLoginController&returnUrl=' + returnUrl, function (response) {
FlyOutAjaxLogin.callAjax('/index.php?load=FlyOutAjaxLogin&returnUrl=' + returnUrl, function (response) {
if (response !== null || response !== undefined || response !== '') {
const login = JSON.parse(response);
const container = document.querySelector('._login');
......
<?php
namespace T3o\T3olayout\Controller;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Mvc\Web\Response;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Fluid\View\StandaloneView;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Utility\EidUtility;
/**
* Class AjaxFrontendLoginController
*
* @target Frontend
*/
class FlyOutAjaxLoginController
{
public static function processLogin()
{
EidUtility::initTCA();
self::getTypoScriptFrontendController();
$feUser = EidUtility::initFeUser();
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$response = $objectManager->get(Response::class);
$response->setHeader('Content-Type', 'application/json; charset=utf-8');
$configurationManager = $objectManager->get(ConfigurationManager::class);
$typoScriptSetup = $configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
$contentObjectRenderer = $objectManager->get(ContentObjectRenderer::class);
$loginPid = $contentObjectRenderer->cObjGetSingle(
$typoScriptSetup['lib.']['loginPid'],
$typoScriptSetup['lib.']['loginPid.']
);
$loginFormPid = $contentObjectRenderer->cObjGetSingle(
$typoScriptSetup['lib.']['loginFormPid'],
$typoScriptSetup['lib.']['loginFormPid.']
);
$menuBarTemplate = $objectManager->get(StandaloneView::class);
$menuBarTemplate->setTemplatePathAndFilename('EXT:t3olayout/Resources/Private/Templates/Felogin/MenuBarAjaxLogin.html');
$menuBarTemplate->assign('user', $feUser->user);
$menuBarTemplate->assign('loginPid', $loginPid);
$menuBarTemplate->assign('loginFormPid', $loginFormPid);
echo json_encode(
[
'loginPid' => $loginPid,
'loginFormPid' => $loginFormPid,
'loggedIn' => $feUser->user['ses_userid'] > 0,
'menuBarTemplate' => $menuBarTemplate->render()
]
);
$response->send();
exit;
}
/**
* Initialize the typoscript frontend controller
*
* @param int $pid
*/
private static function getTypoScriptFrontendController($pid = 1)
{
/** @var \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $frontend */
$frontend = GeneralUtility::makeInstance(
\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController::class,
null,
$pid,
0
);
$GLOBALS['TSFE'] = $frontend;
$frontend->initFEuser();
$frontend->determineId();
$frontend->initTemplate();
$frontend->getConfigArray();
}
}
<?php
namespace T3o\T3olayout\Middlewares;
/*
* This file is part of a TYPO3 extension.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
class FlyOutAjaxLogin implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (!$request->getQueryParams()['load'] && $request->getQueryParams()['load'] !== 'FlyOutAjaxLogin') {
return $handler->handle($request);
}
$objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
$configurationManager = $objectManager->get(\TYPO3\CMS\Extbase\Configuration\ConfigurationManager::class);
$typoScriptSetup = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
$contentObjectRenderer = $objectManager->get(\TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer::class);
$loginPid = $contentObjectRenderer->cObjGetSingle(
$typoScriptSetup['lib.']['loginPid'],
$typoScriptSetup['lib.']['loginPid.']
);
$loginFormPid = $contentObjectRenderer->cObjGetSingle(
$typoScriptSetup['lib.']['loginFormPid'],
$typoScriptSetup['lib.']['loginFormPid.']
);
$feUser = $request->getAttribute('frontend.user');
$menuBarTemplate = $objectManager->get(\TYPO3\CMS\Fluid\View\StandaloneView::class);
$menuBarTemplate->setTemplatePathAndFilename('EXT:t3olayout/Resources/Private/Templates/Felogin/MenuBarAjaxLogin.html');
$menuBarTemplate->assign('user', $feUser->user);
$menuBarTemplate->assign('loginPid', $loginPid);
$menuBarTemplate->assign('loginFormPid', $loginFormPid);
$returnValue = [
'loginPid' => $loginPid,
'loginFormPid' => $loginFormPid,
'loggedIn' => $feUser->user['ses_userid'] > 0,
'menuBarTemplate' => $menuBarTemplate->render()
];
$response = new \GuzzleHttp\Psr7\Response();
$response->getBody()->write(json_encode($returnValue));
return $response;
}
}
......@@ -13,7 +13,7 @@ namespace T3o\T3olayout\ViewHelpers;
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
......
<?php
return [
'frontend' => [
't3olayout-ajaxlogin' => [
'target' => \T3o\T3olayout\Middlewares\FlyOutAjaxLogin::class,
'after' => [
'typo3/cms-frontend/prepare-tsfe-rendering'
]
]
]
];
[request.getQueryParams()['type'] == 4444]
[globalVar = GP:type = 4444]
config {
disableAllHeaderCode = 1
xhtml_cleaning = none
......
......@@ -28,8 +28,6 @@ if (class_exists('T3o\T3olayout\Hooks\MultiContentPreviewRenderer')) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][] = \T3o\T3olayout\Hooks\MultiContentPreviewRenderer::class;
}
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['FlyOutAjaxLoginController'] = \T3o\T3olayout\Controller\FlyOutAjaxLoginController::class . '::processLogin';
/***************
* Set alias for menu processor as fallback if the core menu
* processor does not exist for TYPO3 Versions below 8.5
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment