Implemented permabans

This commit is contained in:
2021-03-28 08:32:28 +11:00
parent e597974581
commit 547d5dba1c
7 changed files with 106 additions and 1 deletions
+36
View File
@@ -1,10 +1,46 @@
const express = require('express');
const router = express.Router();
const { accounts } = require('../database/models');
//middleware
const tokenAuth = require('../utilities/token-auth');
router.use(tokenAuth);
//handle ban stuff
router.use(async (req, res, next) => {
const record = await accounts.findOne({
where: {
username: req.user.username
}
});
if (!record) {
return res.status(500).send('Account not found in banning middleware');
}
if (record.banned) {
return res.status(403).send('This account has been banned');
}
next();
});
//handle mod stuff
router.use((req, res, next) => {
//check the user's mod status
if (!req.user.mod) {
return res.status(401).send('Mods only');
}
next();
});
//routes
router.post('/banuser', require('./ban-user'));
//handle admin stuff
router.use((req, res, next) => {
//check the user's admin status
if (!req.user.admin) {