Finished up with IP-Ban functionality on the back-end. Just need to finish up with UI.
This commit is contained in:
parent
756c42ceaa
commit
977e8e1e2e
16 changed files with 284 additions and 67 deletions
|
|
@ -328,17 +328,9 @@ channelSchema.methods.rankCrawl = async function(userDB,cb){
|
|||
//TODO: replace this with rank check function shared with setRank
|
||||
this.rankList.forEach(async (rankObj, rankIndex) => {
|
||||
//check against user ID to speed things up
|
||||
if(rankObj.user.user == null){
|
||||
if(rankObj.user.toString() == userDB._id.toString()){
|
||||
//If we found a match, call back
|
||||
cb(rankObj, rankIndex);
|
||||
}
|
||||
}else{
|
||||
//in case someone populated the users
|
||||
if(rankObj.user.user == userDB.user){
|
||||
//If we found a match, call back
|
||||
cb(rankObj, rankIndex);
|
||||
}
|
||||
if(rankObj.user != null && rankObj.user._id.toString() == userDB._id.toString()){
|
||||
//If we found a match, call back
|
||||
cb(rankObj, rankIndex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -379,14 +371,22 @@ channelSchema.methods.setRank = async function(userDB,rank){
|
|||
channelSchema.methods.getRankList = async function(){
|
||||
//Create an empty array to hold the user list
|
||||
const rankList = new Map()
|
||||
//Create temp rank list to replace the current one in the advant we have busted users
|
||||
let tempRankList = [];
|
||||
//Flag that lets us know we gotta save
|
||||
let reqSave = false;
|
||||
|
||||
//Populate the user objects in our ranklist based off of their DB ID's
|
||||
await this.populate('rankList.user');
|
||||
|
||||
//For each rank object in the rank list
|
||||
this.rankList.forEach(async (rankObj, rankObjIndex) => {
|
||||
for(rankObjIndex in this.rankList){
|
||||
const rankObj = this.rankList[rankObjIndex];
|
||||
//If the use still exists
|
||||
if(rankObj.user != null){
|
||||
//Push current rank object to the temp rank list in the advant that it doesn't get saved
|
||||
tempRankList.push(rankObj);
|
||||
|
||||
//Create a new user object from rank object data
|
||||
const userObj = {
|
||||
id: rankObj.user.id,
|
||||
|
|
@ -397,12 +397,20 @@ channelSchema.methods.getRankList = async function(){
|
|||
|
||||
//Add our user object to the list
|
||||
rankList.set(rankObj.user.user, userObj);
|
||||
//Otherwise if it's an invalid rank for a deleted user
|
||||
}else{
|
||||
//Otherwise clean deleted users out of list
|
||||
this.rankList.splice(rankObjIndex,1);
|
||||
await this.save();
|
||||
//Ignore the rank object and throw the save flag to save the temporary rank list
|
||||
reqSave = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//if we need to save the temp rank list
|
||||
if(reqSave){
|
||||
//set rank list
|
||||
this.rankList = tempRankList;
|
||||
//save
|
||||
await this.save();
|
||||
}
|
||||
|
||||
//return userList
|
||||
return rankList;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue