Erorr In Login Functions !

[b]Hi All

I have problem in login area when I login in correct email and username related to database , will access without any problem ,

But when I write wrong email or password I have this error message !

Can Any one help me ?

Thanks in advance [/b]

UserIdentity .php




<?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

{


	 // Need to store the user's ID:

	 private $_id;

 	public $password;

 	public $status;




	/**

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

	{

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


		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->status);

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

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

		}

		return !$this->errorCode;

	}

	

	public function getId()

	{

	 return $this->_id;

	}


	

}




LoginForm





<?php


/**

 * LoginForm class.

 * LoginForm is the data structure for keeping

 * user login form data. It is used by the 'login' action of 'SiteController'.

 */

class LoginForm extends CFormModel

{

	public $email;

	public $password;

	public $login;


	/**

	 * Declares the validation rules.

	 * The rules state that username and password are required,

	 * and password needs to be authenticated.

	 */

public function rules()

{

	return array(

		array('email, password', 'required'),

		array('email', 'email'),

		array('password', 'authenticate'),

	);

}


	/**

	 * Declares attribute labels.

	 */

	public function attributeLabels()

	{

		return array(

			'email'=>'Email Address',

		);

	}


	/**

	 * Authenticates the password.

	 * This is the 'authenticate' validator as declared in rules().

	 */

	public function authenticate($attribute,$params)

	{

		if(!$this->hasErrors())  // we only want to authenticate when no input errors

		{

			$identity=new UserIdentity($this->email,$this->password);

			$identity->authenticate();

			switch($identity->errorCode)

			{

				case UserIdentity::ERROR_NONE:

					Yii::app()->user->login($identity);

                	

					break;

				case UserIdentity::ERROR_USERNAME_INVALID:

					$this->addError('email','Email address is incorrect.');

					break;

				default: // UserIdentity::ERROR_PASSWORD_INVALID

					$this->addError('password','Password is incorrect.');

					break;

			}

		}

	}

}




SiteController




 	* Displays the login page

	 */

	public function actionLogin()

	{

		$model=new LoginForm;


		// if it is ajax validation request

		if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}


		// collect user input data

		if(isset($_POST['LoginForm']))

		{

			$model->attributes=$_POST['LoginForm'];

			// validate user input and redirect to the previous page if valid

        	

        	

        	$username=$_POST['LoginForm']['email'];

        	$password=$_POST['LoginForm']['password'];

			if($model->validate())

      	

        	$identity=new UserIdentity($username,$password);

        	if($identity->authenticate()){

          	//  $identity=new UserIdentity($username,$password);

            	$this->redirect(Yii::app()->user->returnUrl);

        	}

        	else

        	{

         	

            	$this->redirect(Yii::app()->user->returnUrl);

        	}

        	

				

		}

		// display the login form

		$this->render('login',array('model'=>$model));

	}










$identity=new UserIdentity($username,$password);

        	if($identity->authenticate()){

          	//  $identity=new UserIdentity($username,$password);



remove these lines, this is already doing in login().

Exactly that is my problem , Thank you so much Rajith R

[b]

[/b]

use like this




if($model->validate() && $model->login())

			{

				$this->redirect(Yii::app()->user->returnUrl);

				

			}



thank you I fixed it .