Finished up with IP-Ban functionality on the back-end. Just need to finish up with UI.

This commit is contained in:
rainbow napkin 2025-01-01 17:36:43 -05:00
parent 756c42ceaa
commit 977e8e1e2e
16 changed files with 284 additions and 67 deletions

View file

@ -71,7 +71,6 @@ module.exports.post = async function(req, res){
return res.send({errors: validResult.array()});
}
}catch(err){
console.log(err)
return exceptionHandler(res, err);
}
}

View file

@ -52,6 +52,22 @@ module.exports.post = async function(req, res){
return errorHandler(res, 'Cannot re-create banned account!', 'unauthorized');
}
//Look for ban by IP
const ipBanDB = await userBanModel.checkBanByIP(req.ip);
//If this ip is randy bobandy
if(ipBanDB != null){
//Make the code and message look pretty (kinda) at the same time
const banMsg = [
'The IP address you are trying to register an account from has been banned.',
'If you beleive this to be an error feel free to reach out to your server administrator.',
'Otherwise, fuck off :)'
];
//tell it to fuck off
return errorHandler(res, banMsg.join('<br>'), 'unauthorized');
}
await userModel.register(user, req.ip);
return res.sendStatus(200);
}else{
@ -59,7 +75,6 @@ module.exports.post = async function(req, res){
return res.send({errors: validResult.array()});
}
}catch(err){
console.log(err);
return exceptionHandler(res, err);
}
}

View file

@ -40,7 +40,7 @@ module.exports.post = async function(req, res){
try{
const validResult = validationResult(req);
if(validResult.isEmpty()){
const {user, permanent, expirationDays} = matchedData(req);
const {user, permanent, ipBan, expirationDays} = matchedData(req);
const userDB = await userModel.findOne({user});
if(userDB == null){
@ -54,7 +54,7 @@ module.exports.post = async function(req, res){
return errorHandler(res, 'You cannot ban peer/outranking users', 'Unauthorized', 401);
}
await banModel.banByUserDoc(userDB, permanent, expirationDays);
await banModel.banByUserDoc(userDB, permanent, expirationDays, ipBan);
res.status(200);
return res.send(await banModel.getBans());