Fixed expiration handlers
This commit is contained in:
parent
853f67fe15
commit
730d816c45
|
|
@ -318,16 +318,23 @@ channelSchema.statics.reqPermCheck = function(perm, chanField = "chanName"){
|
|||
channelSchema.statics.processExpiredBans = async function(){
|
||||
const chanDB = await this.find({});
|
||||
|
||||
chanDB.forEach((channel) => {
|
||||
channel.banList.forEach(async (ban, i) => {
|
||||
for(let chanIndex in chanDB){
|
||||
//Pull channel from channels by index
|
||||
const channel = chanDB[chanIndex];
|
||||
|
||||
//channel.banList.forEach(async (ban, banIndex) => {
|
||||
for(let banIndex in channel.banList){
|
||||
//Pull ban from channel ban list
|
||||
const ban = channel.banList[banIndex];
|
||||
|
||||
//ignore permanent and non-expired bans
|
||||
if(ban.expirationDays >= 0 && ban.getDaysUntilExpiration() <= 0){
|
||||
//Get the index of the ban
|
||||
channel.banList.splice(i,1);
|
||||
return await channel.save();
|
||||
channel.banList.splice(banIndex,1);
|
||||
await channel.save();
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//methods
|
||||
|
|
|
|||
|
|
@ -79,16 +79,21 @@ emailChangeSchema.pre('save', async function (next){
|
|||
//statics
|
||||
emailChangeSchema.statics.processExpiredRequests = async function(){
|
||||
//Pull all requests from the DB
|
||||
//Tested finding request by date, but mongoose kept throwing casting errors.
|
||||
//This seems to be an intermittent issue online. Maybe it will work in a future version?
|
||||
const requestDB = await this.find({});
|
||||
|
||||
//Fire em all off at once without waiting for the last one to complete since we don't fuckin' need to
|
||||
requestDB.forEach(async (request) => {
|
||||
for(let requestIndex in requestDB){
|
||||
//Pull request from requestDB by index
|
||||
const request = requestDB[requestIndex];
|
||||
|
||||
//If the request hasn't been processed and it's been expired
|
||||
if(request.getDaysUntilExpiration() <= 0){
|
||||
//Delete the request
|
||||
await this.deleteOne({_id: request._id});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//methods
|
||||
|
|
|
|||
|
|
@ -70,16 +70,21 @@ passwordResetSchema.pre('save', async function (next){
|
|||
//statics
|
||||
passwordResetSchema.statics.processExpiredRequests = async function(){
|
||||
//Pull all requests from the DB
|
||||
//Tested finding request by date, but mongoose kept throwing casting errors.
|
||||
//This seems to be an intermittent issue online. Maybe it will work in a future version?
|
||||
const requestDB = await this.find({});
|
||||
|
||||
//Fire em all off at once without waiting for the last one to complete since we don't fuckin' need to
|
||||
requestDB.forEach(async (request) => {
|
||||
for(let requestIndex in requestDB){
|
||||
//pull request from requestDB by index
|
||||
const request = requestDB[requestIndex];
|
||||
|
||||
//If the request hasn't been processed and it's been expired
|
||||
if(request.getDaysUntilExpiration() <= 0){
|
||||
//Delete the request
|
||||
await this.deleteOne({_id: request._id});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//methods
|
||||
|
|
|
|||
|
|
@ -353,10 +353,14 @@ userBanSchema.statics.getBans = async function(){
|
|||
}
|
||||
|
||||
userBanSchema.statics.processExpiredBans = async function(){
|
||||
//Channel ban expirations may vary so there's no way to search for expired bans
|
||||
const banDB = await this.find({});
|
||||
|
||||
//Firem all off all at once seperately without waiting for one another
|
||||
banDB.forEach(async (ban) => {
|
||||
for(let banIndex in banDB){
|
||||
//Pull ban from banlist by index
|
||||
const ban = banDB[banIndex];
|
||||
|
||||
//This ban was already processed, and it's user has been deleted. There is no more to be done...
|
||||
if(ban.user == null){
|
||||
return;
|
||||
|
|
@ -394,7 +398,7 @@ userBanSchema.statics.processExpiredBans = async function(){
|
|||
await this.deleteOne({_id: ban._id});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//methods
|
||||
|
|
|
|||
|
|
@ -381,22 +381,26 @@ userSchema.statics.processAgedIPRecords = async function(){
|
|||
//Pull full userlist
|
||||
const users = await this.find({});
|
||||
|
||||
//for every user
|
||||
users.forEach((userDB) => {
|
||||
//Not a fan of iterating through the DB but there doesn't seem to be a way to search for a doc based on the properties of it's subdoc
|
||||
for(let userIndex in users){
|
||||
//Pull user record from users by index
|
||||
const userDB = users[userIndex];
|
||||
//For every recent ip within the user
|
||||
userDB.recentIPs.forEach((record, recordI) => {
|
||||
for(let recordIndex in userDB.recentIPs){
|
||||
//Pull record from recent IPs by index
|
||||
const record = userDB.recentIPs[recordIndex];
|
||||
//Check how long it's been since we've last seen the IP
|
||||
const daysSinceLastUse = ((new Date() - record.lastLog) / (1000 * 60 * 60 * 24)).toFixed(1);
|
||||
|
||||
//If it's been more than a week
|
||||
if(daysSinceLastUse >= 7){
|
||||
//Splice out the IP record
|
||||
userDB.recentIPs.splice(recordI, 1);
|
||||
userDB.recentIPs.splice(recordIndex, 1);
|
||||
//No reason to wait on this since we're done with this user
|
||||
userDB.save();
|
||||
await userDB.save();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue