title: Yii user authentication and session not working
body: <p>I am building a website in Yii and I am stuck at the user authentication step. Whatever i do I am not able to authenticate users or store some value in the session.</p>
  
  <p>My UserIdentity component is as follows:</p>
  
  <pre><code>class UserIdentity extends CUserIdentity
  {
      private $_id;
  
      public function authenticate(){
          if(($userRecord = Admin::model()-&gt;findByAttributes(array('username'=&gt;$this-&gt;username)))===null){
              return $this-&gt;errorCode=self::ERROR_USERNAME_INVALID;
          }
          if($userRecord-&gt;password!=hash('sha256', $this-&gt;password)){
              return $this-&gt;errorCode=self::ERROR_PASSWORD_INVALID;
          }
          $this-&gt;_id=$userRecord-&gt;id;
          $this-&gt;setState('title', $userRecord-&gt;username);
          Yii::app()-&gt;session['clientId'] = $userRecord-&gt;clientId;
          Yii::app()-&gt;session['id'] = $userRecord-&gt;id;
          Yii::app()-&gt;session['loggedin'] = true;
  
          return $this-&gt;errorCode=self::ERROR_NONE;
      }
  
      public function getId(){
          return $this-&gt;_id;
      }
  
  }
  </code></pre>
  
  <p>My <code>Yii:app()-&gt;user-&gt;isGuest</code> always returns true and <code>Yii::app()-&gt;user-&gt;id</code> returns nothing. </p>
  
  <p>That is why I tried using <code>Yii::app()-&gt;session['loggedin']</code> to do authentication. But even that is not working. When I access session array like this <code>Yii::app()-&gt;session</code> I get the error <code>Property "CWebUser.session" is not defined.</code>. </p>
  
  <p>This is getting really frustrating. I am new to Yii. Please help.</p>