public function authenticate() { $record = User::model()->find('user_name=:username and not_login=0', array(':username' => $this->username)); if ($record === null) { $this->errorCode = self::ERROR_USERNAME_INVALID; } else { if ($record->password !== crypt($this->password, $record->password)) { $this->errorCode = self::ERROR_PASSWORD_INVALID; } else { $this->_id = $record->id; foreach ($record as $k => $v) { $this->setState($k, $v); } //更新user_online表 if (!($userOnline = UserOnline::model()->findByPk($record->id))) { $userOnline = new UserOnline(); } $userOnline->setAttributes(array('id' => $record->id, 'time' => time(), 'sid' => Yii::app()->session->sessionId)); $userOnline->save(); // SysLog::model()->createLog($record->id); $this->errorCode = self::ERROR_NONE; } } //var_dump($this->errorCode); return !$this->errorCode; }
public function updateCurrentUserStatus() { $userId = Yii::app()->user->id; if ($userId) { $model = $this->findByPk($userId); if (!$model) { $model = new UserOnline(); $model->setAttributes(array('id' => $userId, 'time' => time(), 'sid' => Yii::app()->session->sessionId)); } else { $model = new UserOnline(); $model->setAttributes(array('id' => $userId, 'time' => time(), 'sid' => Yii::app()->session->sessionId)); } $model->save(); } }
$renderer->assign('active_pet', $Pet); } // end if cookies are set $renderer->assign('logged_in', $logged_in); // Handle the online status of this client. $online = new UserOnline($db); if ($logged_in == true) { $online = $online->findOneByUserId($User->getUserId()); } else { $online = $online->findOneByClientIp($_SERVER['REMOTE_ADDR']); } // end is a guest // If the user/guest was not found as online, recreate the instance and // we're all set. Otherwise, we have the appropriate instance loaded and // ready for updating. if ($online == null) { $online = new UserOnline($db); } // Add the correct stuff and save. if ($logged_in == true) { $online->setUserType('user'); $online->setUserId($User->getUserId()); } else { $online->setUserType('guest'); $online->setClientIp($_SERVER['REMOTE_ADDR']); } // end guest $online->setClientUserAgent($_SERVER['HTTP_USER_AGENT']); $online->setDatetimeLastActive($online->sysdate()); $online->save();