useridentity setState default?

In protected/models/useridentity.php I have




class UserIdentity extends CUserIdentity

{

	private $_id = 0;


	public function authenticate()

	{

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

		

		if ($user===null) 

		{ 

			// No user found!

			$this->errorCode=self::ERROR_USERNAME_INVALID;

		} 

		// md5 encryption

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

		{ 

			// Invalid password!

			$this->errorCode=self::ERROR_PASSWORD_INVALID;

		}		

		else

		{

			// No error

			Yii::app()->setLanguage($user->locale->code);			

			$this->setState('superuser', $user->superuser);			

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

			$this->errorCode=self::ERROR_NONE;

			

		}

		return !$this->errorCode;


	}

	

    public function getId()

    {

        return $this->_id;

    }	


}



If a user hasn’t logged in, then Yii::app()->user->superuser property isn’t available. Whats the best way around this?

Many thanks, Russ

You can create a getter method:


public function getSuperUser()

{

    if ($this->hasState('superuser'))

       return $this->getState('superuser');

    else 

       return 'user not authenticated';

}

Thank you for the fast reply!! :D

Put this in the UserIdentity model and works perfectly - just changed the ‘user not authenticated’ to 0

Yeah! you are welcome!