Reputation: 13527
I have:
class WebUser extends CWebUser {
private $_balance;
public function getBalance() { return $this->_balance; }
}
The problem is, this getBalance value needs to get updated every time the page is refreshed. But it currently only does this when the user logs in the first time. I will have the same problem if a user gets banned, and he is already logged in.
How do I get around this? In other words, how do I force the stored user states to get refreshed every time the user reloads the page?
Here is the code that sets the actual user:
public function authenticate() {
$api = new api();
$user = $api->getAccountDetailsByCellNr($this->username);
if (empty($user)) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
}
else {
if(!isset($this->username))
$this->errorCode = self::ERROR_USERNAME_INVALID;
else if($user->password !== md5($this->password) )
$this->errorCode = self::ERROR_PASSWORD_INVALID;
else {
$this->errorCode = self::ERROR_NONE;
$this->setState('balance', $user->balance);
}
}
Upvotes: 0
Views: 391
Reputation: 1136
Overwrite the init()
function in your WebUser class.
Something like:
class WebUser extends CWebUser {
...
public function init()
{
parent::init();
$user = $api->getAccountDetailsByCellNr($this->username);
$this->_balance = $user->balance;
}
}
Upvotes: 1