first, let's see what happened after logging in.
after
$identity->authenticate();
if
$identity->errorCode===UserIdentity::ERROR_NONE
then we will send the login action
Yii::app()->user->login($identity,$duration)
and what kind of login?
I am scanning the yii source the main idea is
$this->changeIdentity($id,$identity->getName(),$states);
in the entry function to the CWebUser class.
below is the changeIdentity function
protected function changeIdentity($id,$name,$states)
{
Yii::app()->getSession()->regenerateID(true);
$this->setId($id);
$this->setName($name);
$this->loadIdentityStates($states);
}
secondly: stop about the problem
Yii::app()->user->id;
, getId() , CWebUser, ( )/protected/config/main.php :
'components'=>array(
'user'=>array(
'class'=>'WebUser',
'allowAutoLogin'=>true,
),
CWebUser - WebUser.
WebUser getId(), CWebUser, WebUser CWebUser. getId() CWebUser.
https://github.com/yiisoft/yii/blob/1.1.13/framework/web/auth/CWebUser.php#LC287
public function getId()
{
return $this->getState('__id');
}
, "__id" ?
, :
$this->setId($id);
$id?
CWebUser:
public function login($identity,$duration=0)
{
$id=$identity->getId();
$states=$identity->getPersistentStates();
if($this->beforeLogin($id,$states,false))
{
$this->changeIdentity($id,$identity->getName(),$states);
if($duration>0)
{
if($this->allowAutoLogin)
$this->saveToCookie($duration);
else
throw new CException(Yii::t('yii','{class}.allowAutoLogin must be set true in order to use cookie-based authentication.',
array('{class}'=>get_class($this))));
}
$this->afterLogin(false);
}
return !$this->getIsGuest();
}
$id = $identity->getId();
getId $idenity, , getId
UserIdentity, CUserIdentity, :
public function getId()
{
return $this->_id;
}
public function setId($id)
{
$this->_id = $id;
return;
}
user_id setId ($ id) UserIdentity, CUserIdentity, : () {
$record=User::model()->findByAttributes(array('user_name'=>$this->username));
if($record===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if($record->password!==md5($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->setId($record->user_id);
$this->errorCode=self::ERROR_NONE;
}
return !$this->errorCode;
}