Yii Login Message


When we login in yii, we will get the error message only for "username" and "password". Now I added to code here to set and get more error message in yii login form.

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
{
    private $_id;
    const ERROR_ACCOUNT_INACTIVE=1;    
    const ERROR_ACCOUNT_VERIFY=2;
    
    public function authenticate()
    {  
        $users=User::model()->find(array('condition'=>'username="'.$this->username.'" and password="'.sha1($this->password).'"'));       
        if($users==null){
            $this->errorCode=self::ERROR_USERNAME_INVALID;
        }else{
            if($users->isactive=='' || $users->isactive==null){
                $this->errorCode=self::ERROR_ACCOUNT_INACTIVE;                            
            }else if($users->verfiy==0 && $users->verfiy==null){
                $this->errorCode=self::ERROR_ACCOUNT_VERIFY;                        
            }else{
                $this->_id=$users->userid;
                $this->setState("username",$users->username);
                $this->setState("accesslevel",'user');
                $this->errorCode=self::ERROR_NONE;            
            }
        }      
        return !$this->errorCode;
    }
	
    public function getId()
    {
        return $this->_id;
    }
}
?>

LoginForm.php


/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute,$params)
{
    if(!$this->hasErrors())
    {    
        $this->_identity=new UserIdentity($this->username,$this->password);
        if(!$this->_identity->authenticate()){
            switch($this->_identity->errorCode){
                case(UserIdentity::ERROR_USERNAME_INVALID):
                    $this->addError('password','Incorrect username or password.');
                    break;
                case(UserIdentity::ERROR_ACCOUNT_VERIFY):
                    $this->addError('password',"Please verify your account");
                    break;                    
                case(UserIdentity::ERROR_ACCOUNT_INACTIVE):
                    $this->addError('password','Looks like your account is still to be activated');
                    break;
            }                  
        }   
    }
}

/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function login()
{
    if($this->_identity===null)
    {
        $this->_identity=new UserIdentity($this->username,$this->password);
        $this->_identity->authenticate();
    }
    if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
    {
        $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
        Yii::app()->user->login($this->_identity,$duration);
        return true;
    }
    else
        return false;
}