简体   繁体   English

TYPO3:以编程方式登录fe_user后,将用户重定向到受保护的页面

[英]TYPO3: Redirect user to protected page after programmatic login of fe_user

In my Extbase extension, I wrote my own login mechanism, that triggers a manual login as a fe_user like this: 在我的Extbase扩展中,我编写了自己的登录机制,该机制触发了以fe_user身份进行手动登录,如下所示:

$GLOBALS['TSFE']->fe_user->checkPid = 0;
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord($info['db_user'], $feUsername);

$GLOBALS['TSFE']->fe_user->createUserSession($user);
$GLOBALS['TSFE']->fe_user->setAndSaveSessionData('dummy', TRUE);
$GLOBALS['TSFE']->loginUser = 1;

this->redirect(null, null, null, null, 38);

Afterwards I redirect the user to a page (ID 38) that has its Usergroup Access Rights set in a way, so that only this fe_user can access the page. 之后,我将用户重定向到设置了“用户组访问权限”的页面(ID 38),以便只有此fe_user可以访问该页面。

The login works and after login I can see the protected page in the menu and can access it. 登录有效,登录后我可以在菜单中看到受保护的页面并可以访问它。 However, the redirect to the protected page doesn't work. 但是,重定向到受保护的页面不起作用。 I end up on the home page. 我最终进入主页。 It seems the the login is somehow not fully active at the time when the redirect is taking place, but only after the page has been fully loaded once. 似乎在进行重定向时,登录以某种方式并没有完全激活,而只是在页面已完全加载一次之后。

Any idea how to fully apply the login prior to redirect? 知道如何在重定向之前完全应用登录名吗?

to force redirection to access restricted pages: 强制重定向以访问受限页面:

$uri = $this->uriBuilder->reset()
                ->setTargetPageUid($yourTargetUid)
                ->setCreateAbsoluteUri(true)
                ->setLinkAccessRestrictedPages(true)
                ->buildFrontendUri();

My suggestion: Build the URI to the action with the UriBuilder and use the AbstractController->redirectToUri function. 我的建议:使用UriBuilder构建操作的URI,并使用AbstractController-> redirectToUri函数。 Then the login should be completed before the new page is requested. 然后,应该在请求新页面之前完成登录。

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

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