private function checkSession($user_id, $user_sid, $touch = false)
    {
        $user_id = (int)$user_id;
        if (!defined('USER_ID')) {
            define('USER_ID', $user_id);
        }

        // Prolong session
        if ($touch) {
            $sessions = new UsersSessionEntityRepository();
            $sessions->setWhereSid($user_sid);
            /**
             * @var UsersSessionEntity $session
             */
            $session = $sessions->getFirstObjectFromCollection();
            if ($session) {
                $session->setTs(NOW);
                $session->save();
            }
        }

        // Check session for current user exists
        $sessions = new UsersSessionEntityRepository();
        $sessions->setWhereUserId($user_id);
        $sessions->setWhereSid($user_sid);
        $sessions->addWhereFieldIsHigherOrEqual('ts', NOW - CFG_SESSION_KEEP_ALIVE_SECONDS);

        return $sessions->hasAnyObjectInCollection();
    }