Improved admin page

This commit is contained in:
Harvey Tindall 2020-05-05 11:37:13 +01:00
parent a2e7ff4def
commit 81a80afdf2
4 changed files with 41 additions and 10 deletions

View File

@ -40,11 +40,14 @@ function addItem(invite) {
codeCopy.onclick = function(){toClipboard(inviteCode)};
codeCopy.classList.add('fa', 'fa-clipboard');
listCode.appendChild(codeCopy);
console.log(invite[3]);
if (typeof(invite[3]) != 'undefined') {
var sentTo = document.createElement('span');
sentTo.setAttribute('style', 'color: grey; margin-left: 2%; font-style: italic; font-size: 75%;');
if (invite[3].includes('Failed to send to')) {
sentTo.appendChild(document.createTextNode(invite[3]));
} else {
sentTo.appendChild(document.createTextNode('Sent to ' + invite[3]));
}
listCode.appendChild(sentTo);
};
var listDelete = document.createElement('button');
@ -159,7 +162,13 @@ function toClipboard(str) {
document.getSelection().addRange(selected);
}
};
$("form#inviteForm").submit(function() {
var button = document.getElementById('generateSubmit');
button.disabled = true;
button.innerHTML =
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
'Loading...';
var send_object = $("form#inviteForm").serializeObject();
if (document.getElementById('send_to_address_enabled').checked) {
send_object['email'] = document.getElementById('send_to_address').value;
@ -175,7 +184,11 @@ $("form#inviteForm").submit(function() {
beforeSend : function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa(window.token + ":"));
},
success: function() { generateInvites(); },
success: function() {
button.textContent = 'Generate';
button.disabled = false;
generateInvites();
},
});
return false;
@ -183,6 +196,13 @@ $("form#inviteForm").submit(function() {
$("form#loginForm").submit(function() {
window.token = "";
var details = $("form#loginForm").serializeObject();
var errorArea = document.getElementById('loginErrorArea');
errorArea.textContent = '';
var button = document.getElementById('loginSubmit');
button.disabled = true;
button.innerHTML =
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
'Loading...';
$.ajax('/getToken', {
type : 'GET',
dataType : 'json',
@ -196,12 +216,13 @@ $("form#loginForm").submit(function() {
data: { get_param: 'value' },
complete: function(data) {
if (data['status'] == 401) {
var formBody = document.getElementById('formBody');
button.disabled = false;
button.textContent = 'Login';
var wrongPassword = document.createElement('div');
wrongPassword.classList.add('alert', 'alert-danger');
wrongPassword.setAttribute('role', 'alert');
wrongPassword.appendChild(document.createTextNode('Incorrect username or password.'));
formBody.appendChild(wrongPassword);
errorArea.appendChild(wrongPassword);
} else {
window.token = JSON.parse(data['responseText'])['token'];
generateInvites();
@ -219,6 +240,10 @@ $("form#loginForm").submit(function() {
return false;
});
document.getElementById('openUsers').onclick = function () {
this.disabled = true;
this.innerHTML =
'<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="margin-right: 0.5rem;"></span>' +
'Loading...';
$.ajax('/getUsers', {
type : 'GET',
dataType : 'json',
@ -282,7 +307,6 @@ document.getElementById('openUsers').onclick = function () {
send[name] = address
};
};
console.log(send);
send = JSON.stringify(send);
$.ajax('/modifyUsers', {
data : send,
@ -304,10 +328,13 @@ document.getElementById('openUsers').onclick = function () {
entry.appendChild(editButton);
list.appendChild(entry);
};
var button = document.getElementById('openUsers');
button.disabled = false;
button.innerHTML = 'Users <i class="fa fa-user"></i>';
$('#users').modal('show');
};
}
});
$('#users').modal('show');
};
generateInvites(empty = true);
$("#login").modal('show');

View File

@ -66,9 +66,10 @@
<input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
</div>
</form>
<div id="loginErrorArea"></div>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary" value="Login" form="loginForm">
<button type="submit" id="loginSubmit" class="btn btn-primary" form="loginForm">Login</button>
</div>
</div>
</div>
@ -130,7 +131,7 @@
<input type="email" class="form-control" placeholder="example@example.com" id="send_to_address" disabled>
</div>
</div>
<input type="submit" class="btn btn-primary" value="Generate">
<button type="submit" id="generateSubmit" class="btn btn-primary">Generate</button>
</form>
</div>
</div>

View File

@ -181,3 +181,4 @@ class Smtp(Email):
log.error(e.smtp_error)
except:
pass
return False

View File

@ -197,7 +197,9 @@ def generateInvite():
email = Smtp(address)
email.construct_invite({'expiry': valid_till,
'code': invite['code']})
email.send()
response = email.send()
if response is False or type(response) != bool:
invite['email'] = f'Failed to send to {address}'
try:
with open(config['files']['invites'], 'r') as f:
invites = json.load(f)