title: how to create logged in session in yii
body: <p>i tried using hybrid auth for a facebook login on my yii app, but couldn't get it to work. so decided to work on my own. i managed to get it to retrieve data and store it in my DB. but yii, still doesn't detect user as logged in. here is part of my code in my <strong>controllers/FacebookController.php</strong></p>
  
  <pre><code>    if (app()-&gt;request-&gt;isAjaxRequest) {
  
              $user = app()-&gt;request-&gt;getParam('user');
  
              Shared::debug($user);
  // verify one last time that facebook knows this guy
       if ($user['id'] === app()-&gt;facebook-&gt;getUser()) {
  
                      if (!empty($user['email']))
                      {
                          $model = User::model()-&gt;findByEmail($user['email']);
                      }   
                      else if (!empty($user['username']) &amp;&amp; empty($user['email'])) //incase we don't get an email, we use a facebook email
                      {
                          $email = $user['username'].'@facebook.com';
                          $model = User::model()-&gt;findByEmail($email);
                      }
                      else 
                      {
                          $model = false;
                      }
  
                      if (!empty($model)) 
                      {
  
                          // facebook email matches one in the user database
                          $identity = new UserIdentity( $model-&gt;email , null );
                          $identity-&gt;_ssoAuth = true;
                          $identity-&gt;authenticate();
                          if ($identity-&gt;errorCode === UserIdentity::ERROR_NONE) {
                              print_r($identity);
                              app()-&gt;user-&gt;login($identity, null);
                              echo json_encode(array('error' =&gt; false, 'success' =&gt; url('/')));
                              app()-&gt;end();
                          } 
                          else {
                              echo json_encode(array('error' =&gt; 'System Authentication Failed', 'code' =&gt; 'auth'));
                              app()-&gt;end();
                          }
                      } 
  </code></pre>
  
  <p>in my code above, when i <code>print_r($identity);</code> the object below is echoed. and FYI, the email <code>xxxxxx@facebook.com</code> is stored in the DB but <code>app()-&gt;user-&gt;isGuest()</code> still returns true. what am i doing wrong here?</p>
  
  <pre><code>UserIdentity Object
  (
      [_ssoAuth] =&gt; 1
      [_id:UserIdentity:private] =&gt; 19
      [username] =&gt; xxxxxx@facebook.com
      [password] =&gt; 
      [errorCode] =&gt; 0
      [errorMessage] =&gt; 
      [_state:CBaseUserIdentity:private] =&gt; Array
          (
          )
  
      [_e:CComponent:private] =&gt; 
      [_m:CComponent:private] =&gt; 
  )
  </code></pre>