Есть допустим пользователь, он залогинен. Как только удаляю пользователя (в бд) он по прежнему остаётся залогиненым со своей сессией. Похоже в сессию пишется какая то информация о пользователе (id и имя?). И на её основе определяется является пользователь гостем или нет.
Решения - либо вести учет ID сессий, с которыми пользователь логинился (и, при необходимости, грохать их - например, если хранить в memcached или в db), либо каждый раз проверять пользователя на наличие в БД (отсутствует в БД - делать логаут)
class WebUser extends CWebUser
{
private $_refreshModel = true;
public function getId()
{
$id = parent::getId();
if ($this->_refreshModel) {
$user = User::model()->findByPk($id);
if ($user === null || $user->status != User::STATUS_ACTIVE) {
if ($id !== null) {
$this->logout();
$id = null;
}
} else {
$this->attachBehavior('user', $user);
}
$this->_refreshModel = false;
}
return $id;
}
public function setId($value)
{
$this->_refreshModel = true;
parent::setId($value);
}
public function getName()
{
$id = $this->getId();
if ($id === null) {
return parent::getName();
} else {
return $this->user->username;
}
}
}
User
class User extends CActiveRecord implements IBehavior
{
public function attach($owner)
{
$this->_enabled = true;
}
public function detach($owner)
{
$this->_enabled = false;
}
public function getEnabled()
{
return $this->_enabled;
}
public function setEnabled($value)
{
$value = (bool)$value;
$this->_enabled = $value;
}
}