2019-01-19 22:12:52 +01:00
|
|
|
<main class="container">
|
|
|
|
<div id="users-block" class="my-3 p-3 bg-white rounded shadow">
|
|
|
|
<h6 class="border-bottom pb-2 mb-0">Registered Users</h6>
|
2019-01-19 21:36:34 +01:00
|
|
|
|
2019-01-19 22:12:52 +01:00
|
|
|
<div id="users-list">
|
|
|
|
{{#each users}}
|
|
|
|
<div class="media pt-3">
|
|
|
|
<img class="mr-2 rounded identicon" data-src="{{Email}}">
|
|
|
|
<div class="media-body pb-3 mb-0 small border-bottom">
|
2019-01-20 17:43:56 +01:00
|
|
|
<div class="row justify-content-between">
|
|
|
|
<div class="col">
|
|
|
|
<strong>{{Name}}</strong>
|
2019-01-25 18:50:57 +01:00
|
|
|
{{#if TwoFactorEnabled}}
|
|
|
|
<span class="badge badge-success ml-2">2FA</span>
|
|
|
|
{{/if}}
|
2019-01-26 19:28:54 +01:00
|
|
|
{{#unless _Enabled}}
|
|
|
|
<span class="badge badge-warning ml-2">Disabled</span>
|
|
|
|
{{/unless}}
|
2019-01-20 17:43:56 +01:00
|
|
|
<span class="d-block">{{Email}}</span>
|
|
|
|
</div>
|
|
|
|
<div class="col">
|
|
|
|
<strong> Organizations:</strong>
|
|
|
|
<span class="d-block">
|
|
|
|
{{#each Organizations}}
|
|
|
|
<span class="badge badge-primary" data-orgtype="{{Type}}">{{Name}}</span>
|
|
|
|
{{/each}}
|
|
|
|
</span>
|
|
|
|
</div>
|
2019-01-26 19:28:54 +01:00
|
|
|
<div style="flex: 0 0 240px;">
|
|
|
|
<a class="mr-3" href="#" onclick='deauthUser("{{Id}}")'>Deauthorize sessions</a>
|
2019-01-21 23:41:27 +01:00
|
|
|
<a class="mr-3" href="#" onclick='deleteUser("{{Id}}", "{{Email}}")'>Delete User</a>
|
2019-01-20 17:43:56 +01:00
|
|
|
</div>
|
2019-01-19 21:36:34 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-19 22:12:52 +01:00
|
|
|
{{/each}}
|
2019-01-19 21:36:34 +01:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
2019-01-19 22:12:52 +01:00
|
|
|
<small class="d-block text-right mt-3">
|
|
|
|
<a id="reload-btn" href="">Reload users</a>
|
|
|
|
</small>
|
|
|
|
</div>
|
2019-01-19 21:36:34 +01:00
|
|
|
|
2019-01-19 22:12:52 +01:00
|
|
|
<div id="invite-form-block" class="align-items-center p-3 mb-3 text-white-50 bg-secondary rounded shadow">
|
|
|
|
<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>
|
2019-01-19 21:36:34 +01:00
|
|
|
</div>
|
2019-01-19 22:12:52 +01:00
|
|
|
</div>
|
2019-02-02 16:47:27 +01:00
|
|
|
|
|
|
|
<div id="config-block" class="align-items-center p-3 mb-3 text-white-50 bg-secondary rounded shadow">
|
|
|
|
<div>
|
2019-02-03 00:22:18 +01:00
|
|
|
<h6 class="text-white">Configuration</h6>
|
2019-02-02 16:47:27 +01:00
|
|
|
<form class="form" id="config-form">
|
2019-02-03 00:22:18 +01:00
|
|
|
{{#each config}}
|
|
|
|
{{#if editable}}
|
2019-02-04 01:37:25 +01:00
|
|
|
<div class="form-group row" title="{{doc.description}}">
|
2019-02-03 00:22:18 +01:00
|
|
|
{{#case type "text" "number"}}
|
2019-02-04 01:37:25 +01:00
|
|
|
<label for="input_{{name}}" class="col-sm-3 col-form-label">{{doc.name}}</label>
|
|
|
|
<div class="col-sm-8">
|
2019-02-03 00:22:18 +01:00
|
|
|
<input class="form-control" id="input_{{name}}" type="{{type}}" name="{{name}}" value="{{value}}"
|
|
|
|
{{#if default}} placeholder="Default: {{default}}" {{/if}}>
|
|
|
|
</div>
|
|
|
|
{{/case}}
|
|
|
|
{{#case type "checkbox"}}
|
2019-02-04 01:37:25 +01:00
|
|
|
<div class="col-sm-3">{{doc.name}}</div>
|
|
|
|
<div class="col-sm-8">
|
2019-02-03 00:22:18 +01:00
|
|
|
<div class="form-check">
|
|
|
|
<input class="form-check-input" type="checkbox" id="input_{{name}}" name="{{name}}"
|
|
|
|
{{#if value}} checked {{/if}}>
|
|
|
|
|
|
|
|
<label class="form-check-label" for="input_{{name}}"> Default: {{default}} </label>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
{{/case}}
|
|
|
|
</div>
|
|
|
|
{{/if}}
|
|
|
|
{{/each}}
|
2019-02-02 16:47:27 +01:00
|
|
|
<button type="submit" class="btn btn-primary">Save</button>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-19 22:12:52 +01:00
|
|
|
</main>
|
2019-01-19 21:36:34 +01:00
|
|
|
|
2019-02-03 00:22:18 +01:00
|
|
|
<style>
|
|
|
|
#config-block ::placeholder {
|
|
|
|
/* Most modern browsers support this now. */
|
|
|
|
color: orangered;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2019-01-19 22:12:52 +01:00
|
|
|
<script>
|
|
|
|
function reload() { window.location.reload(); }
|
|
|
|
function identicon(email) {
|
|
|
|
const data = new Identicon(md5(email), { size: 48, format: 'svg' });
|
|
|
|
return "data:image/svg+xml;base64," + data.toString();
|
|
|
|
}
|
|
|
|
function _post(url, successMsg, errMsg, data) {
|
2019-02-03 00:22:18 +01:00
|
|
|
$.post({
|
|
|
|
url: url,
|
|
|
|
data: data,
|
|
|
|
//async: false,
|
|
|
|
contentType: "application/json",
|
|
|
|
}).done(function () {
|
2019-01-21 23:41:27 +01:00
|
|
|
alert(successMsg);
|
|
|
|
}).fail(function (e) {
|
|
|
|
const r = e.responseJSON;
|
|
|
|
const msg = r ? r.ErrorModel.Message : "Unknown error";
|
|
|
|
alert(errMsg + ": " + msg);
|
|
|
|
}).always(reload);
|
2019-01-19 22:12:52 +01:00
|
|
|
}
|
|
|
|
function deleteUser(id, mail) {
|
|
|
|
var input_mail = prompt("To delete user '" + mail + "', please type the name below")
|
2019-01-22 17:26:17 +01:00
|
|
|
if (input_mail != null) {
|
2019-01-19 22:12:52 +01:00
|
|
|
if (input_mail == mail) {
|
|
|
|
_post("/admin/users/" + id + "/delete",
|
|
|
|
"User deleted correctly",
|
|
|
|
"Error deleting user");
|
|
|
|
} else {
|
|
|
|
alert("Wrong email, please try again")
|
|
|
|
}
|
|
|
|
}
|
2019-01-21 23:41:27 +01:00
|
|
|
return false;
|
2019-01-19 22:12:52 +01:00
|
|
|
}
|
2019-01-26 19:28:54 +01:00
|
|
|
function deauthUser(id) {
|
|
|
|
_post("/admin/users/" + id + "/deauth",
|
|
|
|
"Sessions deauthorized correctly",
|
|
|
|
"Error deauthorizing sessions");
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-19 22:12:52 +01:00
|
|
|
function inviteUser() {
|
|
|
|
inv = $("#email-invite");
|
2019-02-02 16:47:27 +01:00
|
|
|
data = JSON.stringify({ "email": inv.val() });
|
2019-01-19 22:12:52 +01:00
|
|
|
inv.val("");
|
|
|
|
_post("/admin/invite/", "User invited correctly",
|
|
|
|
"Error inviting user", data);
|
2019-01-21 23:41:27 +01:00
|
|
|
return false;
|
2019-01-19 22:12:52 +01:00
|
|
|
}
|
2019-02-03 00:22:18 +01:00
|
|
|
function getFormData(form) {
|
|
|
|
var form_array = form.serializeArray();
|
|
|
|
var indexed_array = {};
|
|
|
|
|
|
|
|
$.each(form_array, function (i, v) {
|
|
|
|
indexed_array[v.name] = process_value(v.value);
|
|
|
|
});
|
|
|
|
|
|
|
|
return indexed_array;
|
|
|
|
}
|
|
|
|
function process_value(val) {
|
|
|
|
val = val.trim();
|
|
|
|
if (val === "") { return null; }
|
|
|
|
if (!isNaN(val)) { return +val; }
|
|
|
|
if (val === "true" || val === "on") { return true; }
|
|
|
|
if (val === "false" || val === "off") { return false; }
|
|
|
|
return val;
|
|
|
|
}
|
2019-02-02 16:47:27 +01:00
|
|
|
function saveConfig() {
|
2019-02-03 00:22:18 +01:00
|
|
|
data = JSON.stringify(getFormData($("#config-form")));
|
2019-02-02 16:47:27 +01:00
|
|
|
_post("/admin/config/", "Config saved correctly",
|
|
|
|
"Error saving config", data);
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-20 17:43:56 +01:00
|
|
|
let OrgTypes = {
|
|
|
|
"0": { "name": "Owner", "color": "orange" },
|
|
|
|
"1": { "name": "Admin", "color": "blueviolet" },
|
|
|
|
"2": { "name": "User", "color": "blue" },
|
|
|
|
"3": { "name": "Manager", "color": "green" },
|
|
|
|
};
|
2019-01-19 22:12:52 +01:00
|
|
|
$(window).on('load', function () {
|
|
|
|
$("#invite-form").submit(inviteUser);
|
2019-02-02 16:47:27 +01:00
|
|
|
$("#config-form").submit(saveConfig);
|
2019-01-19 22:12:52 +01:00
|
|
|
$("img.identicon").each(function (i, e) {
|
|
|
|
e.src = identicon(e.dataset.src);
|
|
|
|
});
|
2019-01-20 17:43:56 +01:00
|
|
|
$('[data-orgtype]').each(function (i, e) {
|
|
|
|
let orgtype = OrgTypes[e.dataset.orgtype];
|
|
|
|
e.style.backgroundColor = orgtype.color;
|
|
|
|
e.title = orgtype.name;
|
|
|
|
});
|
2019-01-19 22:12:52 +01:00
|
|
|
});
|
|
|
|
</script>
|