|
|
@ -16,41 +16,44 @@ function addUser(){ |
|
|
|
header: { |
|
|
|
header: { |
|
|
|
'Content-Type':'application/json' |
|
|
|
'Content-Type':'application/json' |
|
|
|
}, |
|
|
|
}, |
|
|
|
body: JSON.stringify(msg) |
|
|
|
body: JSON.stringify(msg), |
|
|
|
|
|
|
|
credentials:'include' |
|
|
|
}).then(() => location.reload()) |
|
|
|
}).then(() => location.reload()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function handleUsers(response){ |
|
|
|
function handleUsers(response){ |
|
|
|
if (response.status == UNAUTHORIZED) { |
|
|
|
if (response.status == UNAUTHORIZED) { |
|
|
|
redirect('login.html?return_to='+encodeURI(window.location.href)) |
|
|
|
redirect('login.html?return_to='+encodeURI(window.location.href)) |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
var users = await response.json(); |
|
|
|
response.json().then(users => { |
|
|
|
var bottom = document.getElementById('bottom'); |
|
|
|
var bottom = document.getElementById('bottom'); |
|
|
|
for (let id in users){ |
|
|
|
for (let id in users){ |
|
|
|
var row = document.createElement("tr"); |
|
|
|
var row = document.createElement("tr"); |
|
|
|
var u = users[id]; |
|
|
|
var u = users[id]; |
|
|
|
row.innerHTML = `<td>${u.username}</td>
|
|
|
|
row.innerHTML = `<td>${u.username}</td>
|
|
|
|
<td>${u.realname}</td> |
|
|
|
<td>${u.realname}</td> |
|
|
|
<td>${u.email}</td> |
|
|
|
<td>${u.email}</td> |
|
|
|
<td>${id}</td> |
|
|
|
<td>${id}</td> |
|
|
|
<td> |
|
|
|
<td> |
|
|
|
<button type="button" onclick="reset_password('${id}')" id="reset-${id}">Reset password</button> |
|
|
|
<button type="button" onclick="reset_password('${id}')" id="reset-${id}">Reset password</button> |
|
|
|
<button id="remove-${u.uuid}" class="danger" onclick="remove('${id}','${u.realname}')" type="button">Remove</button> |
|
|
|
<button id="remove-${u.uuid}" class="danger" onclick="remove('${id}','${u.realname}')" type="button">Remove</button> |
|
|
|
</td>`; |
|
|
|
</td>`; |
|
|
|
bottom.parentNode.insertBefore(row,bottom); |
|
|
|
bottom.parentNode.insertBefore(row,bottom); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function handleRemove(response){ |
|
|
|
function handleRemove(response){ |
|
|
|
if (response.ok){ |
|
|
|
if (response.ok){ |
|
|
|
redirect("users.html"); |
|
|
|
redirect("users.html"); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
var info = await response.text(); |
|
|
|
response.text().then(info => { |
|
|
|
console.log(info); |
|
|
|
console.log(info); |
|
|
|
show(info); |
|
|
|
show(info); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function remove(userId,name){ |
|
|
|
function remove(userId,name){ |
|
|
@ -64,15 +67,14 @@ function remove(userId,name){ |
|
|
|
if (confirm(message.replace("{}",name))) { |
|
|
|
if (confirm(message.replace("{}",name))) { |
|
|
|
fetch(user_controller+"/delete",{ |
|
|
|
fetch(user_controller+"/delete",{ |
|
|
|
method: 'DELETE', |
|
|
|
method: 'DELETE', |
|
|
|
body : JSON.stringify({ user_id : userId, confirmed : true }) |
|
|
|
body : JSON.stringify({ user_id : userId, confirmed : true }), |
|
|
|
|
|
|
|
credentials:'include' |
|
|
|
}).then(handleRemove); |
|
|
|
}).then(handleRemove); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function reset_password(userid){ |
|
|
|
function reset_password(userid){ |
|
|
|
fetch(user_controller+"/reset?user="+userid).then(() => { |
|
|
|
fetch(user_controller+"/reset?user="+userid,{credentials:'include'}).then(() => { disable('reset-'+userid); }); |
|
|
|
disable('reset-'+userid); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fetch(user_controller+"/list",{method:'POST'}).then(handleUsers); |
|
|
|
fetch(user_controller+"/list",{method:'POST',credentials:'include'}).then(handleUsers); |
|
|
|