Disabling User Login

I have a column in my database which indicates if user should be disabled from login or not since I don’t want to delete it from database as user login might be enabled in future. If accessLevel is 4 then user login should be disabled else he should able to login. I have implemented this in following way


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)

		{

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

			if($record->accessLevel == 4)

				return false;

			else

			{

				$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days

				Yii::app()->user->login($this->_identity,$duration);

				return true;

			}

		}

		else

			return false;

	}

So my first question is that if I am doing this in correct way and 2nd question how should I display a particular message to user like "your login has been disabled. contact administrator"?

I’ve done this by adding my own error codes to the UserIdentity class:




class UserIdentity extends CUserIdentity

{

	private $passwordVerifier;

	private $user;


	const ERROR_ACCOUNT_NOT_ACTIVE = 101;

	const ERROR_TOO_MANY_FAILED_LOGINS = 102;


	public function __construct($username, $passwordVerifier)

	{

		$this->passwordVerifier = $passwordVerifier;


		// Leave password blank as it isn't used in verification

		parent::__construct($username, '');

	}


	/**

	 * Authenticates a user.

	 * @return boolean whether authentication succeeds.

	 */

	public function authenticate()

	{

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


		if ($this->user === null)

			$this->errorCode = self::ERROR_USERNAME_INVALID;

		else if (!$this->user->isActive())

			$this->errorCode = self::ERROR_ACCOUNT_NOT_ACTIVE;

		else if ($this->user->tooManyFailedLogins())

			$this->errorCode = self::ERROR_TOO_MANY_FAILED_LOGINS;

		else if ($this->passwordVerifier->getHash() !== $this->user->Password)

			$this->errorCode = self::ERROR_PASSWORD_INVALID;

		else

			$this->errorCode = self::ERROR_NONE;


		return !$this->errorCode;

	}



i think it’s correct way and if you want to display the message using flash

thanks for the replies. I will using flash to display message.