diff --git a/.gitignore b/.gitignore index 770046b..3fac3d3 100755 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ test_*.php +/docs/pfp \ No newline at end of file diff --git a/docs/css/main.css b/docs/css/main.css index 237f6c0..f929b8b 100644 --- a/docs/css/main.css +++ b/docs/css/main.css @@ -13,6 +13,58 @@ font-family: var(--font) !important; } +.banner, +body { + display: flex; + flex-direction: column; + align-items: center; + overflow-x: hidden; + margin-top: 0 +} + +.banner { + justify-content: center; + margin-bottom: calc(-1*var(--elem-height)) +} + +.banner-background, +.banner-content { + height: var(--elem-height); + overflow-y: auto +} + +.banner-background { + border-radius: var(--border-radius); + background-color: var(--gray); + opacity: 30%; + object-fit: cover +} + +.banner-content { + margin-left: 10px; + margin-right: 10px; + position: relative; + top: calc(-1*var(--elem-height)) +} + +.banner, +.banner-background, +.content { + width: var(--elem-width) +} + +.avatar { + display: flex; + justify-content: space-between; + width: var(--elem-width); + align-items: center; +} + +.avatar-img { + width: 50px; + height: 50px; + margin-right: 15px +} .form { width: calc(var(--elem-width) - 1rem); @@ -42,15 +94,6 @@ 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; @@ -58,10 +101,52 @@ border-color: var(--primary-light) } -body { +.header { + z-index: 5; + position: sticky; + top: 0; + display: flex; + background: var(--gray); + color: var(--white); + padding: 10px; + margin-bottom: 10px; + align-items: center; + width: calc(100vw - 20px) +} + +.header-link, +.link { + font-weight: 700; + color: var(--white) +} + +.header-link { + text-decoration: none; + padding-left: .5em; + margin-left: .5em; + border-left: solid var(--white) 2px; + display: flex; flex-direction: column; align-items: center; - overflow-x: hidden; - margin-top: 0 + justify-content: center; + height: 1.5em; +} + +.header-img { + border-left: none; + margin-left: 0; + padding-left: 0; + height: 1.5em; + width: 1.5em; + object-fit: cover; +} + +@media (max-width: 800px) { + .form { + grid-template-columns: 1fr; + } + .form-button, .form-heading, .form-message { + grid-column: span 1; + } } \ No newline at end of file diff --git a/docs/img/newlogo.svg b/docs/img/newlogo.svg new file mode 100644 index 0000000..4515b3d --- /dev/null +++ b/docs/img/newlogo.svg @@ -0,0 +1,73 @@ + + + + diff --git a/docs/login.php b/docs/login.php index 3fbd63e..fa72ca5 100644 --- a/docs/login.php +++ b/docs/login.php @@ -13,7 +13,7 @@ $user = $_POST['user']; $pass = $_POST['pass']; - $stmt = $db->prepare("SELECT * FROM auth WHERE UPPER(username) LIKE UPPER(?)"); + $stmt = $db->prepare("SELECT * FROM main.auth WHERE UPPER(username) LIKE UPPER(?)"); $stmt->execute([$user]); $result = $stmt->fetch(PDO::FETCH_ASSOC); @@ -26,7 +26,7 @@ $token = bin2hex(random_bytes(32)); - $stmt = $db->prepare("INSERT INTO token (username, token) VALUES (?, ?)"); + $stmt = $db->prepare("INSERT INTO main.token (username, token) VALUES (?, ?)"); $stmt->execute([$user,$token]); setcookie("token", $token, time()+3600*24); @@ -39,7 +39,7 @@ $form_message = post_handler(); - form("Log in", $form_message, array( + form("Log in (Register?)", $form_message, array( array('key' => 'Username', 'type' => 'text', 'name' => 'user', 'default' => ''), array('key' => 'Password', 'type' => 'password', 'name' => 'pass', 'default' => '') )); diff --git a/docs/register.php b/docs/register.php index 1268edd..b175d11 100644 --- a/docs/register.php +++ b/docs/register.php @@ -28,7 +28,7 @@ return 'Username is too long or short.'; } - $stmt = $db->prepare("SELECT username FROM auth WHERE UPPER(username) LIKE UPPER(?)"); + $stmt = $db->prepare("SELECT username FROM main.auth WHERE UPPER(username) LIKE UPPER(?)"); $stmt->execute([$user]); $result = $stmt->fetch(PDO::FETCH_ASSOC); @@ -37,7 +37,7 @@ $hashed = password_hash($pass, PASSWORD_DEFAULT); - $stmt = $db->prepare("INSERT INTO auth (username, password) VALUES (?, ?)"); + $stmt = $db->prepare("INSERT INTO main.auth (username, password) VALUES (?, ?)"); $stmt->execute([$user,$hashed]); header("Location: /"); diff --git a/docs/user.php b/docs/user.php new file mode 100644 index 0000000..8527dca --- /dev/null +++ b/docs/user.php @@ -0,0 +1,123 @@ +prepare("SELECT * FROM main.user WHERE UPPER(username) LIKE UPPER(?)"); //weirdly, this requires a schema name + $stmt->execute([$user]); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$result && $user != $username) { + die(); + } + + $bio = isset($result) ? $result['bio'] : 'This user has not set a bio.'; + + $stmt = $db->prepare("SELECT * FROM follow WHERE target = ?"); + $stmt->execute([$user]); + + $following = $stmt->fetchAll(PDO::FETCH_DEFAULT); + + $stmt = $db->prepare("SELECT * FROM follow WHERE username = ?"); + $stmt->execute([$user]); + + $followers = $stmt->fetchAll(PDO::FETCH_DEFAULT); + + } + + function follow() { + global $db; + global $username; + global $user; + + $stmt = $db->prepare("SELECT * FROM main.follow WHERE username = ? AND target = ?"); + $stmt->execute([$user,$username]); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + + if (is_null($username)) return; + + if ($result) { + $stmt = $db->prepare("DELETE FROM main.follow WHERE username = ? AND target = ?"); + $stmt->execute([$user,$username]); + } else { + $stmt = $db->prepare("INSERT INTO main.follow (username,target) VALUES (?,?)"); + $stmt->execute([$user,$username]); + } + } + function settings() { + global $db; + global $username; + global $user; + + if (is_null($username)) return; + + $stmt = $db->prepare("DELETE FROM main.user WHERE username = ?"); + $stmt->execute([$username]); + + $stmt = $db->prepare("INSERT INTO main.user (username,bio) VALUES (?,?)"); + $stmt->execute([$username,$_POST['desc']]); + + move_uploaded_file($_FILES['avatar']['tmp_name'], $_SERVER["DOCUMENT_ROOT"] . '/../docs/pfp/' . $username . '.png'); + } + + get_handler(); +?> +
+ 'Bio', 'type' => 'textarea', 'name' => 'desc', 'default' => $bio), + array('key' => 'Avatar', 'type' => 'file', 'name' => 'avatar', 'default' => '') + ),'/user.php?id=' . $user . '&type=settings'); + } + + page_footer(); +?> \ No newline at end of file diff --git a/libs/auth.php b/libs/auth.php index ee7cc09..2f316f9 100644 --- a/libs/auth.php +++ b/libs/auth.php @@ -6,7 +6,7 @@ global $db; - $stmt = $db->prepare("SELECT * FROM token WHERE token = ?"); + $stmt = $db->prepare("SELECT * FROM main.token WHERE token = ?"); $stmt->execute([$token]); $result = $stmt->fetch(PDO::FETCH_ASSOC); @@ -14,7 +14,7 @@ $username = $result['username']; - $stmt = $db->prepare("SELECT * FROM auth WHERE username = ?"); + $stmt = $db->prepare("SELECT * FROM main.auth WHERE username = ?"); $stmt->execute([$username]); $result = $stmt->fetch(PDO::FETCH_ASSOC); diff --git a/libs/form.php b/libs/form.php index 610ce0c..71e4411 100644 --- a/libs/form.php +++ b/libs/form.php @@ -1,6 +1,6 @@ -