Updated ban UI to handle IP-Bans.
This commit is contained in:
parent
977e8e1e2e
commit
7624e1928a
8 changed files with 165 additions and 71 deletions
|
|
@ -32,6 +32,7 @@ class canopyAdminUtils{
|
|||
//Setup title text real quick-like :P
|
||||
this.title.innerHTML = `Ban ${this.target}`;
|
||||
|
||||
this.ipBan = document.querySelector("#ban-popup-ip");
|
||||
this.permBan = document.querySelector("#ban-popup-perm");
|
||||
this.expiration = document.querySelector("#ban-popup-expiration");
|
||||
this.expirationPrefix = document.querySelector("#ban-popup-expiration-prefix");
|
||||
|
|
@ -62,7 +63,8 @@ class canopyAdminUtils{
|
|||
this.popup.closePopup();
|
||||
|
||||
//Submit the user ban based on input
|
||||
const data = await adminUtil.banUser(this.target, this.permBan.checked, this.expiration.value);
|
||||
console.log(this.ipBan.checked)
|
||||
const data = await adminUtil.banUser(this.target, this.permBan.checked, this.ipBan.checked, this.expiration.value);
|
||||
|
||||
//For some reason comparing this against undefined or null wasnt working in and of itself...
|
||||
if(data != null){
|
||||
|
|
@ -457,66 +459,146 @@ class adminUserBanList{
|
|||
}
|
||||
|
||||
renderBanList(banList){
|
||||
//Clear out the ban list
|
||||
this.clearBanList();
|
||||
|
||||
//For each ban received
|
||||
banList.forEach((ban) => {
|
||||
//Calculate expiration date and expiration days
|
||||
var expirationDateString = `${new Date(ban.expirationDate).toDateString()}<br>(${ban.daysUntilExpiration} day(s) left)`;
|
||||
var banActionString = ban.permanent ? "Nuke<br>Accounts" : "Un-Ban";
|
||||
if(ban.user == null){
|
||||
let expirationDateString = `${new Date(ban.expirationDate).toLocaleDateString()}<br>(${ban.daysUntilExpiration} day(s) left)`;
|
||||
let banActionString = ban.permanent ? "Nuke<br>Accounts" : "Un-Ban";
|
||||
let nuked = ban.user == null;
|
||||
|
||||
//If the user is null (the ban has been nuked)
|
||||
if(nuked){
|
||||
//Fudge the user object if it's already been deleted
|
||||
ban.user = {
|
||||
img: "/img/nuked.png",
|
||||
id: "-",
|
||||
user: ban.deletedNames[0] ? ban.deletedNames[0] : "UNKNOWN",
|
||||
deleted: true
|
||||
//Use dead name if we got one
|
||||
user: ban.deletedNames[0] != null ? ban.deletedNames[0] : "Nuked"
|
||||
};
|
||||
|
||||
ban.alts[0] = {
|
||||
user: "Nuked"
|
||||
}
|
||||
|
||||
//Fake the display string
|
||||
var signUpDateString = "-"
|
||||
expirationDateString = "Accounts<br>Nuked"
|
||||
banActionString = "Accounts<br>Nuked"
|
||||
|
||||
}else{
|
||||
var signUpDateString = new Date(ban.user.date).toDateString()
|
||||
}
|
||||
//Create entry row
|
||||
const entryRow = document.createElement('tr');
|
||||
entryRow.classList.add("admin-list-entry");
|
||||
|
||||
//Create IMG node inside of IMG cell
|
||||
const imgNode = document.createElement('img');
|
||||
imgNode.classList.add("admin-list-entry","admin-list-entry-item");
|
||||
imgNode.src = ban.user.img;
|
||||
|
||||
//Create unban icon
|
||||
const unbanIcon = document.createElement('i');
|
||||
unbanIcon.classList.add("bi-emoji-smile-fill","admin-user-list-icon","admin-user-list-unban-icon");
|
||||
unbanIcon.id = `admin-user-list-unban-icon-${ban.user.user}`;
|
||||
unbanIcon.title = `Unban ${ban.user.user}`;
|
||||
unbanIcon.addEventListener("click", this.unban.bind(this));
|
||||
|
||||
//Create nuke account icon
|
||||
const nukeAccount = document.createElement('i');
|
||||
nukeAccount.classList.add("bi-radioactive","admin-user-list-icon","admin-user-list-unban-icon");
|
||||
nukeAccount.id = `admin-user-list-unban-icon-${ban.user.user}`;
|
||||
nukeAccount.title = `Nuke accounts`;
|
||||
nukeAccount.addEventListener("click",console.log);
|
||||
|
||||
//append img cell to row
|
||||
entryRow.appendChild(utils.ux.newTableCell(imgNode, true));
|
||||
|
||||
//Generate and append row to table
|
||||
this.table.appendChild(utils.ux.newTableRow([
|
||||
ban.user.id,
|
||||
ban.user.user,
|
||||
signUpDateString,
|
||||
new Date(ban.banDate).toDateString(),
|
||||
this.renderUser(ban.user, nuked),
|
||||
this.renderUsers(ban.alts, nuked),
|
||||
this.renderDeadUsers(ban.deletedNames),
|
||||
this.renderIPs(ban.ips),
|
||||
new Date(ban.banDate).toLocaleDateString(),
|
||||
expirationDateString,
|
||||
banActionString,
|
||||
(ban.user.deleted ? unbanIcon : [unbanIcon, nukeAccount])
|
||||
this.renderIcons(ban.user)
|
||||
]));
|
||||
});
|
||||
}
|
||||
|
||||
renderUser(user, nuked = false){
|
||||
if(nuked){
|
||||
var userNode = document.createElement('img');
|
||||
userNode.classList.add("admin-list-entry","admin-list-entry-item");
|
||||
userNode.src = '/img/nuked.png'
|
||||
userNode.title = "Nuked"
|
||||
}else{
|
||||
var userNode = document.createElement('p');
|
||||
userNode.innerHTML = user.user;
|
||||
}
|
||||
return userNode;
|
||||
}
|
||||
|
||||
renderUsers(users, nuked){
|
||||
//Create userlist span
|
||||
let userList = document.createElement('span');
|
||||
|
||||
if(!nuked){
|
||||
//For each user
|
||||
for(let user of users){
|
||||
//Render out the user
|
||||
userList.appendChild(this.renderUser(user));
|
||||
}
|
||||
}else{
|
||||
userList = document.createElement('img');
|
||||
userList.classList.add("admin-list-entry","admin-list-entry-item");
|
||||
userList.src = '/img/nuked.png'
|
||||
userList.title = "Nuked"
|
||||
}
|
||||
|
||||
//return our list
|
||||
return userList;
|
||||
}
|
||||
|
||||
renderDeadUsers(users){
|
||||
//Create userlist span
|
||||
const deadUsers = document.createElement('span');
|
||||
|
||||
//For each ip
|
||||
for(let user of users){
|
||||
//Create a node
|
||||
const userNode = document.createElement('p');
|
||||
//Fill it wit the ip
|
||||
userNode.innerHTML = user;
|
||||
//Append it
|
||||
deadUsers.appendChild(userNode);
|
||||
}
|
||||
|
||||
//return our list
|
||||
return deadUsers;
|
||||
}
|
||||
|
||||
renderIPs(ips){
|
||||
//Create userlist span
|
||||
const ipList = document.createElement('span');
|
||||
|
||||
//For each ip
|
||||
for(let ip of ips.plaintext){
|
||||
//Create a node
|
||||
const ipNode = document.createElement('p');
|
||||
//Fill it wit the ip
|
||||
ipNode.innerHTML = ip;
|
||||
//Append it
|
||||
ipList.appendChild(ipNode);
|
||||
}
|
||||
|
||||
//For each user
|
||||
for(let hash of ips.hashed){
|
||||
//Create a node
|
||||
const ipNode = document.createElement('p');
|
||||
//List it as a hashed ip with the hash as alt text
|
||||
ipNode.innerHTML = '[Hashed IP]';
|
||||
ipNode.title = hash;
|
||||
//Append the node
|
||||
ipList.appendChild(ipNode);
|
||||
}
|
||||
|
||||
//return our list
|
||||
return ipList;
|
||||
}
|
||||
|
||||
renderIcons(user){
|
||||
//Create unban icon
|
||||
const unbanIcon = document.createElement('i');
|
||||
unbanIcon.classList.add("bi-emoji-smile-fill","admin-user-list-icon","admin-user-list-unban-icon");
|
||||
unbanIcon.id = `admin-user-list-unban-icon-${user.user}`;
|
||||
unbanIcon.title = `Unban ${user.user}`;
|
||||
unbanIcon.addEventListener("click", this.unban.bind(this));
|
||||
|
||||
//Create nuke account icon
|
||||
const nukeAccount = document.createElement('i');
|
||||
nukeAccount.classList.add("bi-radioactive","admin-user-list-icon","admin-user-list-unban-icon");
|
||||
nukeAccount.id = `admin-user-list-unban-icon-${user.user}`;
|
||||
nukeAccount.title = `Nuke accounts`;
|
||||
nukeAccount.addEventListener("click",console.log);
|
||||
|
||||
//If our user has been deleted don't return the nuke icon
|
||||
return (user.deleted ? unbanIcon : [unbanIcon, nukeAccount]);
|
||||
}
|
||||
}
|
||||
|
||||
class adminTokeCommandList{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue