diff --git a/web/application/controllers/base.php b/web/application/controllers/base.php index 8e08ef5..0780856 100644 --- a/web/application/controllers/base.php +++ b/web/application/controllers/base.php @@ -11,17 +11,9 @@ abstract class base extends \system\engine\HF_Controller { protected $sessionData = null; protected $loginRequired = true; protected $sessionRequired = true; - protected function isLoggedIn() { - if (!$this->sessionData && !isset($this->sessionData->userId)) { - header("Location: /login"); - return false; - } else { - return true; - } - } protected function loadRender($template, $parameters=array()) { - $newParameters = array_merge($parameters, ["session" => $this->sessionData, "config" => $this->config, "user" => $this->user]); + $newParameters = array_merge($parameters, ["session" => $this->session, "config" => $this->config, "user" => $this->user]); return parent::loadRender($template, $newParameters); } @@ -40,6 +32,7 @@ abstract class base extends \system\engine\HF_Controller { $this->session->ip = $_SERVER["REMOTE_ADDR"]; $this->session->userAgent = $_SERVER["HTTP_USER_AGENT"]; $this->session->sessionid = $sessionId; + $this->session->random = 0; $this->session->save(); setcookie("session", $sessionId, 2147483647, "/"); } @@ -50,6 +43,7 @@ abstract class base extends \system\engine\HF_Controller { $this->session->ip = $_SERVER["REMOTE_ADDR"]; $this->session->userAgent = $_SERVER["HTTP_USER_AGENT"]; $this->session->sessionid = $sessionId; + $this->session->random = 0; $this->session->id = $this->session->save(); setcookie("session", $sessionId, 2147483647, "/"); } diff --git a/web/application/controllers/main.php b/web/application/controllers/main.php index bf373de..2448cbe 100644 --- a/web/application/controllers/main.php +++ b/web/application/controllers/main.php @@ -53,6 +53,15 @@ class main extends base } } + public function togglerandom() { + if ($_POST["random"] == "true") { + $this->session->random = 1; + } else { + $this->session->random = 0; + } + $this->session->save(); + } + public function send() { $message = new application\models\Messages(); $message->user_from = $this->session->id; @@ -127,7 +136,7 @@ class main extends base } // If no match was made - match with first session - if ($firstResult && !$result) { + if ($firstResult && !$result && $this->session->random) { $firstResult->waiting = 0; $firstResult->to_user = $this->session->id; $this->session->to_user = $firstResult->id; diff --git a/web/application/migrations/1.php b/web/application/migrations/1.php index 119cf8f..2d7ff98 100644 --- a/web/application/migrations/1.php +++ b/web/application/migrations/1.php @@ -13,5 +13,6 @@ DB::query("CREATE TABLE sessions ( data TEXT, waiting TINYINT(1), to_user INTEGER, - lastPing INTEGER + lastPing INTEGER, + random TINYINT(1) )"); \ No newline at end of file diff --git a/web/application/models/sessions.php b/web/application/models/sessions.php index d4334cc..ee5b427 100644 --- a/web/application/models/sessions.php +++ b/web/application/models/sessions.php @@ -10,6 +10,7 @@ class Sessions extends \system\engine\HF_Model { public $waiting; public $to_user; public $lastPing; + public $random; public function setData($key, $val) { $raw = json_decode($this->data, true); diff --git a/web/application/views/chat.html b/web/application/views/chat.html index 87032ef..b3d44a4 100644 --- a/web/application/views/chat.html +++ b/web/application/views/chat.html @@ -1,16 +1,31 @@ {% extends "base.html" %} {% block content %} - -
- -
- +
+
+ +
+
+ +
+ +