Can delete user account

This commit is contained in:
2022-04-08 17:54:51 +02:00
parent 65dac1e923
commit c7d075f94e
5 changed files with 92 additions and 6 deletions

View File

@ -19,7 +19,7 @@
</thead>
<tbody>
{% for u in users %}
<tr>
<tr id="row-user-{{ u.uid }}">
<td>{{ u.username }}</td>
<td>{{ u.first_name }}</td>
<td>{{ u.last_name }}</td>
@ -28,11 +28,39 @@
<td>{% if u.enabled %}Enabled{% else %}Disabled{% endif %}</td>
<td>
<a href="/admin/edit_user?id={{ u.uid }}">Edit</a>
Delete
<a href="javascript:delete_user('{{ u.uid }}', '{{ u.username }}')">Delete</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<script>
async function delete_user(id, username) {
if(!confirm("Do you really want to delete " + username + "'s account?"))
return;
try {
let data = new URLSearchParams();
data.append("user_id", id);
const res = await fetch("/admin/api/delete_user", {
body: data,
method: "POST",
});
if (res.status != 200)
return alert("Failed to delete user account!");
alert("User account was successfully deleted!");
document.getElementById("row-user-" + id).remove()
} catch(e) {
console.error(e);
alert("Failed to delete user account!");
}
}
</script>
{% endblock content %}