From 067348835299febed3080ab61ffca365cd07743f Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sun, 27 Apr 2025 22:24:05 +0500 Subject: feat: change username and pfp --- public/account/index.php | 65 +++++++++++++++++++++++++++++++++++++++++++++--- src/config.php | 7 +++++- src/images.php | 12 ++++++--- 3 files changed, 76 insertions(+), 8 deletions(-) diff --git a/public/account/index.php b/public/account/index.php index 8f40ec9..2edb39a 100644 --- a/public/account/index.php +++ b/public/account/index.php @@ -1,5 +1,11 @@ prepare("SELECT id FROM users WHERE username = ?"); + $stmt->execute([$username]); + + if ($stmt->rowCount() == 0) { + $stmt = $db->prepare("UPDATE users SET username = ? WHERE id = ?"); + $stmt->execute([$username, $_SESSION["user_id"]]); + } else { + generate_alert("/account", "The username has already taken"); + exit; + } + } + + if (isset($_FILES["pfp"])) { + $pfp = $_FILES["pfp"]; + resize_image( + $pfp["tmp_name"], + "../static/userdata/avatars/" . $_SESSION["user_id"], + ACCOUNT_PFP_MAX_SIZE[0], + ACCOUNT_PFP_MAX_SIZE[1], + false + ); + } + + $db = null; + generate_alert("/account", "Your changes have been applied!", 200); + exit; +} ?> @@ -24,10 +67,11 @@ include "../../src/partials.php";
+

Account management

-
+

Profile

Profile picture

" id="pfp" width="64" @@ -35,7 +79,7 @@ include "../../src/partials.php";

Username

- "> + ">
@@ -56,4 +100,19 @@ include "../../src/partials.php"; + + \ No newline at end of file diff --git a/src/config.php b/src/config.php index 3f4c52d..9191bb9 100644 --- a/src/config.php +++ b/src/config.php @@ -12,4 +12,9 @@ define("RATING_NAMES", [ // UPLOADS define("ANONYMOUS_UPLOAD", false); -define("ANONYMOUS_DEFAULT_NAME", "chud"); \ No newline at end of file +define("ANONYMOUS_DEFAULT_NAME", "chud"); + +// ACCOUNTS +define("ACCOUNT_USERNAME_REGEX", "/^[A-Za-z0-9_]+$/"); +define("ACCOUNT_USERNAME_MAX_LENGTH", 20); +define("ACCOUNT_PFP_MAX_SIZE", [128, 128]); \ No newline at end of file diff --git a/src/images.php b/src/images.php index fea1825..970fa99 100644 --- a/src/images.php +++ b/src/images.php @@ -1,5 +1,5 @@ readImage($src_path); - $format = strtolower($imagick->getImageFormat()); + $format = "." . strtolower($imagick->getImageFormat()); + + if (!$set_format) { + $format = ""; + } if ($imagick->getNumberImages() > 1) { $imagick = $imagick->coalesceImages(); @@ -29,7 +33,7 @@ function resize_image(string $src_path, string $dst_path, int $max_width, int $m } $imagick = $imagick->deconstructImages(); - $imagick->writeImages("$dst_path.$format", true); + $imagick->writeImages("$dst_path$format", true); } else { $width = $imagick->getImageWidth(); $height = $imagick->getImageHeight(); @@ -38,7 +42,7 @@ function resize_image(string $src_path, string $dst_path, int $max_width, int $m $new_height = (int) ($height * $ratio); $imagick->resizeImage($new_width, $new_height, Imagick::FILTER_TRIANGLE, 1); - $imagick->writeImage("$dst_path.$format"); + $imagick->writeImage("$dst_path$format"); } $imagick->clear(); -- cgit v1.2.3