Slon/Http/AdminServer: Allow deletion of users
This commit is contained in:
parent
fcc95d971b
commit
261c8454f5
2 changed files with 34 additions and 2 deletions
|
@ -227,6 +227,25 @@ U0 @slon_admin_settings_instance_get(SlonHttpSession* session, U8* buf)
|
|||
String.Append(buf, "<br><br><input type=submit value=Save></form>");
|
||||
}
|
||||
|
||||
U0 @slon_admin_delete_account(SlonHttpSession* session)
|
||||
{
|
||||
SLON_SCRATCH_BUFFER_AND_REQUEST_JSON
|
||||
if (!request_json->@("id"))
|
||||
return;
|
||||
I64 i;
|
||||
JsonArray* accounts = db->a("accounts");
|
||||
JsonObject* account = NULL;
|
||||
for (i = 0; i < accounts->length; i++) {
|
||||
account = accounts->o(i);
|
||||
if (account && !StrICmp(request_json->@("id"), account->@("id"))) {
|
||||
accounts->remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@slon_db_save_to_disk;
|
||||
@slon_http_send_json(session, SLON_EMPTY_JSON_OBJECT);
|
||||
}
|
||||
|
||||
U0 @slon_admin_new_account(SlonHttpSession* session)
|
||||
{
|
||||
SLON_SCRATCH_BUFFER_AND_REQUEST_JSON
|
||||
|
@ -276,6 +295,11 @@ U0 @slon_admin_server_get(SlonHttpSession* session)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!StrICmp("/delete/account", @slon_http_request_path(session))) {
|
||||
@slon_admin_delete_account(session);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!StrICmp("/manage/accounts", @slon_http_request_path(session))) {
|
||||
@slon_admin_manage_accounts(session);
|
||||
return;
|
||||
|
|
|
@ -70,9 +70,9 @@
|
|||
const accounts = await response.json();
|
||||
let html = "<h4 class=\"title is-4\">Accounts</h4><div class=spacer></div>";
|
||||
if (accounts.length) {
|
||||
html += "<table class=table><thead><tr><th>id</th><th>username</th></tr></head><tbody>";
|
||||
html += "<table class=table><thead><tr><th>id</th><th>acct</th><th>display_name</th><th>type</th><th>delete</th></tr></head><tbody>";
|
||||
for (let i = 0; i < accounts.length; i++) {
|
||||
html += "<tr><td>" + accounts[i]["id"] + "</td><td>" + accounts[i]["username"] + "</td><tr>";
|
||||
html += "<tr><td>" + accounts[i]["id"] + "</td><td>" + accounts[i]["acct"] + "</td><td>" + accounts[i]["display_name"] + "</td><td>"+ (accounts[i]["remote_actor"] == undefined ? "local" : "remote") + "</td><td style=\"text-align:center\"><a href=\"javascript:confirmDeleteUser('" + accounts[i]["acct"] + "','" + accounts[i]["id"] + "');\">❌</a></td><tr>";
|
||||
}
|
||||
html += "</tbody></table>";
|
||||
} else {
|
||||
|
@ -82,6 +82,14 @@
|
|||
setContent(html);
|
||||
setActiveLink("accounts");
|
||||
}
|
||||
async function confirmDeleteUser(user, id) {
|
||||
if(confirm("Are you sure you want to delete '" + user + "' ?")) {
|
||||
const request = new Request("/delete/account?id=" + id);
|
||||
const response = await fetch(request);
|
||||
const empty_json = await response.json();
|
||||
manageAccounts();
|
||||
}
|
||||
}
|
||||
function manageNewUser() {
|
||||
clearActiveLinks();
|
||||
let html = "<h4 class=\"title is-4\">New User</h4><div class=spacer></div>";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue