From 0356e455e6ae7f92d7285cb94f1829b44b3b99ab Mon Sep 17 00:00:00 2001 From: Yarcio Date: Wed, 28 May 2025 21:17:23 +0200 Subject: [PATCH] sync --- index.php | 61 +++++++++++++++++++++++++++++++++++++ login/index.php | 37 ++++++++++++++++++++++ login/login.css | 11 +++++++ login/login.js | 41 +++++++++++++++++++++++++ login/login.php | 28 +++++++++++++++++ login/register/index.php | 37 ++++++++++++++++++++++ login/register/register.js | 45 +++++++++++++++++++++++++++ login/register/register.php | 32 +++++++++++++++++++ main.sql | 1 + menu.css | 31 +++++++++++++++++++ php/functions.php | 19 ++++++++++++ php/pages.php | 6 ++++ php/scripts.php | 6 ++++ single/index.php | 25 +++++++++++++++ styles/main.css | 37 ++++++++++++++++++++++ styles/quiz.css | 5 +++ styles/variables.css | 7 +++++ template.html | 22 +++++++++++++ test/index.php | 43 ++++++++++++++++++++++++++ test/test.js | 16 ++++++++++ test/test.php | 10 ++++++ 21 files changed, 520 insertions(+) create mode 100644 index.php create mode 100644 login/index.php create mode 100644 login/login.css create mode 100644 login/login.js create mode 100644 login/login.php create mode 100644 login/register/index.php create mode 100644 login/register/register.js create mode 100644 login/register/register.php create mode 100644 main.sql create mode 100644 menu.css create mode 100644 php/functions.php create mode 100644 php/pages.php create mode 100644 php/scripts.php create mode 100644 single/index.php create mode 100644 styles/main.css create mode 100644 styles/quiz.css create mode 100644 styles/variables.css create mode 100644 template.html create mode 100644 test/index.php create mode 100644 test/test.js create mode 100644 test/test.php diff --git a/index.php b/index.php new file mode 100644 index 0000000..a286ce7 --- /dev/null +++ b/index.php @@ -0,0 +1,61 @@ + + + + + + + + Menu - quiz.czem.eu + + + + + +

Witaj na quiz.czem.eu

+
+
+

Wybierz typ quizu

+
+
+

Jedno Pytanie

+

Wyświetl jedno pytanie z bazy quizu oraz natychmiastowo dostań na nie odpowiedź

+
+
+

Test 20 pytań

+

Wykonaj test 20 pytań, wynik oraz prawidłowość odpowiedzi pojawi się dopiero po oddaniu, w + trakcie możesz zmieniać odpowiedzi na już rozwiązane pytania

+
+
+

Własna długość testu

+

Kiedy 20 pytań to za dużo bądź za mało, zmień długość testu zależnie od swoich potrzeb

+
+
+
+
+
+
+

Inne

+
+
+

Twoje wyniki

+
+
+

Rankingi

+
+
+

Wyloguj się

+
+
+

Przejdź do czem.eu

+
+
+

Kod źródłowy

+
+
+
+
+ + + \ No newline at end of file diff --git a/login/index.php b/login/index.php new file mode 100644 index 0000000..e31a547 --- /dev/null +++ b/login/index.php @@ -0,0 +1,37 @@ + + + + + + + + Logowanie - quiz.czem.eu + + + + + + +

Logowanie do quizu o PHP

+
+
+
+

Logowanie

+

Login:

+

Hasło:

+

+ + +
+

Nie masz konta?

+ + Zarejestruj się +
+
+

+ + + \ No newline at end of file diff --git a/login/login.css b/login/login.css new file mode 100644 index 0000000..0271950 --- /dev/null +++ b/login/login.css @@ -0,0 +1,11 @@ +@import url("/styles/variables.css"); + +main form { + margin: auto; + width: min-content; +} + +main form p { + text-align: left; +} + diff --git a/login/login.js b/login/login.js new file mode 100644 index 0000000..e3f5856 --- /dev/null +++ b/login/login.js @@ -0,0 +1,41 @@ +document.addEventListener('DOMContentLoaded', function () { + const output = document.getElementById("info"); + document.getElementById("loginForm").addEventListener('submit', async function (formE) { + formE.preventDefault(); + const formData = new FormData(formE.target); + const response = await fetch("login.php", { + method: "POST", + body: formData, + credentials: "include", + headers: { + 'X-Requested-With': 'XMLHttpRequest' + } + + }); + const result = await response.json(); + output.innerHTML = result.msg; + output.style.display = "block"; + setTimeout(function () { if (result.redirect) window.location.replace(result.redirect); }, 300); + + }); + document.getElementById("guest").addEventListener("click", async function () { + const formData = new FormData(); + formData.append("guest", "true"); + const response = await fetch("login.php", { + method: "POST", + body: formData, + credentials: "include", + headers: { + 'X-Requested-With': 'XMLHttpRequest' + } + }); + const result = await response.json(); + output.innerHTML = result.msg; + output.style.display = "block"; + setTimeout(function () { if (result.redirect) window.location.replace(result.redirect); }, 300); + }); + passwordI = document.getElementById("password"); + document.getElementById("showPassword").addEventListener("mousedown", function () { passwordI.type = "text"; }); + document.getElementById("showPassword").addEventListener("mouseup", function () { passwordI.type = "password"; }); + document.getElementById("showPassword").addEventListener("mouseleave", function () { passwordI.type = "password"; }); +}); diff --git a/login/login.php b/login/login.php new file mode 100644 index 0000000..0182466 --- /dev/null +++ b/login/login.php @@ -0,0 +1,28 @@ +prepare("SELECT UID, password FROM users WHERE username = ?"); + $username = trim($_POST["username"]); + $password = trim($_POST["password"]); + $stmt->bind_param("s", $username); + $stmt->execute(); + $stmt->bind_result($UID, $passwordHash); + if ($stmt->fetch()) { + if (password_verify($password, $passwordHash)) { + $_SESSION["UID"] = $UID; + $_SESSION["username"] = $username; + echo json_encode(["redirect" => "/", "msg" => "Zalogowano jako $username"]); + } else + jsonMsg("Nieprawidłowe hasło"); + } else + jsonMsg("Nieprawidłowy login"); + $stmt->close(); + $conn->close(); +} elseif ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["guest"])) { + $_SESSION["UID"] = 0; + echo json_encode(["redirect" => "/", "msg" => "Zalogowano jako gość"]); +} else + jsonMsg("Nieprawidłowy request"); + diff --git a/login/register/index.php b/login/register/index.php new file mode 100644 index 0000000..0aaee0b --- /dev/null +++ b/login/register/index.php @@ -0,0 +1,37 @@ + + + + + + + + Rejestracja - quiz.czem.eu + + + + + + +

Rejestracja do quizu o PHP

+
+
+
+

Rejestracja

+

Login:

+

Hasło:

+

Potwierdź hasło:

+

+ + +
+

Jednak masz konto?

+

Powróć do strony logowania

+
+
+

+ + + \ No newline at end of file diff --git a/login/register/register.js b/login/register/register.js new file mode 100644 index 0000000..4b56335 --- /dev/null +++ b/login/register/register.js @@ -0,0 +1,45 @@ +document.addEventListener("DOMContentLoaded", function () { + document.getElementById("regForm").addEventListener("submit", async function (formE) { + formE.preventDefault(); + formData = new FormData(formE.target); + if (formData.get("password") == formData.get("password2")) { + formData.delete("password2"); + if (formData.get("username").trim().length < 4) msg("Login użytkownika musi mieć przynajmniej 4 znaki"); + else if (formData.get("username").trim().length > 32) msg("Login nie może być dłuższa niż 32 znaki"); + else if (formData.get("password").trim().length < 4) msg("Hasło musi mieć przynajmniej 4 znaki"); + else if (formData.get("password").trim().length > 32) msg("Hasło nie może być dłuże niż 32 znaki"); + else { + const response = await fetch("register.php", { + method: "POST", + body: formData, + credentials: "include", + headers: { + 'X-Requested-With': 'XMLHttpRequest' + } + }); + const result = await response.json(); + msg(result.msg); + setTimeout(function () { if (result.redirect) window.location.replace(result.redirect); }, 300); + } + } else msg("Hasła nie są identyczne"); + }); + passwordI = document.getElementById("password"); + passwordI2 = document.getElementById("password2"); + document.getElementById("showPassword").addEventListener("mousedown", function () { + passwordI.type = "text"; + passwordI2.type = "text"; + }); + document.getElementById("showPassword").addEventListener("mouseup", function () { + passwordI.type = "password"; + passwordI2.type = "password"; + }); + document.getElementById("showPassword").addEventListener("mouseleave", function () { + passwordI.type = "password"; + passwordI2.type = "password"; + }); +}); +function msg(msg) { + const output = document.getElementById("info"); + output.innerHTML = msg; + output.style.display = "block"; +} \ No newline at end of file diff --git a/login/register/register.php b/login/register/register.php new file mode 100644 index 0000000..1aef661 --- /dev/null +++ b/login/register/register.php @@ -0,0 +1,32 @@ + 32) + jsonMsg("Login nie może być dłuższa niż 32 znaki"); + elseif (strlen($password) < 4) + jsonMsg("Hasło musi mieć przynajmniej 4 znaki"); + elseif (strlen($password) > 32) + jsonMsg("Hasło nie może być dłuże niż 32 znaki"); + else { + $conn = connectDB(); + $stmt = $conn->prepare("SELECT 1 FROM users where username = ? LIMIT 1"); + $stmt->bind_param("s", $username); + $stmt->execute(); + if ($stmt->fetch()) + jsonMsg("Użytkownik o takim loginie już istnieje"); + else { + $password = password_hash($password, PASSWORD_ARGON2I); + $stmt = $conn->prepare("INSERT INTO users (username, password) VALUES (?, ?)"); + $stmt->bind_param("ss", $username, $password); + if ($stmt->execute()) echo json_encode(["redirect" => "/login/", "msg" => "Utworzono użytkownika $username"]); + else jsonMsg("Nie udało się utworzyć użytkownika"); + } + $stmt->close(); + $conn->close(); + } +} else + jsonMsg("Nieprawidłowy request"); \ No newline at end of file diff --git a/main.sql b/main.sql new file mode 100644 index 0000000..63c1c2b --- /dev/null +++ b/main.sql @@ -0,0 +1 @@ +create table users (UID int PRIMARY KEY AUTO_INCREMENT, username TEXT UNIQUE NOT NULL, password TEXT NOT NULL); \ No newline at end of file diff --git a/menu.css b/menu.css new file mode 100644 index 0000000..95e1935 --- /dev/null +++ b/menu.css @@ -0,0 +1,31 @@ +@import url("/styles/variables.css"); + +main { + min-width: 200px; + max-width: 90%; +} +main article { + display: flex; + flex-wrap: wrap; + justify-content: space-evenly; +} +main article div { + margin: 30px; + padding: 20px 35px; + width: 250px; + background-color: var(--color-alt); + border: 1px solid var(--border-basic); + border-radius: 20px; + transition: 0.2s; + user-select: none; +} +main article div:hover { + background-color: var(--color-alt-hover); +} +main article div:active { + background-color: var(--color-alt-active); +} +main article div h3 { + margin-bottom: 30px; +} + diff --git a/php/functions.php b/php/functions.php new file mode 100644 index 0000000..e3d05c9 --- /dev/null +++ b/php/functions.php @@ -0,0 +1,19 @@ +connect_error) + exit("Błąd połączenia: " . $conn->connect_error); + return $conn; +} +function jsonMsg($messsage) { + echo json_encode(["msg" => $messsage]); +} +function checkLogin() { + session_start(); + if (isset($_SESSION["UID"])) return true; + return false; +} \ No newline at end of file diff --git a/php/pages.php b/php/pages.php new file mode 100644 index 0000000..d757f32 --- /dev/null +++ b/php/pages.php @@ -0,0 +1,6 @@ + + + + + + + + Pytanie - quiz.czem.eu + + + + + +

Pojedyńcze pytanie - quiz PHP

+
+
+ +
+
+

+ + + \ No newline at end of file diff --git a/styles/main.css b/styles/main.css new file mode 100644 index 0000000..da14f92 --- /dev/null +++ b/styles/main.css @@ -0,0 +1,37 @@ +@import url("/styles/variables.css"); + +h1 { + margin-left: 10px; +} + +* { + box-sizing: border-box; +} + +body { + margin: 0; + font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif; + display: flex; + flex-direction: column; + min-height: 100vh; +} + +main { + border: solid 1px var(--border-basic); + text-align: center; + padding: 20px; +} + +div.wrap { + display: flex; + flex: 1; + align-items: center; + justify-content: center; + margin: 10px; +} +main form p#info { + text-align: center; + display: none; + color: red; + font-size: smaller; +} \ No newline at end of file diff --git a/styles/quiz.css b/styles/quiz.css new file mode 100644 index 0000000..61226e5 --- /dev/null +++ b/styles/quiz.css @@ -0,0 +1,5 @@ +@import url("/styles/variables.css"); + +main form p span.bigger { + font-size: larger; +} \ No newline at end of file diff --git a/styles/variables.css b/styles/variables.css new file mode 100644 index 0000000..b92d8d6 --- /dev/null +++ b/styles/variables.css @@ -0,0 +1,7 @@ +:root { + --test: 1px; + --border-basic: black; + --color-alt: rgb(200, 228, 253); + --color-alt-hover: rgb(152, 205, 252); + --color-alt-active: rgb(63, 166, 255); +} \ No newline at end of file diff --git a/template.html b/template.html new file mode 100644 index 0000000..aadddbe --- /dev/null +++ b/template.html @@ -0,0 +1,22 @@ + + + + + + + quiz.czem.eu + + + + + +

q

+
+
+ +
+
+

+ + + \ No newline at end of file diff --git a/test/index.php b/test/index.php new file mode 100644 index 0000000..2be6fc3 --- /dev/null +++ b/test/index.php @@ -0,0 +1,43 @@ + + + + + + + + Test - quiz.czem.eu + + + + + + +

Rozpocznij test - quiz PHP

+
+
+ +
+ Długość testu:
pytań

"; + else + echo ""; + ?> +

+ Nie jesteś zalogowany,
więc żaden postęp nie zostanie zapisany!

"; + else + echo "

" + ?> +
+

Jednak nie chcesz zacząć?

+

Powrót do strony głównej

+
+
+

+ + + \ No newline at end of file diff --git a/test/test.js b/test/test.js new file mode 100644 index 0000000..64566e8 --- /dev/null +++ b/test/test.js @@ -0,0 +1,16 @@ +document.addEventListener("DOMContentLoaded", function () { + document.getElementById("startForm").addEventListener("submit", async function (formE) { + formE.preventDefault(); + formData = new FormData(formE.target); + const response = await fetch("test.php", { + method: "POST", + body: formData, + credentials: "include", + headers: { + 'X-Requested-With': 'XMLHttpRequest' + } + }); + const result = await response.json(); + document.getElementById("content").innerHTML = result.msg; + }); +}); \ No newline at end of file diff --git a/test/test.php b/test/test.php new file mode 100644 index 0000000..4f3320e --- /dev/null +++ b/test/test.php @@ -0,0 +1,10 @@ +