How To Login With Id Or Email In Yii

Hi All

I posted my problem with full code in stackoverflow site , Please help me .

thanks in advance .

Fixed new Code here .

<?php




/** Ahmad Samilo

 * 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

{


     // Need to store the user's ID:

     private $_id;

 	public $password;

 	public $status;

 	public $session;

 

	/**

     * 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()

	{

	

 

 

  	if(strpos($this->username, '@') == true){

	

   $user = Users::model()->findByAttributes(array('email'=>$this->username));

}


else{

   

   $user = Users::model()->findByAttributes(array('user_id'=>$this->username));

}

 

        	/// set number of faild login

     		$session=new CHttpSession;

     		$session->open();

      	

   		Yii::app()->session['number']= Yii::app()->session['number']+1;

   		$session=Yii::app()->session['number'];

          	/// end 


  	




		if ($user===null) { // No user found!

			$this->errorCode=self::ERROR_USERNAME_INVALID;

		}

 		else if ($user->password !== SHA1($this->password) ) { // Invalid password!

			$this->errorCode=self::ERROR_PASSWORD_INVALID;

        	

        	

    	

    	

    	

 	

 		

		} else { // Okay!

    	

 		

       		

	     	$this->errorCode=self::ERROR_NONE;

			// Store the role in a session:

	     	$this->setState('status', $user->active);

     		

     		$this->setState('id', $user->user_id);

     		$this->setState('name', $user->first_name.' '.$user->last_name);

			$this->_id = $user->user_id;

		}

		return !$this->errorCode;

	}

	

	public function getId()

	{

     return $this->_id;

	}


	

}

Thanks to Asgaroth To fixd my problem .