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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue