2016-08-22 61 views
0

我试图在ajaxAction中手动登录前端用户(并执行其他一些基本操作),但它似乎不起作用,因为我打算。我做什么,当登录表单提交:试图返回之前打印出来$GLOBALS['TSFE']->fe_usertypo3 7 + extbase:手动登录前端用户

$loginData = array(
    'username' => $username, 
    'uident_text' => $password, 
    'status' => 'login', 
); 

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

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

return json_encode(['login' => 'true']); 

,数据集和$GLOBALS['TSFE']->loginUser = 1,所以一切看起来文件。然而,当我重新加载登录表单时,fe_user数据仍然存在,但流体security.ifAuthenticated不起作用。

表单视图看起来是这样的:

<f:security.ifAuthenticated> 
    <f:then> 
     user is authenticated! 
    </f:then> 
    <f:else> 
     <f:render partial="LoginForm.html"/> 
    </f:else> 
</f:security.ifAuthenticated> 

Username: {user.firstName} 

它corretly输出登录用户的名字,但也仍显示登录表单。 security.ifAuthenticated总是进入ELSE。当我看着视图帮助器时,这是因为没有设置$GLOBALS['TSFE']->loginUser

任何提示/想法为什么发生这种情况?

回答

0

从我的实验中,你需要设置一个cookie来使其工作。

$reflection = new \ReflectionClass($GLOBALS['TSFE']->fe_user); 
$setSessionCookieMethod = $reflection->getMethod('setSessionCookie'); 
$setSessionCookieMethod->setAccessible(TRUE); 
$setSessionCookieMethod->invoke($GLOBALS['TSFE']->fe_user); 

如果我只用$ GLOBALS [ 'TSFE']玩 - > fe_users,它没有即使fe_session在数据库中创建工作。

0

发现我对typo3的经验不足,而fe_login出错。我不知道的是$ GLOBALS ['TSFE'] - > loginUser是fe_groups的一个指标。问题在于,我的前端用户未分配到组,“数据库中的用户组”列为空。因此,Typo3将loginUser设置为false,这就是为什么ifAuthenticated不起作用。

我写了关于解决方案here,但基本上我做的唯一的事情就是将用户分配到一个组,然后登录,因为我试过它工作正常。