public function actionIndex() { // clear user online list UserOnline::clearList(); // return users, verify force reload. return ['useronline' => UserOnline::getList(), 'forceReload' => Yii::$app->adminuser->identity->force_reload]; }
public function actionIndex($token) { if (empty(Yii::$app->remoteToken) || sha1(Yii::$app->remoteToken) !== $token) { throw new Exception('Wrong token'); exit; } return ['yii_version' => Yii::getVersion(), 'luya_version' => Module::VERSION, 'app_title' => Yii::$app->siteTitle, 'app_debug' => (int) YII_DEBUG, 'app_env' => YII_ENV, 'app_transfer_exceptions' => (int) Yii::$app->errorHandler->transferException, 'admin_online_count' => UserOnline::getCount(), 'app_elapsed_time' => Yii::getLogger()->getElapsedTime()]; }
public static function clearList() { $time = time(); $items = UserOnline::find()->where('last_timestamp <= ' . ($time - 30 * 60))->all(); foreach ($items as $model) { $model->delete(); } }
/** * see if the user id matches against the moduleName, controllerName, actionName inside of the rights database. * * @param string $moduleName Module Name * @param string $controllerName The name of the controller without suffix "Controller" * @param string $actionName The name of the action without prefix "action"; * * @return bool */ public function matchRoute($userId, $route) { UserOnline::refreshUser($userId, $route); $groups = Yii::$app->db->createCommand('SELECT * FROM admin_user_group AS t1 LEFT JOIN(admin_group_auth as t2 LEFT JOIN (admin_auth as t3) ON (t2.auth_id = t3.id)) ON (t1.group_id=t2.group_id) WHERE t1.user_id=:user_id AND t3.route=:route')->bindValue('user_id', $userId)->bindValue('route', $route)->queryAll(); if (is_array($groups) && count($groups) > 0) { return true; } return false; }
public function login() { if ($this->validate()) { $user = $this->getUser(); $user->scenario = 'login'; $user->auth_token = \yii::$app->security->hashData(\yii::$app->security->generateRandomString(), $user->password_salt); $user->save(); $login = new UserLogin(); $login->setAttributes(["auth_token" => $user->auth_token, "user_id" => $user->id]); $login->insert(); UserOnline::refreshUser($user->id, 'login'); return $user; } else { return false; } }
public function testAddUser() { UserOnline::clearList(0); $this->assertEquals(0, UserOnline::getCount()); UserOnline::refreshUser(1, 'my/test'); // create UserOnline::refreshUser(1, 'my/test'); // refresh $this->assertEquals(1, UserOnline::getCount()); $list = UserOnline::getList(); $this->assertArrayHasKey(0, $list); UserOnline::clearList(0); $this->assertEquals(true, is_array(UserOnline::getList())); $this->assertEquals(0, count(UserOnline::getList())); UserOnline::refreshUser(1, 'my/test'); // create UserOnline::removeUser(1); }
public function login() { if ($this->validate()) { $user = $this->getUser(); $user->detachBehavior('LogBehavior'); $user->scenario = 'login'; $user->force_reload = 0; $user->auth_token = Yii::$app->security->hashData(Yii::$app->security->generateRandomString(), $user->password_salt); $user->save(); $login = new UserLogin(); $login->setAttributes(['auth_token' => $user->auth_token, 'user_id' => $user->id]); $login->insert(); UserOnline::refreshUser($user->id, 'login'); return $user; } else { return false; } }
public function onBeforeLogout() { UserOnline::removeUser($this->getId()); }
public function actionIndex() { UserOnline::clearList(); return UserOnline::getList(); }