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 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) (limited to 'public/account/index.php') 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 -- cgit v1.2.3