如何手动/以编程方式在typo3中创建和登录前端用户(用户)?

时间:2019-05-09 07:48:31

标签: login typo3 frontend felogin

我想在typo3中创建并登录一个前端用户,并且我应该能够看到用户以登录形式登录。仅供参考,用户已添加到数据库的fe_user表中,但未登录。

$GLOBALS['TSFE']->fe_user->forceSetCookie = TRUE;
                    $GLOBALS['TSFE']->fe_user->start();
                    $GLOBALS['TSFE']->fe_user->createUserSession($user);
                    $GLOBALS['TSFE']->fe_user->user = $user;
                    $GLOBALS['TSFE']->fe_user->setKey('user', 'fe_typo_user', $user);
                    $GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->fetchUserSession();
                    $GLOBALS['TSFE']->fe_user->setAndSaveSessionData('user', TRUE);
                    $this->ses_id = $GLOBALS['TSFE']->fe_user->fetchUserSession();
                    $reflection = new \ReflectionClass($GLOBALS['TSFE']->fe_user);
                    $setSessionCookieMethod = $reflection->getMethod('setSessionCookie');
                    $setSessionCookieMethod->setAccessible(TRUE);
                    $setSessionCookieMethod->invoke($GLOBALS['TSFE']->fe_user);
                    $GLOBALS['TYPO3_CONF_VARS']['SVCONF']['auth']['setup']['FE_alwaysFetchUser'] = true;
                    $GLOBALS['TYPO3_CONF_VARS']['SVCONF']['auth']['setup']['FE_alwaysAuthUser'] = true;
                    $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['felogin']['login_confirmed'] = true;
                    $GLOBALS['TSFE']->fe_user->storeSessionData();
                    $GLOBALS['TSFE']->fe_user->loginUser = 1;

expected this : [https://i.stack.imgur.com/lBBkn.png 现在得到这个https://i.stack.imgur.com/fjBlo.png

1 个答案:

答案 0 :(得分:0)

这种方式在7.6-9.5中对我有效:

$GLOBALS['TSFE']->fe_user->checkPid = 0;
$GLOBALS['TSFE']->fe_user->dontSetCookie = FALSE;
$GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->fetchUserSession();
$GLOBALS['TSFE']->loginUser = 1;
$GLOBALS['TSFE']->fe_user->start();
$GLOBALS['TSFE']->fe_user->createUserSession(['uid' => $userUid]);
$GLOBALS['TSFE']->initUserGroups();
$GLOBALS['TSFE']->fe_user->loginSessionStarted = TRUE;
$GLOBALS['TSFE']->storeSessionData();