diff --git a/backend/middleware/validator.js b/backend/middleware/validator.js index 403de22..5af49f1 100644 --- a/backend/middleware/validator.js +++ b/backend/middleware/validator.js @@ -13,9 +13,10 @@ const validEmailReg = new RegExp( const validNumberReg = new RegExp(/^\+?\d{1,3}[-.\s]?\(?\d{1,4}\)?[-.\s]?\d{1,4}[-.\s]?\d{1,9}$/); const pathTraversal = new RegExp(/(\.\.(\/|\\))+/); const alphanumeric = new RegExp(/^[A-Za-z0-9-_]+$/); +const miroTalkType = new RegExp(/^(SFU|P2P|C2C|BRO)$/); const checkData = (req, res, next) => { - const { username, email, phone, password, room, tag } = req.body; + const { username, email, phone, password, room, tag, type } = req.body; if (username) { const validUsername = isValidUsername(username); log.debug('Validator', { username: validUsername }); @@ -58,6 +59,13 @@ const checkData = (req, res, next) => { return res.status(201).json({ message: validTag }); } } + if (type) { + const validType = isValidType(type); + log.debug('Validator', { type: validType }); + if (validType != true) { + return res.status(201).json({ message: validType }); + } + } return next(); }; @@ -100,17 +108,24 @@ function isValidPassword(password) { return true; } -function isValidRoom(room){ +function isValidRoom(room) { if (room.match(pathTraversal)) { return '⚠️ The room name is not valid!'; - }; + } return true; } -function isValidTag(tag){ +function isValidTag(tag) { if (!tag.match(alphanumeric)) { return '⚠️ The Tag must be alphanumeric!'; - }; + } + return true; +} + +function isValidType(type) { + if (!type.match(miroTalkType)) { + return '⚠️ Type must be one of SFU/P2P/C2C/BRO!'; + } return true; } diff --git a/frontend/js/client.js b/frontend/js/client.js index 3716626..cdd3455 100644 --- a/frontend/js/client.js +++ b/frontend/js/client.js @@ -799,7 +799,7 @@ function delAllRows() { }); } -function removeRow(id){ +function removeRow(id) { dataTable.row(`#${id}`).remove().draw(); }