user identity constants

Hi, aside from these constants from UserIdentity class

ERROR_USERNAME_INVALID;

ERROR_PASSWORD_INVALID;

ERROR_NONE;

  1. aren’t there any other constants that are built in?

  2. where should I define my own ERROR_CONSTANTS if it’s allowed to do that ?

my main objective is, throw a warning to the user when he attempts to log-in if his account is not yet

activated, I have a column that is set to 1 if he clicks the activation link from email

and is 0 if link is untouched.

apparently this is what I have in my UserIdentity class




	public function authenticate()

	{


		$record = Wsmembers::model()->findByAttributes(array('LoginName' => $this->username));

		if($record === null)

			$this->errorCode = self::ERROR_USERNAME_INVALID;

		else if($record->LoginPassword !== sha1($this->password))

			$this->errorCode = self::ERROR_PASSWORD_INVALID;

		else 

		{

			$this->_id = $record->MemberShipID;

			$this->setState('name', $record->LoginName);

			$this->errorCode = self::ERROR_NONE;

		}

		return !$this->errorCode;

	}



Kindly throw some of things you think is best approach in my objective thanks :D

Extend CUserIdentity by creating a new class, like this:




class MyUserIdentity extends CUserIdentity

{


   const ERROR_NOT_ACTIVATED = 3;


}



Now you can use MyUserIdentity with the new constant.

what i did now is update my UserIdentity class into this,




        const ERROR_EMAIL_INACTIVE = 0;    


        public function authenticate()

        {


                $record = Wsmembers::model()->findByAttributes(array('LoginName' => $this->username));

                $email = Wsmembers::model()->findByAttributes(array('WSEmailConfirmed' => 0));

                if($record === null)

                        $this->errorCode = self::ERROR_USERNAME_INVALID;

                else if($record->LoginPassword !== sha1($this->password))

                        $this->errorCode = self::ERROR_PASSWORD_INVALID;

                else if($email === 0)

                        $this->errorCode = self::ERROR_EMAIL_INACTIVE;

                else 

                {

                        $this->_id = $record->MemberShipID;

                        $this->setState('name', $record->LoginName);

                        $this->errorCode = self::ERROR_NONE;

                }

                return !$this->errorCode;

        }



and then I added an "if" to the loginform model




	public function login()

	{

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

		{

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

			$this->_identity->authenticate();

		}

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

		{

			$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;



but when i login in using the not yet activated account…it gets redirected back to the home page lol ,

how will I add the an error message like “Hey your email is not yet activated” and the login page won’t go away?

For the constant you should use another value, see the reserved values here. 0 means no error. So use 3 :)

Within the login form model you can add errors to the form:




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

                {

                        $this->addError('username','Account is not activated yet!');

                }



problem solved, thanks :)