Typo3 7: manual FE-Login won’t work

In a typo3 7.6.10 installation I had to login a frontend user via ajax. This wouldn’t work and when I took a closer look at $GLOBALS[‘TSFE’] I noticed that fe_user->user was set, but $GLOBALS[‘TSFE’]->loginUser would always be reset to false after a page reload. Eventually I inspected the typo3 source and found the problem in initUserGroups in sysext/frontend/Classes/Controller/TypoScriptFrontendController.php : the user I tried to login did not have a group assigned (meaning the column “usergroup” in fe_users was empty). As soon as I entered a valid fe_groups ID there, the manual login worked as following:

$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']);

//check password etc. 
if ($this->loginSuccessful($user, $password)) {

    $tsfe = $GLOBALS['TSFE'];
    $tsfe->fe_user->createUserSession($user);
    $tsfe->fe_user->setAndSaveSessionData('dummy', TRUE);
    $tsfe->loginUser = 1;
    return json_encode(['status' => 'success']);
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.