[TYPO3-dev] Create and login temp user
Christopher Lörken
christopher at loerken.net
Fri Mar 13 11:26:00 CET 2009
Hi Sebastian,
We are doing something similar and I use the following piece of code for
avoiding the GET parameter redirect. Would be nice to get some
feedback on that method too. (The comment of the method contains some
links to (german) posts regarding that question.)
/**
* Logs in a user in the Typo3 FE.
*
* Login code discussion:
http://www.typo3.net/forum/list/list_post//71147/?page=1#pid299542
* Final code adopted from here:
http://www.sk-typo3.de/FE-Userlogin-per-Code.191.0.html
*
* @param string $uname - unescaped name of the user.
*/
public static function loginUserByName($uname) {
if (!$GLOBALS['TSFE']->fe_user) {
if (!isset($GLOBALS['TYPO3_DB']) || !$GLOBALS['TYPO3_DB']->link) {
tslib_eidtools::connectDB();
}
$GLOBALS['TSFE']->fe_user = tslib_eidtools::initFeUser();
}
$GLOBALS['TSFE']->fe_user->checkPid=0; //do not use a particular pid
$info= $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
$user=$GLOBALS['TSFE']->fe_user->fetchUserRecord($info['db_user'],$uname);
$GLOBALS['TSFE']->fe_user->createUserSession($user);
$GLOBALS['TSFE']->fe_user->user = $user;
}
The call to this function does generate a valid user session in the
table. You need to redirect to another page afterwards to do the proper
authentication handling by Typo3 afterwards (too show the user as being
logged in).
Sebastian Gebhard schrieb:
> Peter Russ schrieb:
>> Just check the auth service: that's the rightway to do -> tx_sv_auth
I definitely should check that out but must admit that I haven't had the
time yet.
Maybe it helps
Cheers,
Christopher
More information about the TYPO3-dev
mailing list