diff --git a/api/v1/content.js b/api/v1/content.js index 3f41348..d62ce82 100755 --- a/api/v1/content.js +++ b/api/v1/content.js @@ -120,7 +120,7 @@ app.get('/category/:category/info', [ users: users } }); -})); +}, undefined, config.roleMap.USER)); app.get('/category/list', authenticateEndpoint(async (req, res, user) => { let count = parseInt(req.query.count); @@ -136,6 +136,6 @@ app.get('/category/list', authenticateEndpoint(async (req, res, user) => { message: 'SUCCESS_CATEGORY_LIST_FETCHED', categories }); -})); +}, undefined, config.roleMap.USER)); module.exports = app; \ No newline at end of file diff --git a/api/v1/users.js b/api/v1/users.js index 7155e1a..30eeb7f 100755 --- a/api/v1/users.js +++ b/api/v1/users.js @@ -22,11 +22,26 @@ const createAccountLimiter = rateLimit({ message: "You are being rate limited" }); +app.get('/account/create/info', async (req, res) => { + const restrictions = config.restrictions.signup; + let requiresCode = false; + if (restrictions && restrictions.specialCode) { + requiresCode = true; + } + + res.json({ + error: false, + message: 'SUCCESS_ACCOUNT_CREATE_INFO_FETCH', + requiresSpecialCode: requiresCode + }); +}); + app.post('/account/create', [ createAccountLimiter, body('username').not().isEmpty().trim().isLength({ min: 3, max: 32 }).isAlphanumeric(), body('email').not().isEmpty().isEmail().normalizeEmail(), - body('password').not().isEmpty().isLength({ min: 8, max: 128 }) + body('password').not().isEmpty().isLength({ min: 8, max: 128 }), + body('specialCode').optional().isLength({ min: 12, max: 12 }).isAlphanumeric() ], async (req, res) => { try { const errors = validationResult(req); @@ -34,6 +49,22 @@ app.post('/account/create', [ res.status(400).json({ error: true, message: 'ERROR_REQUEST_INVALID_DATA', errors: errors.array() }); return; } + + const restrictions = config.restrictions.signup; + if (restrictions && restrictions.specialCode) { + const passedSpecialCode = req.body.specialCode; + const specialCode = restrictions.specialCode; + + if (passedSpecialCode && specialCode) { + if (specialCode !== passedSpecialCode) { + res.status(401).json({ error: true, message: 'ERROR_REQUEST_SPECIAL_CODE_MISSING', errors: [{ msg: 'No specialCode passed', param: 'specialCode', location: 'body' }] }); + return false; + } + } else { + res.status(401).json({ error: true, message: 'ERROR_REQUEST_SPECIAL_CODE_MISSING', errors: [{ msg: 'No specialCode passed', param: 'specialCode', location: 'body' }] }); + return false; + } + } const username = req.body.username; @@ -171,7 +202,7 @@ app.get('/user/:userid/info', [ message: 'SUCCESS_USER_DATA_FETCHED', user: await otherUser.getPublicObject(), }); -})); +}, undefined, config.roleMap.USER)); app.post('/browser/token/clear', authenticateEndpoint((req, res, user) => { res.clearCookie('token'); diff --git a/app/auth.html b/app/auth.html index aa3f41b..4f76fb9 100755 --- a/app/auth.html +++ b/app/auth.html @@ -47,13 +47,26 @@ +
+ The owner of this Brainlet instance has made it so that signing up requires a special code. +
+