From 69824f6886c3bd2c9a61481ed7110a78b61386fa Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 22 May 2024 21:15:38 +0200 Subject: [PATCH] sending only needed request (implemented is_admin from 1/2) --- res/forum/script.js | 25 +++++++++++++++++++++---- res/forum/user/user.html | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/res/forum/script.js b/res/forum/script.js index 2d333a2..b129dcb 100644 --- a/res/forum/script.js +++ b/res/forum/script.js @@ -53,20 +53,37 @@ function inject_info(id, username, postfix) }); } -function update_user(old_username, username, nickname, admin, sex, bio, refresh) +async function update_user(old_username, username, nickname, admin, sex, bio, refresh) { + let am_i_admin = await is_admin(); + $.ajax ({ url: "./res/forum/api/update_user.php" + "?old_username=" + old_username + - "&username=" + username + "&nickname=" + nickname + - "&admin=" + admin + "&sex=" + sex + - "&bio=" + bio, + "&bio=" + bio + + ((am_i_admin) ? "&username=" + username + + "&admin=" + admin : ""), success: function(result) { show(refresh); } }); +} + +function is_admin() +{ + return new Promise(function(resolve) + { + $.ajax + ({ + url: "./res/forum/api/is_admin.php", + success: function(result) + { + resolve(result.admin); + } + }) + }); } \ No newline at end of file diff --git a/res/forum/user/user.html b/res/forum/user/user.html index d3083cf..1c453f5 100644 --- a/res/forum/user/user.html +++ b/res/forum/user/user.html @@ -20,7 +20,7 @@ url: "./res/forum/api/get_username.php", success: function(result) { - update_user(result.username, document.getElementById("username").value, document.getElementById("nickname").value, document.getElementById("admin").value, document.getElementById("sex").value,document.getElementById("bio").value, "user"); + update_user(result.username, null, document.getElementById("nickname").value, null, document.getElementById("sex").value,document.getElementById("bio").value, "user"); } }) }