Alt account entries now deleted with account upon account deletion.

This commit is contained in:
rainbow napkin 2024-12-25 05:52:03 -05:00
parent 980c84afff
commit 60801f0dc2
3 changed files with 29 additions and 10 deletions

View file

@ -35,7 +35,7 @@ module.exports.post = async function(req, res){
//if we found any related nuked bans
if(nukedBans != null){
//Shit our pants!
return errorHandler(res, 'Cannot get alts for non-existant user!');
return errorHandler(res, 'Cannot re-create banned account!', 'unauthorized');
}
await userModel.register(user, req.ip);

View file

@ -31,7 +31,7 @@ module.exports.get = async function(req, res){
const userDB = await userModel.findOne({user: data.user});
if(userDB == null){
return errorHandler(res, 'Cannot re-create banned account!', 'unauthorized');
return errorHandler(res, 'Cannot get alts for non-existant user!');
}
return res.render('partial/tooltip/altList', {alts: await userDB.getAltProfiles()});

View file

@ -187,6 +187,27 @@ userSchema.pre('save', async function (next){
next();
});
//post-delete function (document not query)
userSchema.post('deleteOne', {document: true}, async function (){
//Kill any active sessions
await this.killAllSessions("If you're seeing this, your account has been deleted. So long, and thanks for all the fish! <3");
//Populate alts
await this.populate('alts');
//iterate through alts
for(alt in this.alts){
//Find the index of the alt entry for this user inside of the alt users array of alt users
const altIndex = this.alts[alt].alts.indexOf(this._id);
//splice the entry for this user out of the alt users array of alt users
this.alts[alt].alts.splice(altIndex,1);
//Save the alt user
await this.alts[alt].save();
}
});
//statics
userSchema.statics.register = async function(userObj, ip){
//Pull values from user object
@ -370,7 +391,7 @@ userSchema.statics.processAgedIPRecords = async function(){
//methods
userSchema.methods.checkPass = function(pass){
return hashUtil.comparePassword(pass, this.pass);
return hashUtil.comparePassword(pass, this.pass)
}
userSchema.methods.getAuthenticatedSessions = async function(){
@ -606,20 +627,18 @@ userSchema.methods.passwordReset = async function(passChange){
}
userSchema.methods.nuke = async function(pass){
//Check we have a confirmation password
if(pass == "" || pass == null){
//scream and shout
throw new Error("No confirmation password!");
}
//Check that the password is correct
if(this.checkPass(pass)){
//Annoyingly there isnt a good way to do this from 'this'
//delete the user
var oldUser = await this.deleteOne();
if(oldUser){
await this.killAllSessions("If you're seeing this, your account has been deleted. So long, and thanks for all the fish! <3");
}else{
throw new Error("Server Error: Unable to delete account! Please report this error to your server administrator, and with timestamp.");
}
}else{
//complain about a bad pass
throw new Error("Bad pass.");
}
}