gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:10:55 25 4
gpt4 key购买 nike

我正在开发一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com