[TYPO3] Automatic FE user creation and auto-login

Jerome Schneider typo3dev at ameos.com
Mon Oct 1 14:05:51 CEST 2007


Hi Lasse,

For the automatic login, you can use this:

$rSql = $GLOBALS["TYPO3_DB"]->exec_SELECTquery(
	"*",
	"fe_users",
	"uid='" . $myUid . "'"
);

if(($aUser = $GLOBALS["TYPO3_DB"]->sql_fetch_assoc($rSql)) !== FALSE) {
	$GLOBALS["TSFE"]->fe_user->createUserSession($aUser);
	$GLOBALS["TSFE"]->fe_user->loginSessionStarted = TRUE;
	$GLOBALS["TSFE"]->fe_user->user =
		$GLOBALS["TSFE"]->fe_user->fetchUserSession();
}



Hope this helps,
Jerome Schneider


Lasse Guldsborg a écrit :
> Hi list!
> 
> I'm making and extension to auto-login FE users by URL.
> If the URL contains certain parameters a new FE user is created and logged 
> in.
> 
> Below is the part of the code, where the user i created and logged in. It 
> works, but it's not too smooth. The whole page is loaded before it reloads 
> and logs in the new user.
> 
> Is there a better way? A way in which the user is logged in immediately upon 
> creation.. before the HTML content starts generating.
> 
> Any help and/or comments are appreciated! :o)
> 
> Best regards,
> Lasse
> 
> ------------------------------------------
> 
> # Create user
> $query = 'insert into fe_users (pid, tstamp, username, password, usergroup, 
> endtime, name, crdate)
>   values (
>     "314",
>     "'.$time.'",
>     "'.mysql_escape_string($username).'",
>     "'.mysql_escape_string($password).'",
>     "10",
>     "'.($endtime).'",
>     "'.mysql_escape_string($_GET['userid']).'",
>     "'.$time.'")';
> $GLOBALS["TYPO3_DB"]->sql_query($query) or die($query."\n\n".mysql_error());
> 
> # login the new user
> $content .= '
> <form method="post" id="fe_cfu_user_login_form" 
> action="'.$this->pi_getPageLink($GLOBALS["TSFE"]->id).'">
>   <input type="hidden" id="user" name="user" value="'.$username.'" />
>   <input type="hidden" id="pass" name="pass" value="'.$password.'" />
>   <input type="hidden" name="logintype" value="login" />
>   <input type="hidden" name="pid" value="314" />
> </form>
> <script type="text/javascript">
>   document.getElementById("fe_cfu_user_login_form").submit();
> </script>';
> 
> return $content; 
> 
> 


More information about the TYPO3-english mailing list