From 1bed0e7774b18e0a16658d99580693f9bb681300 Mon Sep 17 00:00:00 2001 From: Tonik Date: Sun, 8 Mar 2026 18:49:35 +0100 Subject: [PATCH] naprawa logiki i update stylu --- bin/WebSocketServer.php | 12 +- public/index.php | 325 ++++++++++++++++++++++++++++------------ src/Http/Utils.php | 11 +- 3 files changed, 245 insertions(+), 103 deletions(-) diff --git a/bin/WebSocketServer.php b/bin/WebSocketServer.php index 35085cd..a194613 100644 --- a/bin/WebSocketServer.php +++ b/bin/WebSocketServer.php @@ -65,7 +65,7 @@ class WebSocketServer implements MessageComponentInterface { $decodedMsg = json_decode($msg, true); if (!$decodedMsg) { - $from->send("{\"error\"}: \"not or empty json\""); + $from->send("{\"error\": \"not or empty json\"}"); return; } $index = $this->getConnectionIndex($from); @@ -75,10 +75,10 @@ class WebSocketServer implements MessageComponentInterface $msgContent = $decodedMsg["message"] ?? null; if ($msgContent) { $this->sendToAllAuthenticated($this->connectionsData[$index]["username"], $msgContent); - $from->send("{\"success\"}: \"message send\""); + $from->send("{\"success\": \"message send\"}"); return; } - $from->send("{\"error\"}: \"no message\""); + $from->send("{\"error\": \"no message\"}"); return; } @@ -87,13 +87,13 @@ class WebSocketServer implements MessageComponentInterface $tokenUser = TokenHandler::getTokenOwnership($token); if ($tokenUser) { $this->connectionsData[$index]["username"] = $tokenUser; - $from->send("{\"success\"}: \"authenticated\""); + $from->send("{\"success\": \"authenticated\"}"); return; } - $from->send("{\"error\"}: \"invalid token\""); + $from->send("{\"error\": \"invalid token\"}"); return; } - $from->send("{\"error\"}: \"you are not authenticated\""); + $from->send("{\"error\": \"you are not authenticated\"}"); } public function onClose(ConnectionInterface $conn): void diff --git a/public/index.php b/public/index.php index 06d61d3..40a2c72 100644 --- a/public/index.php +++ b/public/index.php @@ -7,126 +7,261 @@ use ComCen\Html\Html; $html = new Html(); $html->content = <<<'HTML' - + ComCen -

ComCen

- -
- - +
+

ComCen - Terminal Autoryzacji

+
+
+
+ + +
+ +
+ +

+ +

+ +
+ + + + +
+
-
- -
- - + - + } + - HTML; -$html->renderContent(); +$html->renderContent(); \ No newline at end of file diff --git a/src/Http/Utils.php b/src/Http/Utils.php index c777814..47b2c14 100644 --- a/src/Http/Utils.php +++ b/src/Http/Utils.php @@ -4,15 +4,22 @@ namespace ComCen\Http; use Ratchet\ConnectionInterface; +/* +Access-Control-Allow-Origin: * +zezwala na urzycie portu 8080 +portalowi chodzącemu na porcie 8000 +*/ + + class Utils { static function responeJson(ConnectionInterface $conn, string $head, string $jsonData): void { - $conn->send("HTTP/1.1 {$head}\r\nContent-Type: application/json\r\n\r\n{$jsonData}"); + $conn->send("HTTP/1.1 {$head}\r\nContent-Type: application/json\r\nAccess-Control-Allow-Origin: *\r\n\r\n{$jsonData}"); } static function respondHtml(ConnectionInterface $conn, string $html): void { - $conn->send("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n{$html}"); + $conn->send("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nAccess-Control-Allow-Origin: *\r\n\r\n{$html}"); } } \ No newline at end of file