Added rankfighting to ban.
This commit is contained in:
parent
b138b26f27
commit
ef4894e409
6 changed files with 41 additions and 12 deletions
|
|
@ -19,6 +19,7 @@ const {validationResult, matchedData} = require('express-validator');
|
|||
|
||||
//local imports
|
||||
const banModel = require('../../../schemas/userBanSchema');
|
||||
const permissionModel = require('../../../schemas/permissionSchema');
|
||||
const {userModel} = require('../../../schemas/userSchema');
|
||||
const {exceptionHandler} = require('../../../utils/loggerUtils');
|
||||
|
||||
|
|
@ -43,8 +44,17 @@ module.exports.post = async function(req, res){
|
|||
const userDB = await userModel.findOne({user});
|
||||
|
||||
if(userDB == null){
|
||||
//If the user is null, scream and shout
|
||||
res.status(400);
|
||||
return res.send({errors:[{type: "Bad Query", msg: "User not found.", date: new Date()}]});
|
||||
}else if(userDB.user == req.session.user.user){
|
||||
//If some smart-ass is trying self-privelege escalation
|
||||
res.status(401);
|
||||
return res.send({errors:[{type: "Unauthorized", msg: "Keep it up, maybe I will ban you!", date: new Date()}]});
|
||||
}else if(permissionModel.rankToNum(userDB.rank) >= permissionModel.rankToNum(req.session.user.rank)){
|
||||
//If the user is below the original rank of the user they're setting, scream and shout
|
||||
res.status(401);
|
||||
return res.send({errors:[{type: "Unauthorized", msg: "You cannot ban peer/outranking users.", date: new Date()}]});
|
||||
}
|
||||
|
||||
await banModel.banByUserDoc(userDB, permanent, expirationDays);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue