public function login(sfAuthUser $user, $remember = false) { $context = sfContext::getInstance(); $sfUser = $context->getUser(); $request = $context->getRequest(); $response = $context->getResponse(); $credentials = $user->getAllCredentials(); $sfUser->setAttribute('user_id', $user->getId(), 'sfAuthUser'); $sfUser->setAuthenticated(true); $sfUser->clearCredentials(); $sfUser->addCredentials($user->getAllCredentials()); if ($remember) { //generate a hash for the remember_me_hash column $user->setRememberMeHash(sfAuthUtil::getHashedPasswordBySaltAndString($user->getUsername(), 'cookie')); //Configuration vars $expire = sfConfig::get('app_sf_auth_plugin_cookie_expire', 1209600) + time(); $cookie_name = sfConfig::get('app_sf_auth_plugin_cookie_name', 'sfAuthUserCookie'); //if the cookie already exists destroy it. if ($request->getCookie($cookie_name)) { $response->setCookie($cookie_name, '', time() - 3600); } $response->setCookie($cookie_name, $user->getRememberMeHash(), $expire); $user->save(); } //Event dispatcher the user have logged in... Useful for setting Culture //etc when a user have logged in that may recide in another table $this->dispatcher->notify(new sfEvent($this, 'sf_auth.login')); }