Finished up with global user bans.
This commit is contained in:
parent
26df91262f
commit
8fc699924e
13 changed files with 180 additions and 37 deletions
|
|
@ -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{
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue