<?php
defined('TYPO3') || die();

// Register Opentalent authentication service with TYPO3
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addService(
    'ot_connect',
    'auth',
    'tx_otconnect_service',
    [
        'title' => 'Opentalent Authentication',
        'description' => 'Opentalent authentication service for Frontend and Backend',
        'subtype' => 'getUserFE,authUserFE,getUserBE,authUserBE',
        'available' => true,
        'priority' => 80,
        // Priority must be higher than the priority of \TYPO3\CMS\Sv\AuthenticationService (50), or else failed login attempts will be logged each time
        'quality' => 80,
        'os' => '',
        'exec' => '',
        'className' => \Opentalent\OtConnect\Service\OtAuthenticationService::class
    ]
);

# Always fetch FE user, since the previous one could have been disconnected from the Opentalent API since
$GLOBALS['TYPO3_CONF_VARS']['SVCONF']['auth']['setup']['FE_alwaysFetchUser'] = true;
$GLOBALS['TYPO3_CONF_VARS']['SVCONF']['auth']['setup']['FE_alwaysAuthUser'] = true;

// Use popup window to refresh login instead of the AJAX relogin:
$GLOBALS['TYPO3_CONF_VARS']['BE']['showRefreshLoginPopup'] = 1;

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['postLoginFailureProcessing'][] =
    \Opentalent\OtConnect\Hooks\PostLoginFailureProcessingHook::class . '->postLoginFailureProcessing';
