Ask your Symfony questions! Pay money and get answers fast! (more info)

How can I manually call Remember Me? Symfony

  • SOLVED

I'm helping a client integrate a site with JanRain RPX. We want people to stay logged in for awhile.

If the user logs in the normal way, using the signinSuccess.php form that comes with sfGuardUserPlugin. And if people click the RememberMe button, they stay logged in for a long time. I'm trying to figure out how I can trigger "RememberMe" manually.

I'm using this code handling JanRain RPX:


$user = sfGuardUserPeer::retrieveByUsername($email);
if (get_class($user) == 'sfGuardUser') {
$this->getUser()->signin($user);
$this->setFlash('notice', 'You are logged in');
$this->forward('user', 'home');
return sfView::SUCCESS;
}


This code works great, but it does not seem to trigger RememberMe. I need to figure out a way to make that happen.

Basically, I want to set the RememberMe cookie, which seems easy to do from action code, but I assume I can not do this in the action code, since that comes too late in the overall process, yes?

In sfGuardRememberMeFilter.class.php I do not see a cookie being set, so I assume the code that sets the cookie is elsewhere. But where? And what value is used to set this cookie?

Answers (3)

2010-07-27

JuG answers:

Hi,


Just call the sfGuardSecurityUser::signIn with an extra parameter :


$user = sfGuardUserPeer::retrieveByUsername($email);

// Please note the use of "instanceof" in the condition
if ( $user instanceof sfGuardUser )
{
$this->getUser()->signin( $user, true ); // TRUE means "remember me"
$this->setFlash('notice', 'You are logged in');
$this->forward('user', 'home');
return sfView::SUCCESS;
}



For more details, see [[LINK href="http://trac.symfony-project.org/browser/plugins/sfGuardPlugin/branches/1.3/lib/user/sfGuardSecurityUser.class.php#L78"]]sfGuardPlugin code source[[/LINK]]


Julien

2010-07-26

Joan Teixidó answers:

The RememberMe just register in database a hash to compare with a cookie saved in client (and the IP and user_id too).

So, in JanRain RPX i don't know if you can make a query to database if the actual user has a cookie with the correct hash.

I'm not sure if this can help you

joan

2010-07-27

Loban Rahman answers:

JuG is perfectly right.