/** * initialize. * * @internal */ public function __construct() { if (!Session::isLoggedIn()) { exit; } $this->query = Request::getStrParam('q', Request::getStrParam('term')); $this->querySimiliar = strlen($this->query) > 1 ? $this->query . '%' : ''; parent::__construct(); }
/** * Get an update for the current user. */ public function update() { if (!Session::isLoggedIn()) { exit; } header('Content-Type: text/event-stream'); header('Cache-Control: no-cache'); header('Access-Control-Allow-Origin: *'); $lastEventId = floatval(isset($_SERVER['HTTP_LAST_EVENT_ID']) ? $_SERVER['HTTP_LAST_EVENT_ID'] : 0); if ($lastEventId == 0) { $lastEventId = floatval(isset($_GET['lastEventId']) ? $_GET['lastEventId'] : 0); } // 2kB padding for IE // @codingStandardsIgnoreStart # echo ':'.str_repeat(' ', 2048)."\n"; echo 'retry: ' . self::$RETRY * 1000 . PHP_EOL; // event-stream $started = time(); //while (true) { $notification = NotificationBrowser::getNextByUserId(Session::getUserId()); if ($notification !== false) { $data = ['type' => 'notification', 'title' => $notification['title'], 'payload' => $notification['content']]; NotificationBrowser::deleteByPK($notification['id']); $lastEventId++; echo 'id: ' . $lastEventId . PHP_EOL; echo 'data: ' . str_replace("\n", "\ndata: ", json_encode($data)) . PHP_EOL . PHP_EOL; ob_flush(); flush(); // @codingStandardsIgnoreEnd // } elseif ((time() - $started) % self::$KEEP_ALIVE == 0) { // // send keep alive comment // echo ': '.sha1(mt_rand())."\n\n"; } // if (time() - $started > self::$TIMEOUT) { // break; // } // usleep(self::$RETRY * 1000000); //} exit; }
/** * Login user. * * @internal */ public static function login() { $config = self::getConfig(); if (empty($config['login']) || !isset($_COOKIE[$config['login']]) || empty($config['password']) || !isset($_COOKIE[$config['password']])) { // return if no login cookie set return; } if (!Session::isLoggedIn()) { // try to login $user_id = User::getIdByCredentials($_COOKIE[$config['login']], $_COOKIE[$config['password']], true); if ($user_id !== false) { $_SESSION['thisuser'] = User::getByPk($user_id); Logger::getInstance()->info("login with cookies"); LogEvent::add(['event' => 'Login.Cookie.Success', 'user_id' => $user_id, 'reference_parameters' => json_encode([]), 'description' => $_SESSION['thisuser']['name'] . ' logged in (über Cookies)']); } else { LogEvent::add(['event' => 'Login.Cookie.Failed', 'user_id' => 0, 'reference_parameters' => json_encode([]), 'description' => $_COOKIE[$config['login']] . ' hat sich vergeblich versucht einzuloggen (über Cookies)']); self::deleteLoginCookie(); } } else { // renew Logger::getInstance()->info("renew login cookie"); self::setLoginCookie($_COOKIE[$config['login']], $_COOKIE[$config['password']]); } }