Added tokeCommand delete endpoint and ajax call, replaced all raw error responses.
This commit is contained in:
parent
af7f4219a5
commit
864304f13b
|
|
@ -19,7 +19,7 @@ const config = require('../../config.json');
|
||||||
const {userModel} = require('../schemas/userSchema');
|
const {userModel} = require('../schemas/userSchema');
|
||||||
const permissionModel = require('../schemas/permissionSchema');
|
const permissionModel = require('../schemas/permissionSchema');
|
||||||
const channelModel = require('../schemas/channel/channelSchema');
|
const channelModel = require('../schemas/channel/channelSchema');
|
||||||
const {exceptionHandler} = require("../utils/loggerUtils");
|
const {exceptionHandler, errorHandler} = require("../utils/loggerUtils");
|
||||||
|
|
||||||
//register page functions
|
//register page functions
|
||||||
module.exports.get = async function(req, res){
|
module.exports.get = async function(req, res){
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ const {validationResult, matchedData} = require('express-validator');
|
||||||
//local imports
|
//local imports
|
||||||
const {userModel} = require('../../../schemas/userSchema');
|
const {userModel} = require('../../../schemas/userSchema');
|
||||||
const accountUtils = require('../../../utils/sessionUtils.js');
|
const accountUtils = require('../../../utils/sessionUtils.js');
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
|
|
||||||
//api account functions
|
//api account functions
|
||||||
module.exports.post = async function(req, res){
|
module.exports.post = async function(req, res){
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ const {validationResult, matchedData} = require('express-validator');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const accountUtils = require('../../../utils/sessionUtils.js');
|
const accountUtils = require('../../../utils/sessionUtils.js');
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
|
|
||||||
|
|
||||||
//api account functions
|
//api account functions
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const accountUtils = require('../../../utils/sessionUtils.js');
|
const accountUtils = require('../../../utils/sessionUtils.js');
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
|
|
||||||
module.exports.get = async function(req, res){
|
module.exports.get = async function(req, res){
|
||||||
if(req.session.user){
|
if(req.session.user){
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const permissionModel = require('../../../schemas/permissionSchema.js');
|
const permissionModel = require('../../../schemas/permissionSchema.js');
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
|
|
||||||
//api account functions
|
//api account functions
|
||||||
module.exports.get = async function(req, res){
|
module.exports.get = async function(req, res){
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ const {validationResult, matchedData} = require('express-validator');
|
||||||
//local imports
|
//local imports
|
||||||
const {userModel} = require('../../../schemas/userSchema');
|
const {userModel} = require('../../../schemas/userSchema');
|
||||||
const userBanModel = require('../../../schemas/userBanSchema.js');
|
const userBanModel = require('../../../schemas/userBanSchema.js');
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
|
|
||||||
module.exports.post = async function(req, res){
|
module.exports.post = async function(req, res){
|
||||||
try{
|
try{
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ const {validationResult, matchedData} = require('express-validator');
|
||||||
//local imports
|
//local imports
|
||||||
const {userModel} = require('../../../schemas/userSchema');
|
const {userModel} = require('../../../schemas/userSchema');
|
||||||
const accountUtils = require('../../../utils/sessionUtils.js');
|
const accountUtils = require('../../../utils/sessionUtils.js');
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
|
|
||||||
module.exports.post = async function(req, res){
|
module.exports.post = async function(req, res){
|
||||||
const validResult = validationResult(req);
|
const validResult = validationResult(req);
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ const {validationResult, matchedData} = require('express-validator');
|
||||||
const banModel = require('../../../schemas/userBanSchema');
|
const banModel = require('../../../schemas/userBanSchema');
|
||||||
const permissionModel = require('../../../schemas/permissionSchema');
|
const permissionModel = require('../../../schemas/permissionSchema');
|
||||||
const {userModel} = require('../../../schemas/userSchema');
|
const {userModel} = require('../../../schemas/userSchema');
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils');
|
||||||
|
|
||||||
module.exports.get = async function(req, res){
|
module.exports.get = async function(req, res){
|
||||||
try{
|
try{
|
||||||
|
|
@ -45,16 +45,13 @@ module.exports.post = async function(req, res){
|
||||||
|
|
||||||
if(userDB == null){
|
if(userDB == null){
|
||||||
//If the user is null, scream and shout
|
//If the user is null, scream and shout
|
||||||
res.status(400);
|
return errorHandler(res, `User not found.`, 'Bad Query', 400);
|
||||||
return res.send({errors:[{type: "Bad Query", msg: "User not found.", date: new Date()}]});
|
|
||||||
}else if(userDB.user == req.session.user.user){
|
}else if(userDB.user == req.session.user.user){
|
||||||
//If some smart-ass is trying self-privelege escalation
|
//If some smart-ass is trying self-privelege escalation
|
||||||
res.status(401);
|
return errorHandler(res, `Keep it up, maybe I will ban you!`, 'Unauthorized', 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)){
|
}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
|
//If the user is below the original rank of the user they're setting, scream and shout
|
||||||
res.status(401);
|
return errorHandler(res, 'You cannot ban peer/outranking users', 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "You cannot ban peer/outranking users.", date: new Date()}]});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await banModel.banByUserDoc(userDB, permanent, expirationDays);
|
await banModel.banByUserDoc(userDB, permanent, expirationDays);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const {validationResult, matchedData} = require('express-validator');
|
const {validationResult, matchedData} = require('express-validator');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils');
|
||||||
const permissionModel = require('../../../schemas/permissionSchema');
|
const permissionModel = require('../../../schemas/permissionSchema');
|
||||||
const {userModel} = require('../../../schemas/userSchema');
|
const {userModel} = require('../../../schemas/userSchema');
|
||||||
|
|
||||||
|
|
@ -36,20 +36,16 @@ module.exports.post = async function(req, res){
|
||||||
|
|
||||||
if(userDB == null){
|
if(userDB == null){
|
||||||
//If the user is null, scream and shout
|
//If the user is null, scream and shout
|
||||||
res.status(400);
|
return errorHandler(res, 'User not found.', 'Bad Query');
|
||||||
res.send({errors:[{type: "Bad Query", msg: "User not found.", date: new Date()}]});
|
|
||||||
}else if(userDB.user == req.session.user.user){
|
}else if(userDB.user == req.session.user.user){
|
||||||
//If some smart-ass is trying self-privelege escalation
|
//If some smart-ass is trying self-privelege escalation
|
||||||
res.status(401);
|
return errorHandler(res, "No, you can't change your own rank, fuck off.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "No, you can't change your own rank. Fuck off.", date: new Date()}]});
|
|
||||||
}else if(permissionModel.rankToNum(data.rank) >= permissionModel.rankToNum(req.session.user.rank)){
|
}else if(permissionModel.rankToNum(data.rank) >= permissionModel.rankToNum(req.session.user.rank)){
|
||||||
//If the user is below the new rank of the user they're setting, scream and shout
|
//If the user is below the new rank of the user they're setting, scream and shout
|
||||||
res.status(401);
|
return errorHandler(res, "New rank must be below that of the user changing it.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "New rank must be below that of the user changing it.", date: new Date()}]});
|
|
||||||
}else if(permissionModel.rankToNum(userDB.rank) >= permissionModel.rankToNum(req.session.user.rank)){
|
}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
|
//If the user is below the original rank of the user they're setting, scream and shout
|
||||||
res.status(401);
|
return errorHandler(res, "You cannot promote/demote peer/outranking users.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "You cannot promote/demote peer/outranking users.", date: new Date()}]});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
userDB.rank = data.rank;
|
userDB.rank = data.rank;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
const channelModel = require('../../../schemas/channel/channelSchema.js');
|
const channelModel = require('../../../schemas/channel/channelSchema.js');
|
||||||
|
|
||||||
//api list channel functions
|
//api list channel functions
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
const {userModel} = require('../../../schemas/userSchema');
|
const {userModel} = require('../../../schemas/userSchema');
|
||||||
|
|
||||||
//api list account functions
|
//api list account functions
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const {validationResult, matchedData} = require('express-validator');
|
const {validationResult, matchedData} = require('express-validator');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
const permissionModel = require('../../../schemas/permissionSchema.js');
|
const permissionModel = require('../../../schemas/permissionSchema.js');
|
||||||
|
|
||||||
//api permissions functions
|
//api permissions functions
|
||||||
|
|
@ -76,8 +76,7 @@ module.exports.post = async function(req, res){
|
||||||
|
|
||||||
//Flip our shit if something's wrong.
|
//Flip our shit if something's wrong.
|
||||||
if(permError){
|
if(permError){
|
||||||
res.status(401);
|
return errorHandler(res, "New rank must be equal to or below that of the user changing it.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "New rank must be equal to or below that of the user changing it.", date: new Date()}]});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await perms.save();
|
await perms.save();
|
||||||
|
|
|
||||||
|
|
@ -40,14 +40,44 @@ module.exports.post = async function(req, res){
|
||||||
//if they're empty
|
//if they're empty
|
||||||
if(validResult.isEmpty()){
|
if(validResult.isEmpty()){
|
||||||
const {command} = matchedData(req);
|
const {command} = matchedData(req);
|
||||||
const foundToke = await tokeCommandModel.findOne({command});
|
const tokeDB = await tokeCommandModel.findOne({command});
|
||||||
|
|
||||||
if(foundToke != null){
|
if(tokeDB != null){
|
||||||
return errorHandler(res, `Toke command '!${command}' already exists!`);
|
return errorHandler(res, `Toke command '!${command}' already exists!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Add the toke
|
//Add the toke
|
||||||
const tokeDB = await tokeCommandModel.create({command});
|
await tokeCommandModel.create({command});
|
||||||
|
|
||||||
|
//Return the updated command list
|
||||||
|
res.status(200);
|
||||||
|
return res.send(await tokeCommandModel.getCommandStrings());
|
||||||
|
}else{
|
||||||
|
//otherwise scream
|
||||||
|
res.status(400);
|
||||||
|
return res.send({errors: validResult.array()})
|
||||||
|
}
|
||||||
|
|
||||||
|
}catch(err){
|
||||||
|
return exceptionHandler(res, err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.delete = async function(req, res){
|
||||||
|
try{
|
||||||
|
//get validation error results
|
||||||
|
const validResult = validationResult(req);
|
||||||
|
|
||||||
|
//if they're empty
|
||||||
|
if(validResult.isEmpty()){
|
||||||
|
const {command} = matchedData(req);
|
||||||
|
const tokeDB = await tokeCommandModel.findOne({command});
|
||||||
|
|
||||||
|
if(tokeDB == null){
|
||||||
|
return errorHandler(res, `Cannot delete non-existant toke command '!${command}'!`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await tokeCommandModel.deleteOne({_id: tokeDB._id});
|
||||||
|
|
||||||
//Return the updated command list
|
//Return the updated command list
|
||||||
res.status(200);
|
res.status(200);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const {validationResult, matchedData} = require('express-validator');
|
const {validationResult, matchedData} = require('express-validator');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
const {userModel} = require('../../../schemas/userSchema.js');
|
const {userModel} = require('../../../schemas/userSchema.js');
|
||||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||||
const permissionModel = require('../../../schemas/permissionSchema.js')
|
const permissionModel = require('../../../schemas/permissionSchema.js')
|
||||||
|
|
@ -65,16 +65,13 @@ module.exports.post = async function(req, res){
|
||||||
|
|
||||||
if(targetDB == null){
|
if(targetDB == null){
|
||||||
//If the user is null, scream and shout
|
//If the user is null, scream and shout
|
||||||
res.status(400);
|
return errorHandler(res, `User not found.`, 'Bad Query', 400);
|
||||||
return res.send({errors:[{type: "Bad Query", msg: "User not found.", date: new Date()}]});
|
|
||||||
}else if(targetDB.user == req.session.user.user){
|
}else if(targetDB.user == req.session.user.user){
|
||||||
//If some smart-ass is trying to self-ban
|
//If some smart-ass is trying to self-ban
|
||||||
res.status(401);
|
return errorHandler(res, `Keep it up, maybe I will ban you!`, 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "Keep it up, maybe I will ban you!", date: new Date()}]});
|
|
||||||
}else if(permissionModel.rankToNum(targetRank) >= permissionModel.rankToNum(initiatorRank)){
|
}else if(permissionModel.rankToNum(targetRank) >= permissionModel.rankToNum(initiatorRank)){
|
||||||
//If the user is trying to ban a peer/outranking user
|
//If the user is trying to ban a peer/outranking user
|
||||||
res.status(401);
|
return errorHandler(res, 'You cannot ban peer/outranking users', 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "You cannot ban peer/outranking users.", date: new Date()}]});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await chanDB.banByUserDoc(targetDB, expirationDays, banAlts);
|
await chanDB.banByUserDoc(targetDB, expirationDays, banAlts);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const {validationResult, matchedData} = require('express-validator');
|
const {validationResult, matchedData} = require('express-validator');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||||
|
|
||||||
//api account functions
|
//api account functions
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
|
|
||||||
//api account functions
|
//api account functions
|
||||||
module.exports.get = async function(req, res){
|
module.exports.get = async function(req, res){
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const {validationResult, matchedData} = require('express-validator');
|
const {validationResult, matchedData} = require('express-validator');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
const channelModel = require('../../../schemas/channel/channelSchema.js');
|
const channelModel = require('../../../schemas/channel/channelSchema.js');
|
||||||
const permissionModel = require('../../../schemas/permissionSchema.js');
|
const permissionModel = require('../../../schemas/permissionSchema.js');
|
||||||
|
|
||||||
|
|
@ -81,8 +81,7 @@ module.exports.post = async function(req, res){
|
||||||
|
|
||||||
//Flip our shit if something's wrong.
|
//Flip our shit if something's wrong.
|
||||||
if(permError){
|
if(permError){
|
||||||
res.status(401);
|
return errorHandler(res, "New rank must be equal to or below that of the user changing it.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "New rank must be equal to or below that of the user changing it.", date: new Date()}]});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await chanDB.save();
|
await chanDB.save();
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const {validationResult, matchedData} = require('express-validator');
|
const {validationResult, matchedData} = require('express-validator');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils');
|
||||||
const permissionModel = require('../../../schemas/permissionSchema');
|
const permissionModel = require('../../../schemas/permissionSchema');
|
||||||
const {userModel} = require('../../../schemas/userSchema');
|
const {userModel} = require('../../../schemas/userSchema');
|
||||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||||
|
|
@ -80,20 +80,16 @@ module.exports.post = async function(req, res){
|
||||||
|
|
||||||
if(data.user == null || userDB == null){
|
if(data.user == null || userDB == null){
|
||||||
//If the user is null, scream and shout
|
//If the user is null, scream and shout
|
||||||
res.status(400);
|
return errorHandler(res, 'User not found.', 'Bad Query');
|
||||||
return res.send({errors:[{type: "Bad Query", msg: "User not found.", date: new Date()}]});
|
|
||||||
}else if(data.user == req.session.user.user){
|
}else if(data.user == req.session.user.user){
|
||||||
//If some smart-ass is trying self-privelege escalation
|
//If some smart-ass is trying self-privelege escalation
|
||||||
res.status(401);
|
return errorHandler(res, "No, you can't change your own rank, fuck off.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "No, you can't change your own rank. Fuck off.", date: new Date()}]});
|
|
||||||
}else if(permissionModel.rankToNum(data.rank) >= permissionModel.rankToNum(chanRank)){
|
}else if(permissionModel.rankToNum(data.rank) >= permissionModel.rankToNum(chanRank)){
|
||||||
//If the user is below the new rank of the user they're setting, scream and shout
|
//If the user is below the new rank of the user they're setting, scream and shout
|
||||||
res.status(401);
|
return errorHandler(res, "New rank must be below that of the user changing it.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "New rank must be below that of the user changing it.", date: new Date()}]});
|
|
||||||
}else if(permissionModel.rankToNum(targetChanRank) >= permissionModel.rankToNum(chanRank)){
|
}else if(permissionModel.rankToNum(targetChanRank) >= permissionModel.rankToNum(chanRank)){
|
||||||
//If the user is below the original rank of the user they're setting, scream and shout
|
//If the user is below the original rank of the user they're setting, scream and shout
|
||||||
res.status(401);
|
return errorHandler(res, "You cannot promote/demote peer/outranking users.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "You cannot promote/demote peer/outranking users.", date: new Date()}]});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set rank
|
//Set rank
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const {validationResult, matchedData} = require('express-validator');
|
const {validationResult, matchedData} = require('express-validator');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
const {userModel} = require('../../../schemas/userSchema.js');
|
const {userModel} = require('../../../schemas/userSchema.js');
|
||||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const {validationResult, matchedData} = require('express-validator');
|
const {validationResult, matchedData} = require('express-validator');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../../../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../../../utils/loggerUtils.js');
|
||||||
const channelModel = require('../../../schemas/channel/channelSchema');
|
const channelModel = require('../../../schemas/channel/channelSchema');
|
||||||
|
|
||||||
//api account functions
|
//api account functions
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const config = require('../../config.json');
|
const config = require('../../config.json');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../utils/loggerUtils');
|
const {exceptionHandler, errorHandler} = require('../utils/loggerUtils');
|
||||||
const channelModel = require('../schemas/channel/channelSchema');
|
const channelModel = require('../schemas/channel/channelSchema');
|
||||||
const permissionModel = require('../schemas/permissionSchema');
|
const permissionModel = require('../schemas/permissionSchema');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
const config = require('../../config.json');
|
const config = require('../../config.json');
|
||||||
|
|
||||||
//local imports
|
//local imports
|
||||||
const {exceptionHandler} = require('../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../utils/loggerUtils.js');
|
||||||
const channelModel = require('../schemas/channel/channelSchema');
|
const channelModel = require('../schemas/channel/channelSchema');
|
||||||
|
|
||||||
//root index functions
|
//root index functions
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//Local Imports
|
//Local Imports
|
||||||
const {userModel} = require('../schemas/userSchema');
|
const {userModel} = require('../schemas/userSchema');
|
||||||
const {exceptionHandler} = require('../utils/loggerUtils.js');
|
const {exceptionHandler, errorHandler} = require('../utils/loggerUtils.js');
|
||||||
|
|
||||||
//Config
|
//Config
|
||||||
const config = require('../../config.json');
|
const config = require('../../config.json');
|
||||||
|
|
|
||||||
|
|
@ -46,5 +46,6 @@ router.post('/ban', permissionSchema.reqPermCheck("banUser"), accountValidator.
|
||||||
router.delete('/ban', permissionSchema.reqPermCheck("banUser"), accountValidator.user(), banController.delete);
|
router.delete('/ban', permissionSchema.reqPermCheck("banUser"), accountValidator.user(), banController.delete);
|
||||||
router.get('/tokeCommands', permissionSchema.reqPermCheck("adminPanel"), tokeCommandController.get);
|
router.get('/tokeCommands', permissionSchema.reqPermCheck("adminPanel"), tokeCommandController.get);
|
||||||
router.post('/tokeCommands', permissionSchema.reqPermCheck("editTokeCommands"), tokebotValidator.command(), tokeCommandController.post);
|
router.post('/tokeCommands', permissionSchema.reqPermCheck("editTokeCommands"), tokebotValidator.command(), tokeCommandController.post);
|
||||||
|
router.delete('/tokeCommands', permissionSchema.reqPermCheck("editTokeCommands"), tokebotValidator.command(), tokeCommandController.delete);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
|
||||||
|
|
@ -225,8 +225,7 @@ channelSchema.statics.reqPermCheck = function(perm, chanField = "chanName"){
|
||||||
next();
|
next();
|
||||||
}else{
|
}else{
|
||||||
//If not, prevent the request from going through and tell them why
|
//If not, prevent the request from going through and tell them why
|
||||||
res.status(401);
|
return errorHandler(res, "You do not have a high enough rank to access this resource.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "You do not have a high enough rank to access this resource.", date: new Date()}]});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -155,8 +155,7 @@ permissionSchema.statics.reqPermCheck = function(perm){
|
||||||
if(await permissionSchema.statics.permCheck(req.session.user, perm)){
|
if(await permissionSchema.statics.permCheck(req.session.user, perm)){
|
||||||
next();
|
next();
|
||||||
}else{
|
}else{
|
||||||
res.status(401);
|
return errorHandler(res, "You do not have a high enough rank to access this resource.", 'Unauthorized', 401);
|
||||||
return res.send({errors:[{type: "Unauthorized", msg: "You do not have a high enough rank to access this resource.", date: new Date()}]});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,14 +15,13 @@ You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
|
||||||
|
|
||||||
//At some point this will be a bit more advanced, right now it's just a placeholder :P
|
//At some point this will be a bit more advanced, right now it's just a placeholder :P
|
||||||
module.exports.errorHandler = function(res, msg, type = "Generic"){
|
module.exports.errorHandler = function(res, msg, type = "Generic", status = 400){
|
||||||
res.status(400);
|
res.status(status);
|
||||||
return res.send({errors: [{type, msg, date: new Date()}]});
|
return res.send({errors: [{type, msg, date: new Date()}]});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.exceptionHandler = function(res, err){
|
module.exports.exceptionHandler = function(res, err){
|
||||||
//if not yell at the browser for fucking up, and tell it what it did wrong.
|
//if not yell at the browser for fucking up, and tell it what it did wrong.
|
||||||
res.status(400);
|
|
||||||
module.exports.errorHandler(res, err.message, "Caught Exception");
|
module.exports.errorHandler(res, err.message, "Caught Exception");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -198,6 +198,23 @@ class canopyAdminUtils{
|
||||||
utils.ux.displayResponseError(await response.json());
|
utils.ux.displayResponseError(await response.json());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deleteTokeCommand(command){
|
||||||
|
var response = await fetch(`/api/admin/tokeCommands`,{
|
||||||
|
method: "DELETE",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json"
|
||||||
|
},
|
||||||
|
//Unfortunately JSON doesn't natively handle ES6 maps, and god forbid someone update the standard in a way that's backwards compatible...
|
||||||
|
body: JSON.stringify({command})
|
||||||
|
});
|
||||||
|
|
||||||
|
if(response.status == 200){
|
||||||
|
return await response.json();
|
||||||
|
}else{
|
||||||
|
utils.ux.displayResponseError(await response.json());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class adminUserList{
|
class adminUserList{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue