typo3-8.x - 如何在 Typo3 v8 或 v9 中 Hook 前端用户的注销操作

标签 typo3-8.x typo3-9.x typo3-extensions

我正在开发一个 Typo3 扩展,我想 Hook 前端用户的注销操作。我搜索了一个合适的指南/教程,并大致了解了如何做到这一点。我尝试了两种方法:

1) 使用 Logout_confirmed Hook 但它没有用。也许我错过了什么。我所做的是... 我在 ext_localconf.php 中提到了下面一行

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['logout_confirmed'] = Vendor/Ext_key/Hooks/Logout::class.'->checklogout'

并在给定路径 Vendor/Ext_key/Hooks/Logout::class.'->checklogout'... 创建了一个类,但是当用户点击注销时,流程永远不会到达 checklogout() 方法。有人可以告诉我我错过了什么或做错了什么。

2) 我尝试通过检查直接在 Controller 操作中拦截注销请求

            if ($_REQUEST['logintype'] == 'logout')

我可以拦截此请求,但在我在 Controller 中拦截它之前,用户已注销并且其数据已从 session 中清除。 当用户点击注销时,我必须为每个用户设置一些值,所以我想在用户点击注销之间和他的 session 被清除之前 Hook 。这样我就可以访问用户名并相应地为该用户设置值。

最佳答案

logoff() 方法中使用类 TYPO3\CMS\Core\Authentication\AbstractUserAuthentication 中的钩子(Hook)之一:

ext_localconf.php 中注册你的扩展钩子(Hook):

$GLOBALS['TYPO3_CONF_VARS']
        ['SC_OPTIONS']
        ['t3lib/class.t3lib_userauth.php']
        ['logoff_pre_processing']
        [] = \Vendor\Extension\Hooks\FrontendLogoutHook::class . '->checklogout';

添加类 Vendor\Extension\Hooks\FrontendLogoutHook:

class FrontendLogoutHook
{
    public function checklogout(array $ref, $userAuth)
    {
        $userId = $userAuth->getSession()->getUserId();

        if (
            $userAuth instanceof \TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
            && $userAuth->getLoginFormData()['status'] == 'logout'
            && $userId
        ) {
            // ... do stuff
        }
    }
}

上面的例子使用了钩子(Hook)logoff_pre_processing,它在注销发生之前被调用,但是在注销之后也有一个钩子(Hook)(logoff_post_processing)。

确保在将钩子(Hook)添加到 ext_localconf.php 后删除整个 TYPO3 缓存!

关于typo3-8.x - 如何在 Typo3 v8 或 v9 中 Hook 前端用户的注销操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61036724/

相关文章:

TYPO3 - 在自己的扩展中停用 cHash - 8LTS

youtube - 不要显示带有 TYPO3 分机 :news 的相关 youtube 视频

TYPO3,新闻 : change sort order and direction via get parameter

typo3 - 如何使用语言的多树概念设置 TYPO3 9.5.x

forms - 如何使用 EXT : Form in TYPO3 8. 7.1 将数据保存到数据库?

image - 如何在 TYPO3 中处理图像宽度/高度?

typo3 - 如何为多域 TYPO3 v9 设置 baseVariants?

typo3 - TYPO3 CMS 中的 dotenv-connector

typo3 - 如何升级 TYPO3 7.6.x 到 8.x.0

Typo3 - 自己的 viewhelper 在 T3 V8 中转义 HTML