Finished up with global user bans.

This commit is contained in:
rainbow napkin 2024-11-29 15:39:53 -05:00
parent 26df91262f
commit 8fc699924e
13 changed files with 180 additions and 37 deletions

View file

@ -19,6 +19,7 @@ const {validationResult, matchedData} = require('express-validator');
//local imports
const {userModel} = require('../../../schemas/userSchema');
const userBanModel = require('../../../schemas/userBanSchema.js');
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
module.exports.post = async function(req, res){
@ -27,6 +28,17 @@ module.exports.post = async function(req, res){
if(validResult.isEmpty()){
const user = matchedData(req);
//Would prefer to stick this in userModel.statics.register() but we end up with circular dependencies >:(
const nukedBans = await userBanModel.checkProcessedBans(user.user);
//if we found any related nuked bans
if(nukedBans != null){
//Shit our pants!
res.status(401);
return res.send({errors:[{msg:"Cannot re-create banned account!",type:"unauthorized"}]});
}
await userModel.register(user)
return res.sendStatus(200);
}else{

View file

@ -65,14 +65,8 @@ module.exports.delete = async function(req, res){
const validResult = validationResult(req);
if(validResult.isEmpty()){
const {user} = matchedData(req);
const userDB = await userModel.findOne({user});
if(userDB == null){
res.status(400);
return res.send({errors:[{type: "Bad Query", msg: "User not found.", date: new Date()}]});
}
await banModel.unbanByUserDoc(userDB);
await banModel.unban({user});
res.status(200);
return res.send(await banModel.getBans());