User Identity

hi…i am new Babie to yii…userIdentity does not work

this function in login Form does not called…

$this->_identity=new UserIdentity($this->username,$this->password);

<?php

/**

  • UserIdentity represents the data needed to identity a user.

  • It contains the authentication method that checks if the provided

  • data can identity the user.

*/

class UserIdentity extends CUserIdentity

{

/**


 * Authenticates a user.


 * The example implementation makes sure if the username and password


 * are both 'demo'.


 * In practical applications, this should be changed to authenticate


 * against some persistent user identity storage (e.g. database).


 * @return boolean whether authentication succeeds.


 */

/*

public function authenticate()


{


	&#036;users=array(


		// username =&gt; password


		'demo'=&gt;'demo',


		'admin'=&gt;'admin',


	);


	if(&#33;isset(&#036;users[&#036;this-&gt;username]))


		&#036;this-&gt;errorCode=self::ERROR_USERNAME_INVALID;


	elseif(&#036;users[&#036;this-&gt;username]&#33;==&#036;this-&gt;password)


		&#036;this-&gt;errorCode=self::ERROR_PASSWORD_INVALID;


	else


		&#036;this-&gt;errorCode=self::ERROR_NONE;


	return &#33;&#036;this-&gt;errorCode;


}

*/

private $_id;

public function authenticate()

{

&#036;record=Trainer::model()-&gt;findByAttributes(array('email'=&gt;&#036;this-&gt;username));  // here I use Email as user name which comes from database


   if(&#036;record===null)


           {


                   &#036;this-&gt;_id='user Null';


                               &#036;this-&gt;errorCode=self::ERROR_USERNAME_INVALID;


           }


   else if(&#036;record-&gt;password&#33;==&#036;this-&gt;password)            // here I compare db password with passwod field


           {        &#036;this-&gt;_id=&#036;this-&gt;username;


                  // &#036;this-&gt;errorCode=self::ERROR_PASSWORD_INVALID;


           }


     else if(&#036;record['status']&#33;=='Active')                //  here I check status as Active in db


           {        


                                    &#036;err = &quot;You have been Inactive by Admin.&quot;;


                            &#036;this-&gt;errorCode = &#036;err;


           }


    


   else


   {  


      &#036;this-&gt;_id=&#036;record['id'];


       Yii::app()-&gt;session['sUserId'] = &#036;this-&gt;_id;


       Yii::app()-&gt;session['sEmail'] = ucwords(&#036;record-&gt;email);


        Yii::app()-&gt;session['mode'] = &quot;trainer&quot;;


       &#036;this-&gt;setState('id', &#036;record['id']);


       &#036;this-&gt;errorCode=self::ERROR_NONE;


        


   }


   return &#33;&#036;this-&gt;errorCode;

}

public function getId() // override Id

{

   return &#036;this-&gt;_id;

}

}

please help me

Getting idea from these below wiki links -

http://www.yiiframework.com/wiki/724/disallowing-login-for-inactive-users-in-yii/

http://www.yiiframework.com/wiki/742/how-to-get-store-last-login-datetime-in-database/

compare your userIdentity.php file source code also i suggest to you not need to session, even you can use setState.

like -

http://www.yiiframework.com/doc/api/1.1/CUserIdentity

http://www.yiiframework.com/doc/api/1.1/CBaseUserIdentity#setState-detail