Ask your Symfony questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How can I manually call Remember Me? Symfony


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->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)


JuG answers:


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=""]]sfGuardPlugin code source[[/LINK]]



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



Loban Rahman answers:

JuG is perfectly right.