How To Add More Information To Yii::app()->User

Hello

in this Wiki http://www.yiiframework.com/wiki/6/how-to-add-more-information-to-yii-app-user

we have this code




class UserIdentity extends CUserIdentity

{

    private $_id;

 

    public function authenticate()

    {

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

        if($user===null)

            $this->errorCode=self::ERROR_USERNAME_INVALID;

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

            $this->errorCode=self::ERROR_PASSWORD_INVALID;

        else

        {

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

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

            $this->errorCode=self::ERROR_NONE;

        }

        return !$this->errorCode;

    }

 

    public function getId()

    {

        return $this->_id;

    }

}



I want to know , Just lastLoginTime will save in Cookie if allowAutoLogin==true , Or both $_id and lastLoginTime will save in Cookie if allowAutoLogin==true

I want to create these class

For FrontEnd




class FrontEndIdentity extends CUserIdentity{

 public $isAdmin = false;

}



For Backend




class BackEndIdentity extends CUserIdentity{

  public $isAdmin = true;

}



and in use Yii::app()->user->isAdmin to detect admin , Is it SAFE ??

(I save admin and user information in deferent Database table and may be admin and user have equal ID)

  1. both states will be saved in cookie for auto login

  2. CUserIdentity is NOT what is visible under Yii::app()->user. in order to extend this component and add "isAdmin" attribute you need to to extend also CWebUser and configure applicatio to use instead of the default class.

ok thanks