@ -20,13 +20,12 @@
< style >
< style >
body { padding-top: 70px; }
body { padding-top: 70px; }
img { width: 48px; height: 48px; }
img { width: 48px; height: 48px; }
#logo { width: 48px; height: 48px; }
< / style >
< / style >
< script >
< script >
let key = null;
let key = null;
function getI denticon(email) {
function i denticon(email) {
const data = new Identicon(md5(email), {
const data = new Identicon(md5(email), {
size: 48,
size: 48,
format: 'svg'
format: 'svg'
@ -35,41 +34,97 @@
return "data:image/svg+xml;base64," + data;
return "data:image/svg+xml;base64," + data;
}
}
function loadUsers() {
function setVis(elem, vis) {
$("#users-list").empty();
if (vis) { $(elem).removeClass('d-none'); }
else { $(elem).addClass('d-none'); }
}
function updateVis() {
setVis("#no-key-form", !key);
setVis("#users-block", key);
setVis("#invite-form", key);
}
function setKey() {
key = $('#key').val() || window.location.hash.slice(1);
updateVis();
if (key) { loadUsers(); }
return false;
}
function resetKey() {
key = null;
updateVis();
}
$.ajax({
function fillRow(data) {
type: "GET",
url: "/admin/users",
headers: { "Authorization": "Bearer " + key }
}).done(function (data) {
for (i in data) {
for (i in data) {
let user = data[i];
const user = data[i];
let row = $("#tmp-user-row").clone();
const row = $("#tmp-row").clone();
row.attr("id", "user-row:" + user.Id);
row.attr("id", "user-row:" + user.Id);
row.find(".tmp-user-name").text(user.Name);
row.find(".tmp-name").text(user.Name);
row.find(".tmp-user-mail").text(user.Email);
row.find(".tmp-mail").text(user.Email);
row.find(".tmp-user-icon").attr("src", getIdenticon(user.Email))
row.find(".tmp-icon").attr("src", i denticon(user.Email))
row.find(".tmp-user-del").on("click", function (e) {
row.find(".tmp-del").on("click", function (e) {
alert("Not Implemented: Deleting UUID " + user.Id);
if (confirm("Delete User '" + user.Name + "'?")) {
deleteUser(user.Id);
}
return false;
});
});
row.appendTo("#users-list");
row.appendTo("#users-list");
row.removeClass('d-none' );
setVis(row, true );
}
}
})
}
}
$(window).on('load', function () {
function _headers() { return { "Authorization": "Bearer " + key }; }
key = new URLSearchParams(window.location.search).get('key');
if (key) {
function loadUsers() {
$("#no-key-form").addClass('d-none');
$("#users-list").empty();
$.get({ url: "/admin/users", headers: _headers() })
.done(fillRow)
.fail(resetKey);
return false;
}
function _post(url, successMsg, errMsg, resetOnErr, data) {
$.post({ url: url, headers: _headers(), data: data })
.done(() => {
alert(successMsg);
loadUsers();
loadUsers();
} else {
})
$("#users-block").addClass('d-none');
.fail((e) => {
const msg = e.responseJSON ?
e.responseJSON.ErrorModel.Message
: "Unknown error";
alert(errMsg + ": " + msg);
if (resetOnErr) { resetKey(); }
});
}
function deleteUser(id) {
_post("/admin/users/" + id + "/delete",
"User deleted correctly",
"Error deleting user", true);
}
}
function inviteUser() {
data = JSON.stringify({ "Email": $("#email-invite").val() });
_post("/admin/invite/",
"User invited correctly",
"Error inviting user", false, data);
}
$(window).on('load', function () {
setKey();
$("#key-form").submit(setKey);
$("#reload-btn").on("click", loadUsers);
$("#invite-form").submit(inviteUser);
});
});
< / script >
< / script >
< / head >
< / head >
@ -89,36 +144,48 @@
< / div >
< / div >
< / nav >
< / nav >
< main class = "container" >
< main class = "container" >
< div id = "no-key-form" class = " align-items-center p-3 mb-3 text-white-50 bg-danger rounded shadow">
< div id = "no-key-form" class = " d-none align-items-center p-3 mb-3 text-white-50 bg-danger rounded shadow">
< div >
< div >
< h6 class = "mb-0 text-white" > Authentication key needed to continue< / h6 >
< h6 class = "mb-0 text-white" > Authentication key needed to continue< / h6 >
< small > Please provide it below:< / small >
< small > Please provide it below:< / small >
< form class = "form-inline" method= "get ">
< form class = "form-inline" id= "key-form ">
< input type = " text " class = "form-control mr-2" id = "key" name = "key" placeholder = "Enter admin key" >
< input type = " password " class = "form-control w-50 mr-2" id = "key" placeholder = "Enter admin key" >
< button type = "submit" class = "btn btn-primary" > Submit < / button >
< button type = "submit" class = "btn btn-primary" > Save < / button >
< / form >
< / form >
< / div >
< / div >
< / div >
< / div >
< div id = "users-block" class = " my-3 p-3 bg-white rounded shadow">
< div id = "users-block" class = " d-none my-3 p-3 bg-white rounded shadow">
< h6 class = "border-bottom pb-2 mb-0" > Registered Users< / h6 >
< h6 class = "border-bottom pb-2 mb-0" > Registered Users< / h6 >
< div id = "users-list" > < / div >
< div id = "users-list" > < / div >
< small class = "d-block text-right mt-3" >
< small class = "d-block text-right mt-3" >
< a href= "#" onclick = "loadUsers(); "> Reload users< / a >
< a id= "reload-btn" href = "# "> Reload users< / a >
< / small >
< / small >
< / div >
< / div >
< div id = "tmp-user-row" class = "d-none media pt-3" >
< div id = "invite-form" class = "d-none align-items-center p-3 mb-3 text-white-50 bg-secondary rounded shadow" >
< img src = "#" alt = "identicon" class = "mr-2 rounded tmp-user-icon" >
< div >
< h6 class = "mb-0 text-white" > Invite User< / h6 >
< small > Email:< / small >
< form class = "form-inline" id = "invite-form" >
< input type = "email" class = "form-control w-50 mr-2" id = "email-invite" placeholder = "Enter email" >
< button type = "submit" class = "btn btn-primary" > Invite< / button >
< / form >
< / div >
< / div >
< div id = "tmp-row" class = "d-none media pt-3" >
< img class = "mr-2 rounded tmp-icon" >
< div class = "media-body pb-3 mb-0 small border-bottom" >
< div class = "media-body pb-3 mb-0 small border-bottom" >
< div class = "d-flex justify-content-between" >
< div class = "d-flex justify-content-between" >
< strong class = "tmp-user-name" > Full Name< / strong >
< strong class = "tmp- name"> Full Name< / strong >
< a class = "tmp-user-del mr-3" href = "#" > Delete User< / a >
< a class = "tmp- del mr-3" href = "#" > Delete User< / a >
< / div >
< / div >
< span class = "d-block tmp-user-mail" > Email< / span >
< span class = "d-block tmp- mail"> Email< / span >
< / div >
< / div >
< / div >
< / div >
< / main >
< / main >