sending only needed request

(implemented is_admin from 1/2)
This commit is contained in:
Václav Šmejkal 2024-05-22 21:15:38 +02:00
parent d5c1e3c13f
commit 69824f6886
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 22 additions and 5 deletions

View File

@ -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 $.ajax
({ ({
url: "./res/forum/api/update_user.php" + url: "./res/forum/api/update_user.php" +
"?old_username=" + old_username + "?old_username=" + old_username +
"&username=" + username +
"&nickname=" + nickname + "&nickname=" + nickname +
"&admin=" + admin +
"&sex=" + sex + "&sex=" + sex +
"&bio=" + bio, "&bio=" + bio +
((am_i_admin) ? "&username=" + username +
"&admin=" + admin : ""),
success: function(result) success: function(result)
{ {
show(refresh); show(refresh);
} }
}); });
}
function is_admin()
{
return new Promise(function(resolve)
{
$.ajax
({
url: "./res/forum/api/is_admin.php",
success: function(result)
{
resolve(result.admin);
}
})
});
} }

View File

@ -20,7 +20,7 @@
url: "./res/forum/api/get_username.php", url: "./res/forum/api/get_username.php",
success: function(result) 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");
} }
}) })
} }