rename isAuthenticated middleware to requireAuthenticated

pull/4/head
Cameron Clough 2022-03-24 00:00:25 +00:00
parent 8de0b2f8dd
commit 91d094eede
No known key found for this signature in database
GPG Key ID: BFB3B74B026ED43F
8 changed files with 30 additions and 25 deletions

View File

@ -5,7 +5,7 @@ export const getAccount = async (req, res, next) => {
next(); next();
}; };
export const isAuthenticated = async (req, res, next) => { export const requireAuthenticated = async (req, res, next) => {
const account = await authenticationController.getAuthenticatedAccount(req); const account = await authenticationController.getAuthenticatedAccount(req);
if (!account) { if (!account) {
res.status(401).json({ res.status(401).json({

View File

@ -2,13 +2,13 @@ import bodyParser from 'body-parser';
import express from 'express'; import express from 'express';
import authenticationController from '../../../controllers/authentication'; import authenticationController from '../../../controllers/authentication';
import { isAuthenticated } from '../../../middlewares/authentication'; import { requireAuthenticated } from '../../../middlewares/authentication';
import { createAccount, verifyEmailToken } from '../../../controllers/users'; import { createAccount, verifyEmailToken } from '../../../controllers/users';
// /api/auth // /api/auth
const router = express.Router(); const router = express.Router();
router.get('/session', isAuthenticated, async (req, res) => { router.get('/session', requireAuthenticated, async (req, res) => {
return res.status(200).json({ return res.status(200).json({
success: true, success: true,
data: { data: {

View File

@ -2,7 +2,7 @@ import express from 'express';
import log4js from 'log4js'; import log4js from 'log4js';
import { getURL, getToken } from '../../../controllers/authentication/oauth/google'; import { getURL, getToken } from '../../../controllers/authentication/oauth/google';
import { isAuthenticated } from '../../../middlewares/authentication'; import { requireAuthenticated } from '../../../middlewares/authentication';
const router = express.Router(); const router = express.Router();
const logger = log4js.getLogger(); const logger = log4js.getLogger();
@ -32,7 +32,7 @@ router.get('/authentication/oauth/:provider', async (req, res) => {
} }
}); });
router.get('/authentication/oauth/pair/:provider', isAuthenticated, async (req, res) => { router.get('/authentication/oauth/pair/:provider', requireAuthenticated, async (req, res) => {
res.status(200); res.status(200);
}); });

View File

@ -1,10 +1,10 @@
import express from 'express'; import express from 'express';
import { isAuthenticated } from '../../../middlewares/authentication'; import { requireAuthenticated } from '../../../middlewares/authentication';
const router = express.Router(); const router = express.Router();
router.get('/authentication/twofactor/enrol', isAuthenticated, async () => { router.get('/authentication/twofactor/enrol', requireAuthenticated, async () => {
// TODO: implementation // TODO: implementation
}); });

View File

@ -4,7 +4,7 @@ import dirTree from 'directory-tree';
import express from 'express'; import express from 'express';
import log4js from 'log4js'; import log4js from 'log4js';
import { isAuthenticated } from '../../middlewares/authentication'; import { requireAuthenticated } from '../../middlewares/authentication';
import deviceController from '../../controllers/devices'; import deviceController from '../../controllers/devices';
import { MutateDevice } from '../../schema/routes/devices'; import { MutateDevice } from '../../schema/routes/devices';
@ -13,7 +13,7 @@ const logger = log4js.getLogger();
// /api/devices // /api/devices
const router = express.Router(); const router = express.Router();
router.get('/', isAuthenticated, async (req, res) => { router.get('/', requireAuthenticated, async (req, res) => {
const { account: { id } } = req; const { account: { id } } = req;
const devices = await deviceController.getDevices(id); const devices = await deviceController.getDevices(id);
@ -35,14 +35,14 @@ router.get('/', isAuthenticated, async (req, res) => {
} }
*/ */
router.put('/:dongleId', [isAuthenticated, bodyParser.json()], async (req, res) => { router.put('/:dongleId', [requireAuthenticated, bodyParser.json()], async (req, res) => {
const { body } = req; const { body } = req;
logger.info(MutateDevice.isValid(body)); logger.info(MutateDevice.isValid(body));
// TODO: response? // TODO: response?
return res.json({ success: true }); return res.json({ success: true });
}); });
router.get('/:dongleId/drives/:driveIdentifier/segment', isAuthenticated, async (req, res) => { router.get('/:dongleId/drives/:driveIdentifier/segment', requireAuthenticated, async (req, res) => {
const { const {
account: { id: accountId }, account: { id: accountId },
params: { params: {
@ -67,7 +67,7 @@ router.get('/:dongleId/drives/:driveIdentifier/segment', isAuthenticated, async
return res.json({ success: true, msg: 'ok', data: directoryTree }); return res.json({ success: true, msg: 'ok', data: directoryTree });
}); });
router.get('/:dongleId/drives', isAuthenticated, async (req, res) => { router.get('/:dongleId/drives', requireAuthenticated, async (req, res) => {
const { dongleId } = req.params; const { dongleId } = req.params;
const { deleted } = req.query; const { deleted } = req.query;
const accountId = req.account.id; const accountId = req.account.id;
@ -82,7 +82,7 @@ router.get('/:dongleId/drives', isAuthenticated, async (req, res) => {
return res.json({ success: true, data: drives }); return res.json({ success: true, data: drives });
}); });
router.get('/:dongleId/bootlogs', isAuthenticated, async (req, res) => { router.get('/:dongleId/bootlogs', requireAuthenticated, async (req, res) => {
const { dongleId } = req.params; const { dongleId } = req.params;
const accountId = req.account.id; const accountId = req.account.id;
const isUserAuthorised = await deviceController.isUserAuthorised(dongleId, accountId); const isUserAuthorised = await deviceController.isUserAuthorised(dongleId, accountId);
@ -95,7 +95,7 @@ router.get('/:dongleId/bootlogs', isAuthenticated, async (req, res) => {
return res.json({ success: true, data: bootlogs }); return res.json({ success: true, data: bootlogs });
}); });
router.get('/:dongleId/crashlogs', isAuthenticated, async (req, res) => { router.get('/:dongleId/crashlogs', requireAuthenticated, async (req, res) => {
const { dongleId } = req.params; const { dongleId } = req.params;
const accountId = req.account.id; const accountId = req.account.id;
const isUserAuthorised = await deviceController.isUserAuthorised(dongleId, accountId); const isUserAuthorised = await deviceController.isUserAuthorised(dongleId, accountId);

View File

@ -3,7 +3,7 @@ import express from 'express';
import { AthenaReturnedData } from '../../../models'; import { AthenaReturnedData } from '../../../models';
import authenticationController from '../../controllers/authentication'; import authenticationController from '../../controllers/authentication';
import deviceController from '../../controllers/devices'; import deviceController from '../../controllers/devices';
import { isAuthenticated } from '../../middlewares/authentication'; import { requireAuthenticated } from '../../middlewares/authentication';
// /api/realtime // /api/realtime
const router = express.Router(); const router = express.Router();
@ -28,7 +28,7 @@ const whitelistParams = {
// TODO: use middleware to get device from dongle id // TODO: use middleware to get device from dongle id
router.get('/:dongleId/connected', isAuthenticated, async (req, res) => { router.get('/:dongleId/connected', requireAuthenticated, async (req, res) => {
const { account, params: { dongleId } } = req; const { account, params: { dongleId } } = req;
const device = await deviceController.getDeviceFromDongleId(dongleId); const device = await deviceController.getDeviceFromDongleId(dongleId);
@ -61,7 +61,7 @@ router.get('/:dongleId/connected', isAuthenticated, async (req, res) => {
}); });
// TODO: change to POST request // TODO: change to POST request
router.get('/:dongleId/send/:method/', isAuthenticated, async (req, res) => { router.get('/:dongleId/send/:method/', requireAuthenticated, async (req, res) => {
const { account, params: { dongleId, method } } = req; const { account, params: { dongleId, method } } = req;
if (!whitelistParams[method.toLowerCase()]) { if (!whitelistParams[method.toLowerCase()]) {

View File

@ -4,7 +4,7 @@ import cookieParser from 'cookie-parser';
import controllers from '../../controllers'; import controllers from '../../controllers';
import deviceController from '../../controllers/devices'; import deviceController from '../../controllers/devices';
import { isAuthenticated } from '../../middlewares/authentication'; import { requireAuthenticated } from '../../middlewares/authentication';
// TODO Remove this, pending on removing all auth logic from routes // TODO Remove this, pending on removing all auth logic from routes
@ -59,7 +59,7 @@ router.get('/', runAsyncWrapper(async (req, res) => {
}); });
})); }));
router.get('/overview', isAuthenticated, runAsyncWrapper(async (req, res) => { router.get('/overview', requireAuthenticated, runAsyncWrapper(async (req, res) => {
const { account } = req; const { account } = req;
const devices = await deviceController.getDevices(account.id); const devices = await deviceController.getDevices(account.id);
@ -74,7 +74,7 @@ router.get('/overview', isAuthenticated, runAsyncWrapper(async (req, res) => {
}); });
})); }));
router.get('/unpair_device/:dongleId', isAuthenticated, runAsyncWrapper(async (req, res) => { router.get('/unpair_device/:dongleId', requireAuthenticated, runAsyncWrapper(async (req, res) => {
const { account, params: { dongleId } } = req; const { account, params: { dongleId } } = req;
const device = await deviceController.getDeviceFromDongleId(dongleId); const device = await deviceController.getDeviceFromDongleId(dongleId);
@ -92,15 +92,20 @@ router.get('/unpair_device/:dongleId', isAuthenticated, runAsyncWrapper(async (r
return res.status(200).json({ success: true }); return res.status(200).json({ success: true });
})); }));
router.post('/pair_device', [isAuthenticated, bodyParser.urlencoded({ extended: true })], runAsyncWrapper(async (req, res) => { router.post('/pair_device', [requireAuthenticated, bodyParser.urlencoded({ extended: true })], runAsyncWrapper(async (req, res) => {
const { account, body: { qrString } } = req; const { qrString } = req.body;
if (!qrString) { if (!qrString) {
return res.json({ success: false, msg: 'BAD_REQUEST', status: 400 }); return res.json({ success: false, msg: 'BAD_REQUEST', status: 400 });
} }
const { account } = req;
const pairDevice = await controllers.devices.pairDevice(account, qrString); const pairDevice = await controllers.devices.pairDevice(account, qrString);
if (!pairDevice.success) { if (!pairDevice.success) {
return res.json({ success: false, msg: 'error', data: pairDevice }); return res.json({
success: false,
msg: 'error',
data: pairDevice,
});
} }
return res.json({ return res.json({
@ -111,7 +116,7 @@ router.post('/pair_device', [isAuthenticated, bodyParser.urlencoded({ extended:
}); });
})); }));
router.post('/password/change', [isAuthenticated, bodyParser.urlencoded({ extended: true })], runAsyncWrapper(async (req, res) => { router.post('/password/change', [requireAuthenticated, bodyParser.urlencoded({ extended: true })], runAsyncWrapper(async (req, res) => {
const { account, body: { oldPassword, newPassword } } = req; const { account, body: { oldPassword, newPassword } } = req;
const result = await controllers.authentication.changePassword( const result = await controllers.authentication.changePassword(
account, account,

View File

@ -12,7 +12,7 @@ import helperController from '../controllers/helpers';
import mailingController from '../controllers/mailing'; import mailingController from '../controllers/mailing';
import deviceController from '../controllers/devices'; import deviceController from '../controllers/devices';
import userController from '../controllers/users'; import userController from '../controllers/users';
import { getAccount, isAuthenticated } from '../middlewares/authentication'; import { getAccount, requireAuthenticated } from '../middlewares/authentication';
const logger = log4js.getLogger(); const logger = log4js.getLogger();
let models; let models;