mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
fix: protect the one-click demo accounts endpoints
This commit is contained in:
@@ -4,7 +4,7 @@ import { body } from 'express-validator';
|
|||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
import BaseController from '@/api/controllers/BaseController';
|
import BaseController from '@/api/controllers/BaseController';
|
||||||
import { OneClickDemoApplication } from '@/services/OneClickDemo/OneClickDemoApplication';
|
import { OneClickDemoApplication } from '@/services/OneClickDemo/OneClickDemoApplication';
|
||||||
|
import config from '@/config';
|
||||||
@Service()
|
@Service()
|
||||||
export class OneClickDemoController extends BaseController {
|
export class OneClickDemoController extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
@@ -16,13 +16,29 @@ export class OneClickDemoController extends BaseController {
|
|||||||
router() {
|
router() {
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post('/one_click', asyncMiddleware(this.oneClickDemo.bind(this)));
|
// Protects the endpoints if the feature is not enabled.
|
||||||
|
const protectMiddleware = (
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) => {
|
||||||
|
// Add your protection logic here
|
||||||
|
if (config.oneClickDemoAccounts) {
|
||||||
|
next();
|
||||||
|
} else {
|
||||||
|
res.status(403).send({ message: 'Forbidden' });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
router.post(
|
||||||
|
'/one_click',
|
||||||
|
protectMiddleware,
|
||||||
|
asyncMiddleware(this.oneClickDemo.bind(this))
|
||||||
|
);
|
||||||
router.post(
|
router.post(
|
||||||
'/one_click_signin',
|
'/one_click_signin',
|
||||||
[
|
[body('demo_id').exists()],
|
||||||
body('demo_id').exists(),
|
|
||||||
],
|
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
|
protectMiddleware,
|
||||||
asyncMiddleware(this.oneClickSignIn.bind(this))
|
asyncMiddleware(this.oneClickSignIn.bind(this))
|
||||||
);
|
);
|
||||||
return router;
|
return router;
|
||||||
|
|||||||
Reference in New Issue
Block a user