Role based login

I have common login table for admin, manager, sales engineer ie(role=>1=admin,2=manager,3=sales engineer) i have three modules i want to allow manager to perform login in manager module and admin to admin model and so… how should i perform this i followed the bellow code im able to restrict user but i unable to show the specified error ie(Your not allowed to perform this login) , thanks in advance

if ($user === null)

    {


        $this->errorCode = self::ERROR_USERNAME_INVALID;


    }





    else if (md5(trim($this->password)) !== trim($user->password)) {


        $this->errorCode = self::ERROR_PASSWORD_INVALID;


    } 


    else if($user->role!=2)


    {


        $this->errorCode='Your not allowed to perform this login';


    }

try:




$this->addError('userName','Your not allowed to perform this login');



Im getting this error

CException

Description

UserIdentity does not have a method named "addError".

This is the solution

====================

In userIdentity

================

const ERROR_USER_TYPE = 1;

public function authenticate() {


  //print_r($this);


     $user = User::model()->find('LOWER(user_name)=?', array(strtolower($this->username)));





    if ($user === null)


    {


        $this->errorCode = self::ERROR_USERNAME_INVALID;


    }





    else if (md5(trim($this->password)) !== trim($user->password)) {


        $this->errorCode = self::ERROR_PASSWORD_INVALID;


    } 


    [b]else if($user->role!=2)


    {


        $this->errorCode=self::ERROR_USER_TYPE;


    }[/b]

else {

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


        $this->_userType = 2;


        $this->username = $user->user_name;


        $this->errorCode = self::ERROR_NONE;


    }


    return!$this->errorCode;


}

In Login

==========

public function authenticate($attribute,$params)

{


       


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


	if(!$this->_identity->authenticate())


		$this->addError('password','Incorrect username or password.');


            if($this->_identity->errorCode===UserIdentity::ERROR_USER_TYPE)


            {


                    $this->addError('username','You are not a valid user!');


            }


}

Of corse, userIdentity is not a CModel!!

Sorry for the bad advice, and thank you a lot for sharing this solution!

I need another one help

else {

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

$this->_userType = 2;

$this->username = $user->user_name;

$this->errorCode = self::ERROR_NONE;

}

how could i refer the value userType in another forms after login

eg(Yii::app()->user->id) what i should do to take user type and name?