Updated ban UI to handle IP-Bans.

This commit is contained in:
rainbow napkin 2025-01-01 23:00:03 -05:00
parent 977e8e1e2e
commit 7624e1928a
8 changed files with 165 additions and 71 deletions

View file

@ -306,24 +306,31 @@ userBanSchema.statics.unban = async function(user){
}
userBanSchema.statics.getBans = async function(){
const banDB = await this.find({}).populate('user');
//Get the ban, populating users and alts
const banDB = await this.find({}).populate('user').populate('alts');
//Create an empty array to hold ban records
var bans = [];
banDB.forEach((ban) => {
//Calcualte expiration date
//Create array to hold alts
var alts = [];
//Calculate expiration date
var expirationDate = new Date(ban.banDate);
expirationDate.setDate(expirationDate.getDate() + ban.expirationDays);
//Make sure we're not about to read the properties of a null object
if(ban.user != null){
var userObj = {
id: ban.user.id,
user: ban.user.user,
img: ban.user.img,
date: ban.user.date
}
var userObj = ban.user.getProfile();
}
//For each alt in the ban
for(alt of ban.alts){
//Get the profile and push it to the alt list
alts.push(alt.getProfile());
}
//Create ban object
const banObj = {
banDate: ban.banDate,
expirationDays: ban.expirationDays,
@ -331,14 +338,16 @@ userBanSchema.statics.getBans = async function(){
daysUntilExpiration: ban.getDaysUntilExpiration(),
user: userObj,
ips: ban.ips,
alts: ban.alts,
alts,
deletedNames: ban.deletedNames,
permanent: ban.permanent
}
//Add it to the array
bans.push(banObj);
});
//Return the array
return bans;
}

View file

@ -74,22 +74,23 @@ const userSchema = new mongoose.Schema({
required: true,
default: "/img/johnny.png"
},
//These should be larger than validator values to make room for escaped characters
bio: {
type: mongoose.SchemaTypes.String,
required: true,
maxLength: 1000,
maxLength: 2000,
default: "Bio not set!"
},
pronouns:{
type: mongoose.SchemaTypes.String,
optional: true,
maxLength: 20,
maxLength: 50,
default: ""
},
signature: {
type: mongoose.SchemaTypes.String,
required: true,
maxLength: 150,
maxLength: 300,
default: "Signature not set!"
},
highLevel: {

View file

@ -32,11 +32,12 @@ module.exports = {
img: (field = 'img') => body(field).optional().isURL({require_tld: false, require_host: false}).trim(),
pronouns: (field = 'pronouns') => body(field).optional().escape().trim().isLength({min: 0, max: 15}),
//Length check before escaping to keep symbols from throwing the count
pronouns: (field = 'pronouns') => body(field).optional().trim().isLength({min: 0, max: 15}).escape(),
signature: (field = 'signature') => body(field).optional().escape().trim().isLength({min: 1, max: 25}),
signature: (field = 'signature') => body(field).optional().trim().isLength({min: 1, max: 25}).escape(),
bio: (field = 'bio') => body(field).optional().escape().trim().isLength({min: 1, max: 1000}),
bio: (field = 'bio') => body(field).optional().trim().isLength({min: 1, max: 1000}).escape(),
rank: (field = 'rank') => body(field).escape().trim().custom(isRank),

View file

@ -18,17 +18,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. %>
<div class="dynamic-container">
<table id="admin-ban-list-table" class="admin-list-table">
<tr id="admin-ban-list-entry-title" class="admin-list-entry-title-row">
<td id="admin-ban-list-entry-img-title" class="admin-list-entry-title admin-list-entry-item admin-list-entry-img-title">
<h3>Img</h3>
<td id="admin-ban-list-entry-user-title" class="admin-list-entry-title admin-list-entry-item">
<h3>Main<br>User</h3>
</td>
<td id="admin-ban-list-entry-alts-title" class="admin-list-entry-title admin-list-entry-item not-first-col">
<h3>Alt<br>Users</h3>
</td>
<td id="admin-ban-list-entry-ban-nuked-users-title" class="admin-list-entry-title admin-list-entry-item not-first-col">
<h3>Nuked<br>Users</h3>
</td>
<td id="admin-ban-list-entry-id-title" class="admin-list-entry-title admin-list-entry-item not-first-col">
<h3>ID</h3>
</td>
<td id="admin-ban-list-entry-name-title" class="admin-list-entry-title admin-list-entry-item not-first-col">
<h3>Name</h3>
</td>
<td id="admin-ban-list-entry-date-title" class="admin-list-entry-title admin-list-entry-item not-first-col">
<h3>Sign-Up<br>Date</h3>
<td id="admin-ban-list-entry-ban-ips-title" class="admin-list-entry-title admin-list-entry-item not-first-col">
<h3>Banned<br>IPs</h3>
</td>
<td id="admin-ban-list-entry-ban-date-title" class="admin-list-entry-title admin-list-entry-item not-first-col">
<h3>Ban<br>Date</h3>

View file

@ -16,6 +16,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. %>
<link rel="stylesheet" type="text/css" href="/css/popup/ban.css">
<h3 class="popup-title">Ban NULL</h3>
<div class="ban-popup-content">
<span>
<label for="ban-popup-perm">IP-Ban:</label>
<input type="checkbox" name="ban-popup-ip" id="ban-popup-ip">
</span>
<span>
<label for="ban-popup-perm">Perma-Ban:</label>
<input type="checkbox" name="ban-popup-perm" id="ban-popup-perm">