Can't setCookies() via hook to login user

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Can't setCookies() via hook to login user

hopespoppa
A few published autologin solutions, as well as
SpecialUserLogin::processlogin uses the $wgUser= $u followed by
$wgUser->SetCookies method similar to the below snippet to login an
existing user.

When running this as a hook function, the Cookies won't set (won't
login). Debug log shows $tmpuser->getID()=13 and
$tmpuser->getName()='John Smith' just prior to the $wgUser=$tmpuser
statement.

Cookies are enabled,

What else is needed?

Thanks for any input,
Brian
- - -

function AutoL(&$user)
{
        global $sso_UN,$wgUser, $wgCommandLineMode;

         if ( !$wgCommandLineMode && !isset( $_COOKIE[session_name()] ) ) {
            User::SetupSession();
         }

        //Cancel if session is current
        $tmpuser = User::LoadFromSession();
        if($tmpuser->isLoggedIn())
             return;

        //Is the user already in the database?
        $tmpuser = User::newFromName($sso_UN);

        //If exists, log them in
        if($tmpuser->getID() != 0)
        {
                $tmpuser->loadFromDatabase();
                $wgUser = $tmpuser;
                $wgUser->setCookies();
                $wgUser->saveSettings();
                return;
        }
}
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l
Reply | Threaded
Open this post in threaded view
|

Re: Can't setCookies() via hook to login user

hopespoppa
Further debugging reveals that cookies are indeed 'set', meaning that a
 print_r($_COOKIE); outputs values for

[SSOLanguage] => en
[SSOCookie] => 3b84iei838ei...
[wikidbUserID] => 13
[wikidbUserName] => John Smith 123
[PHPSESSID] => njg7rnovlc8l...

So why won't the login 'stick'?

bc


On 5/24/06, Brian Carpenter <[hidden email]> wrote:

> A few published autologin solutions, as well as
> SpecialUserLogin::processlogin uses the $wgUser= $u followed by
> $wgUser->SetCookies method similar to the below snippet to login an
> existing user.
>
> When running this as a hook function, the Cookies won't set (won't
> login). Debug log shows $tmpuser->getID()=13 and
> $tmpuser->getName()='John Smith' just prior to the $wgUser=$tmpuser
> statement.
>
> Cookies are enabled,
>
> What else is needed?
>
> Thanks for any input,
> Brian
> - - -
>
> function AutoL(&$user)
> {
>        global $sso_UN,$wgUser, $wgCommandLineMode;
>
>         if ( !$wgCommandLineMode && !isset( $_COOKIE[session_name()] ) ) {
>            User::SetupSession();
>         }
>
>        //Cancel if session is current
>        $tmpuser = User::LoadFromSession();
>        if($tmpuser->isLoggedIn())
>             return;
>
>        //Is the user already in the database?
>        $tmpuser = User::newFromName($sso_UN);
>
>        //If exists, log them in
>        if($tmpuser->getID() != 0)
>        {
>                $tmpuser->loadFromDatabase();
>                $wgUser = $tmpuser;
>                $wgUser->setCookies();
>                $wgUser->saveSettings();
>                return;
>        }
> }
>
_______________________________________________
MediaWiki-l mailing list
[hidden email]
http://mail.wikipedia.org/mailman/listinfo/mediawiki-l