From 533fcaa4982f51298a6e6dd100d9ce27b676e077 Mon Sep 17 00:00:00 2001 From: Sisi Date: Sat, 7 Mar 2026 21:14:50 +0100 Subject: [PATCH] ai added simple ui for register and login --- .idea/.gitignore | 10 +++++ .idea/laravel-idea.xml | 22 +++++++++++ .idea/modules.xml | 8 ++++ .idea/php-com-cen.iml | 29 +++++++++++++++ .idea/php.xml | 45 +++++++++++++++++++++++ .idea/vcs.xml | 6 +++ src/Http/LoginController.php | 65 ++++++++++++++++++++++++++++++++- src/Http/RegisterController.php | 60 +++++++++++++++++++++++++++++- src/Http/Utils.php | 5 +++ 9 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/laravel-idea.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/php-com-cen.iml create mode 100644 .idea/php.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/laravel-idea.xml b/.idea/laravel-idea.xml new file mode 100644 index 0000000..a1cfe2f --- /dev/null +++ b/.idea/laravel-idea.xml @@ -0,0 +1,22 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..68fb876 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php-com-cen.iml b/.idea/php-com-cen.iml new file mode 100644 index 0000000..7dd7874 --- /dev/null +++ b/.idea/php-com-cen.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..e8a70d4 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Http/LoginController.php b/src/Http/LoginController.php index 5a269ec..c5ec091 100644 --- a/src/Http/LoginController.php +++ b/src/Http/LoginController.php @@ -13,10 +13,17 @@ class LoginController implements HttpServerInterface public function onOpen(ConnectionInterface $conn, RequestInterface $request = null): void { $params = []; + parse_str($request->getUri()->getQuery(), $params); + + if (empty($params["username"]) && empty($params["password"])) { + Utils::respondHtml($conn, $this->loginPage()); + $conn->close(); + return; + } + $login = true; $responseHead = ""; $json = ""; - parse_str($request->getUri()->getQuery(), $params); $username = $params["username"]; $password = $params["password"]; @@ -49,6 +56,62 @@ class LoginController implements HttpServerInterface $conn->close(); } + private function loginPage(): string + { + return <<<'HTML' + + + + + Login — ComCen + + + +

Login

+ + + +
+
+

Your token (paste into chat):

+ +
+

No account? Register

+ + + +HTML; + } + public function onMessage(ConnectionInterface $from, $msg): void {} public function onClose(ConnectionInterface $conn): void {} public function onError(ConnectionInterface $conn, \Exception $e): void { $conn->close(); } diff --git a/src/Http/RegisterController.php b/src/Http/RegisterController.php index 09c1a81..b3999c9 100644 --- a/src/Http/RegisterController.php +++ b/src/Http/RegisterController.php @@ -12,10 +12,17 @@ class RegisterController implements HttpServerInterface public function onOpen(ConnectionInterface $conn, RequestInterface $request = null): void { $params = []; + parse_str($request->getUri()->getQuery(), $params); + + if (empty($params["username"]) && empty($params["password"])) { + Utils::respondHtml($conn, $this->registerPage()); + $conn->close(); + return; + } + $createAccount = true; $responseHead = ""; $json = ""; - parse_str($request->getUri()->getQuery(), $params); $username = $params["username"]; $password = $params["password"]; @@ -53,6 +60,57 @@ class RegisterController implements HttpServerInterface $conn->close(); } + private function registerPage(): string + { + return <<<'HTML' + + + + + Register — ComCen + + + +

Register

+ + + +
+

Already have an account? Login

+ + + +HTML; + } + public function onMessage(ConnectionInterface $from, $msg): void {} public function onClose(ConnectionInterface $conn): void {} public function onError(ConnectionInterface $conn, \Exception $e): void { $conn->close(); } diff --git a/src/Http/Utils.php b/src/Http/Utils.php index 1f7c98c..c777814 100644 --- a/src/Http/Utils.php +++ b/src/Http/Utils.php @@ -10,4 +10,9 @@ class Utils { $conn->send("HTTP/1.1 {$head}\r\nContent-Type: application/json\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}"); + } } \ No newline at end of file