简体   繁体   English

Typo3 FE 编程登录

[英]Typo3 FE login programatically

In Typo3 post v10 onwards, how can I log in an FE user programmatically with just a user Id number, using the new authentication services and without having to render a form to submit?在 v10 之后的 Typo3 中,如何使用新的身份验证服务以编程方式仅使用用户 ID 号登录 FE 用户,而无需呈现要提交的表单?

I have a custom Typo3 v10 plugin that authenticates users and has worked fine in Typo3 v9 and v10.我有一个自定义的 Typo3 v10 插件,可以对用户进行身份验证,并且在 Typo3 v9 和 v10 中运行良好。 After checking credentials, I use the following:检查凭据后,我使用以下内容:

$userToLogin = 123; //known user id.

$feUser = $GLOBALS['TSFE']->fe_user;
unset($feUser->user);
$feUser->createUserSession($userToLogin);
$feUser->loginSessionStarted = TRUE;
$feUser->user = $feUser->fetchUserSession();
$GLOBALS['TSFE']->loginUser = 1;
$GLOBALS['TSFE']->initUserGroups(); 

//reload the page so that restricted subpages appear in menus
$this->redirectToUri($this->linkThisPage);
            

I need to upgrade to V11 and thus to use the authentication service process instead, as $GLOBALS['TSFE']->loginUser is removed in Typo3 v11.我需要升级到 V11 并因此改用身份验证服务进程,因为 $GLOBALS['TSFE']->loginUser 在 Typo3 v11 中被删除。

I get it from this post that this involves setting up a custom service, which is registered in the plugin localConf.php file.我从这篇文章中了解到,这涉及设置自定义服务,该服务在插件 localConf.php 文件中注册。 The issue is about how to trigger the login process?问题是关于如何触发登录过程? The example linked above resorts to rendering a mostly hidden form with a "Confirm" submit button that the user must press to trigger the login process.上面链接的示例诉诸于渲染一个大部分隐藏的表单,其中包含一个“确认”提交按钮,用户必须按下该按钮才能触发登录过程。 This may work, but looks bad, as the user has already authenticated elsewhere.这可能有效,但看起来很糟糕,因为用户已经在其他地方进行了身份验证。

Does anyone know how can I trigger the authentication process programatically in a controller, without requiring the form submission?有谁知道如何在 controller 中以编程方式触发身份验证过程,而不需要提交表单? Many thanks in advance.提前谢谢了。

The Authentication Service login is triggered when Typo3 finds the request parameter with a logintype=login then your authentication service can do what it needs to do当 Typo3 找到带有logintype=login的请求参数时,将触发身份验证服务登录,然后您的身份验证服务可以执行它需要执行的操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM