diff --git a/docs/css/main.css b/docs/css/main.css new file mode 100644 index 0000000..237f6c0 --- /dev/null +++ b/docs/css/main.css @@ -0,0 +1,67 @@ +:root { + --black: rgb(16, 16, 16); + --gray: rgb(38, 38, 38); + --white: rgb(240, 240, 240); + --primary-dark: rgb(230, 78, 78); + --primary-light: rgb(255, 200, 200); + --elem-width: min(800px, 90vw); + --elem-height: 300px; + --border-radius: 15px; + --font: system-ui, sans-serif; + color: var(--white); + background: var(--black); + font-family: var(--font) !important; +} + + +.form { + width: calc(var(--elem-width) - 1rem); + grid-template-columns: .51fr 1fr; + display: grid +} + +.form-key { + margin-right: 10px +} + +.form-button, +.form-input, +.form { + border: solid var(--gray) 3px; + background: var(--black); + border-radius: var(--border-radius); + color: var(--white); + padding: .5rem; + margin-bottom: .5rem; + text-decoration: none +} + +.form-button, +.form-heading, +.form-message { + grid-column: span 2; +} + +@media (max-width: 800px) { + .form { + grid-template-columns: 1fr; + } + .form-button, .form-heading, .form-message { + grid-column: span 1; + } +} + +.form-button { + font-weight: 700; + display: inline-block; + background: var(--primary-dark); + border-color: var(--primary-light) +} + +body { + display: flex; + flex-direction: column; + align-items: center; + overflow-x: hidden; + margin-top: 0 +} \ No newline at end of file diff --git a/docs/index.php b/docs/index.php new file mode 100644 index 0000000..3036608 --- /dev/null +++ b/docs/index.php @@ -0,0 +1,10 @@ + + +

Very barren.

+ + \ No newline at end of file diff --git a/docs/login.php b/docs/login.php new file mode 100644 index 0000000..32e8882 --- /dev/null +++ b/docs/login.php @@ -0,0 +1,64 @@ +prepare("SELECT * FROM auth WHERE UPPER(username) LIKE UPPER(?)"); + $stmt->execute([$user]); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$result) return 'Username does not exist.'; + + $verified = password_verify($pass,$result['password']); + + if (!$verified) return 'Password is wrong.'; + + $token = bin2hex(random_bytes(32)); + + $stmt = $db->prepare("INSERT INTO token (username, token) VALUES (?, ?)"); + $stmt->execute([$user,$token]); + + setcookie("token", $token, time()+3600*24); + + header("Location: /"); + die(); + } + + page_header(); + + $form_message = post_handler(); + + // TODO: form builder. this is lazy for testing purposes +?> + +
+

+ Join +

+ + + + + Username + + + + Password + + + +
+ + \ No newline at end of file diff --git a/docs/register.php b/docs/register.php new file mode 100644 index 0000000..60e2e90 --- /dev/null +++ b/docs/register.php @@ -0,0 +1,77 @@ + 0) { + return 'Username contains invalid characters.'; + } + + if (strlen($user) < 1 || strlen($user) > 32) { + return 'Username is too long or short.'; + } + + $stmt = $db->prepare("SELECT username FROM auth WHERE UPPER(username) LIKE UPPER(?)"); + $stmt->execute([$user]); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($result) return 'Username is taken.'; + + $hashed = password_hash($pass, PASSWORD_DEFAULT); + + $stmt = $db->prepare("INSERT INTO auth (username, password) VALUES (?, ?)"); + $stmt->execute([$user,$hashed]); + + header("Location: /"); + die(); + } + + page_header(); + + $form_message = post_handler(); + + // TODO: form builder. this is lazy for testing purposes +?> + +
+

+ Join +

+ + + + + Username + + + + Password + + + + Password (again) + + + +
+ + \ No newline at end of file diff --git a/libs/auth.php b/libs/auth.php new file mode 100644 index 0000000..ee7cc09 --- /dev/null +++ b/libs/auth.php @@ -0,0 +1,27 @@ +prepare("SELECT * FROM token WHERE token = ?"); + $stmt->execute([$token]); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + if (!$result) return '!guest'; + + $username = $result['username']; + + $stmt = $db->prepare("SELECT * FROM auth WHERE username = ?"); + $stmt->execute([$username]); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + if (!$result) return '!guest'; + + return $username; + } + + $username = auth($_COOKIE['token']); +?> \ No newline at end of file diff --git a/libs/page.php b/libs/page.php new file mode 100644 index 0000000..991f56b --- /dev/null +++ b/libs/page.php @@ -0,0 +1,16 @@ + + + + + NewBiglyChat + + + + + + + \ No newline at end of file diff --git a/scripts/init.php b/scripts/init.php new file mode 100644 index 0000000..5fa3c4e --- /dev/null +++ b/scripts/init.php @@ -0,0 +1,11 @@ +exec($sql); + + echo "Database was set up."; +?> \ No newline at end of file diff --git a/scripts/init.sql b/scripts/init.sql new file mode 100644 index 0000000..b8bc3e8 --- /dev/null +++ b/scripts/init.sql @@ -0,0 +1,2 @@ +CREATE TABLE IF NOT EXISTS main.auth (username TEXT, password TEXT); +CREATE TABLE IF NOT EXISTS main.token (username TEXT, token TEXT); \ No newline at end of file