/**
  * Signs in the user on the application.
  *
  * @param sfGuardUser $user The sfGuardUser id
  * @param boolean $remember Whether or not to remember the user
  * @param Doctrine_Connection $con A Doctrine_Connection object
  */
 public function signIn($user, $remember = false, $con = null)
 {
     // signin
     $this->setAttribute('user_id', $user->getId(), 'sfGuardSecurityUser');
     $this->setAuthenticated(true);
     $this->clearCredentials();
     $this->addCredentials($user->getAllPermissionNames());
     // save last login
     $user->setLastLogin(date('Y-m-d H:i:s'));
     $user->save($con);
     // remember?
     if ($remember) {
         $expiration_age = sfConfig::get('app_sf_guard_plugin_remember_key_expiration_age', 15 * 24 * 3600);
         // remove old keys
         Doctrine::getTable('sfGuardRememberKey')->createQuery()->delete()->where('created_at < ?', date('Y-m-d H:i:s', time() - $expiration_age))->execute();
         // remove other keys from this user
         Doctrine::getTable('sfGuardRememberKey')->createQuery()->delete()->where('user_id = ?', $user->getId())->execute();
         // generate new keys
         $key = $this->generateRandomKey();
         // save key
         $rk = new sfGuardRememberKey();
         $rk->setRememberKey($key);
         $rk->setsfGuardUser($user);
         $rk->setIpAddress($_SERVER['REMOTE_ADDR']);
         $rk->save($con);
         // make key as a cookie
         $remember_cookie = sfConfig::get('app_sf_guard_plugin_remember_cookie_name', 'sfRemember');
         sfContext::getInstance()->getResponse()->setCookie($remember_cookie, $key, time() + $expiration_age);
     }
 }
 /**
  * Signs in the user on the application.
  *
  * @param sfGuardUser $user The sfGuardUser id
  * @param boolean $remember Whether or not to remember the user
  * @param Doctrine_Connection $con A Doctrine_Connection object
  */
 public function signIn($user, $auth_key = null, $con = null)
 {
     // signin
     $this->setApiUserid($user->getId());
     $this->setAuthenticated(true);
     $this->clearCredentials();
     $this->addCredentials($user->getAllPermissionNames());
     // save last login
     $user->setLastLogin(date('Y-m-d H:i:s'));
     $user->save($con);
     // Set login messages
     $message = array();
     foreach ($user->getUndisplayedLoginMessages() as $message) {
         $messages[] = $message->getMessage();
         $message->setDisplayed(true);
         $message->save();
     }
     if (count($message) > 0) {
         $this->setFlash('login', $messages);
     }
     // remember?
     if ($auth_key) {
         $this->setApiAuthkey($auth_key);
         $api_key = sfConfig::get('app_web_app_api_key');
         $api = ApiKeyTable::getInstance()->findOneBy('api_key', $api_key);
         $auth_key = sfGuardUserAuthKeyTable::getInstance()->getMostRecentValidByApiKeyIdAndAuthKey($api->getIncremented(), $auth_key);
         $expires = strtotime($auth_key->getExpiresAt());
         // make key as a cookie
         $remember_cookie = sfConfig::get('app_sf_guard_plugin_remember_cookie_name', 'sfRemember');
         sfContext::getInstance()->getResponse()->setCookie($remember_cookie, $auth_key->getAuthKey(), $expires);
     }
 }
 /**
  * Signs in the user on the application.
  *
  * @param sfGuardUser $user The sfGuardUser id
  * @param boolean $remember Whether or not to remember the user
  * @param Doctrine_Connection $con A Doctrine_Connection object
  */
 public function signIn($user, $remember = false, $con = null)
 {
     // signin
     $this->setAttribute('user_id', $user->getId(), 'sfGuardSecurityUser');
     $this->setAuthenticated(true);
     $this->clearCredentials();
     $this->addCredentials($user->getAllPermissionNames());
     // save last login
     $user->setLastLogin(date('Y-m-d H:i:s'));
     $user->save($con);
     // remember?
     if ($remember) {
         $expiration_age = sfConfig::get('app_sf_guard_plugin_remember_key_expiration_age', 15 * 24 * 3600);
         // remove old keys
         Doctrine_Core::getTable('sfGuardRememberKey')->createQuery()->delete()->where('created_at < ?', date('Y-m-d H:i:s', time() - $expiration_age))->execute();
         // remove other keys from this user
         Doctrine_Core::getTable('sfGuardRememberKey')->createQuery()->delete()->where('user_id = ?', $user->getId())->execute();
         // generate new keys
         $key = $this->generateRandomKey();
         // save key
         $rk = new sfGuardRememberKey();
         $rk->setRememberKey($key);
         $rk->setUser($user);
         $rk->setIpAddress($_SERVER['REMOTE_ADDR']);
         $rk->save($con);
         // make key as a cookie
         $remember_cookie = sfConfig::get('app_sf_guard_plugin_remember_cookie_name', 'sfRemember');
         //My remember cookie MUST depend on the path and in the future it will on the domain as well.
         //FIXME: WHEN HAVING A DOMAIN TO ADD IT HERE AS WELL!!!!
         //       AND THE CONFIGURATION PARAMETER ON /config/app.yml!!!!
         $path = sfConfig::get('app_sf_guard_plugin_remember_cookie_path', '/');
         sfContext::getInstance()->getResponse()->setCookie($remember_cookie, $key, time() + $expiration_age, $path);
     }
 }