[TYPO3] Automatic FE user creation and auto-login

Lasse Guldsborg lasse at clioonline.dk
Wed Oct 3 15:18:51 CEST 2007


Hi Jerome!

Thank you so much =)
I have modeled my code after yours, and it works great!

I have just one small issue left. Even though the user is in fact logged in, 
it is not shown in the login box on the first page that is loaded. Once you 
start navigating around the website the login box changes and shows that the 
user is logged in. Is there any way of correcting this, so that the login 
box immediatly shows that the new user is logged in?

Best regards,
Lasse


"Jerome Schneider" <typo3dev at ameos.com> skrev i en meddelelse 
news:mailman.1.1191240530.12906.typo3-english at lists.netfielders.de...
> 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