implemented removal of user

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
2024-08-10 20:44:55 +02:00
parent 62c85410a9
commit cc131d45e0
7 changed files with 70 additions and 17 deletions

View File

@@ -22,7 +22,15 @@ function getValue(id){
}
function hide(id){
get(id).style.display = 'none';
var elem = get(id);
if (elem) elem.style.display = 'none';
}
function hideAll(clazz){
var elems = document.getElementsByTagName('*'), i;
for (i in elems) {
if((' ' + elems[i].className + ' ').indexOf(' ' + clazz + ' ') > -1) elems[i].style.display = 'none';
}
}
function isChecked(id){
@@ -48,5 +56,6 @@ function setValue(id,newVal){
}
function show(id){
get(id).style.display = '';
var elem = get(id);
if (elem) elem.style.display = '';
}

View File

@@ -29,29 +29,42 @@ async function handleUsers(response){
var bottom = document.getElementById('bottom');
for (let id in users){
var row = document.createElement("tr");
var user = users[id];
row.innerHTML = `<td>${user.username}</td>
<td>${user.realname}</td>
<td>${user.email}</td>
var u = users[id];
row.innerHTML = `<td>${u.username}</td>
<td>${u.realname}</td>
<td>${u.email}</td>
<td>${id}</td>
<td>
<button type="button" onclick="reset_password('${id}')" id="reset-${id}">Reset password</button>
<button class="danger" onclick="remove('${id}')" type="button">Remove</button>
<button id="remove-${u.uuid}" class="danger" onclick="remove('${id}','${u.realname}')" type="button">Remove</button>
</td>`;
bottom.parentNode.insertBefore(row,bottom);
}
}
function handleRemove(response){
redirect("users.html");
async function handleRemove(response){
if (response.ok){
redirect("users.html");
} else {
var info = await response.text();
console.log(info);
show(info);
}
}
function remove(userId){
function remove(userId,name){
disable(`remove-${userId}`);
if (userId == user.uuid) {
//return;
}
setText(`remove-${userId}`,"sent…");
hideAll('error');
var message = document.getElementById('message').innerHTML;
if (confirm(message.replace("{}",userId))) {
if (confirm(message.replace("{}",name))) {
fetch(user_controller+"/delete",{
method: 'DELETE',
body : JSON.stringify({ userId : userId })
body : JSON.stringify({ user_id : userId, confirmed : true })
}).then(handleRemove);
}
}

View File

@@ -12,7 +12,6 @@
<div id="content">
<h1>to do…</h1>
<ul>
<li><a href="users.html">Users: remove</a></li>
<li><a href="login.html">Login: "remember me" option</a></li>
<li>at_hash in ID Token</li>
<li>drop outdated sessions</li>

View File

@@ -41,7 +41,10 @@
</tr>
</table>
<span class="error" style="display: none" id="pw-mismatch">Passwords do not match!</span>
<span class="hidden" id="message">Really remove client "{}"?</span>
<span class="error" style="display: none" id="missing_user_id">Server did not receive a valid user_id for removal!</span>
<span class="error" style="display: none" id="missing_confirmation">Server did not receive confirmation for this request!</span>
<span class="error" style="display: none" id="unknown_user">The backend does not know this user!</span>
</fieldset>
</div>
</body>