开发者

Setting a fe_users session from extbase

As I have to verify the login-data in a way, normal login extensions can not handle, I have to develop a custom login-form. This login box is part of an ext. written in extbase.

But I stuck with a basic quest开发者_如何学运维ion: How can i handle fe_users sessions in extbase?


I wrote this function, maybe it helps:

/** @var $fe_user tslib_feUserAuth */
$fe_user = $GLOBALS['TSFE']->fe_user;
$fe_user->createUserSession(array('uid' => $uid));
$fe_user->user = $fe_user->getRawUserByUid($uid);
$fe_user->fetchGroupData();
$GLOBALS['TSFE']->loginUser = 1;

It's inspired by Tx_Phpunit_Framework::loginFrontEndUser($userId) :

// Instead of passing the actual user data to createUserSession, we
// pass an empty array to improve performance (e.g. no session record
// will be written to the database).
$GLOBALS['TSFE']->fe_user->createUserSession(array());
$GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->getRawUserByUid($userId);
$GLOBALS['TSFE']->fe_user->fetchGroupData();
$GLOBALS['TSFE']->loginUser = 1;


None of the answers provided seemed to work for me in TYPO3 6.2. The fix is described in a Bugreport in the Forge, https://forge.typo3.org/issues/62194 . Basically, the SessionCookie isn't placed automatically anymore, you need to do that on your own now, adding

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

after calling the createUserSession().


I finally made it, by combining lots of snippets. Thats how it worked out for me:

$loginData = array(
  'uname' => $loginData['user'],
  'uident' => $loginData['passw'],
  'status' => 'login'
);

$GLOBALS['TSFE']->fe_user->checkPid = 0;
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord( $info['db_user'], $loginData['uname'] );
if ( $GLOBALS['TSFE']->fe_user->compareUident($user,$loginData) )
{
    $GLOBALS["TSFE"]->fe_user->user = $GLOBALS["TSFE"]->fe_user->fetchUserSession();
    $GLOBALS['TSFE']->loginUser = 1;
    $GLOBALS['TSFE']->fe_user->fetchGroupData(); 
    $GLOBALS['TSFE']->fe_user->start();
    $GLOBALS["TSFE"]->fe_user->createUserSession($user);
    $GLOBALS["TSFE"]->fe_user->loginSessionStarted = TRUE;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜