diff --git a/backend/server/index.js b/backend/server/index.js index 0ade59764..b3e06c804 100644 --- a/backend/server/index.js +++ b/backend/server/index.js @@ -3,14 +3,16 @@ const server = require("http").createServer(app); const cors = require("cors"); const Rooms = require("./Utils/Rooms"); const io = require("socket.io")(server, { origins: "*:*" }); - +const helmet = require('helmet'); +const rateLimiter = require('./rateLimiter'); // instantiate a new rooms object to store all clients in the room const rooms = new Rooms(); +app.use(helmet()); // io.origins(["http://localhost:3000"]); app.use(cors()); -io.on("connection", (socket) => { +io.on("connection" , (socket) => { let roomId = 0; let userName = ""; let userId = 1; @@ -65,7 +67,7 @@ io.on("connection", (socket) => { }); }); -app.get("/", (req, res) => { +app.get("/",rateLimiter , (req, res) => { res.send({ response: "Server is up and Running." }).status(200); }); diff --git a/backend/server/package-lock.json b/backend/server/package-lock.json index 1bc630b45..37c874ebb 100644 --- a/backend/server/package-lock.json +++ b/backend/server/package-lock.json @@ -543,6 +543,11 @@ "vary": "~1.1.2" } }, + "express-rate-limit": { + "version": "5.2.6", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-5.2.6.tgz", + "integrity": "sha512-nE96xaxGfxiS5jP3tD3kIW1Jg9yQgX0rXCs3rCkZtmbWHEGyotwaezkLj7bnB41Z0uaOLM8W4AX6qHao4IZ2YA==" + }, "fill-range": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", @@ -651,6 +656,11 @@ "resolved": "https://registry.npmjs.org/has-yarn/-/has-yarn-2.1.0.tgz", "integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==" }, + "helmet": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/helmet/-/helmet-4.4.1.tgz", + "integrity": "sha512-G8tp0wUMI7i8wkMk2xLcEvESg5PiCitFMYgGRc/PwULB0RVhTP5GFdxOwvJwp9XVha8CuS8mnhmE8I/8dx/pbw==" + }, "http-cache-semantics": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", diff --git a/backend/server/package.json b/backend/server/package.json index b35fa0caa..ee7eb0677 100644 --- a/backend/server/package.json +++ b/backend/server/package.json @@ -12,6 +12,8 @@ "dependencies": { "cors": "^2.8.5", "express": "^4.17.1", + "express-rate-limit": "^5.2.6", + "helmet": "^4.4.1", "nodemon": "^2.0.6", "socket.io": "^2.4.1" } diff --git a/backend/server/rateLimiter.js b/backend/server/rateLimiter.js new file mode 100644 index 000000000..5922d4705 --- /dev/null +++ b/backend/server/rateLimiter.js @@ -0,0 +1,10 @@ +const rateLimit = require('express-rate-limit'); + +const limit = rateLimit({ + windowMs: 1 * 60 * 1000, + max: 100, + message: + "Too many requests created from this IP, please try again after an hour" + }); + + module.exports = limit; \ No newline at end of file diff --git a/frontend/syntaxmeets/package-lock.json b/frontend/syntaxmeets/package-lock.json index bbfe2a488..f4537b350 100644 --- a/frontend/syntaxmeets/package-lock.json +++ b/frontend/syntaxmeets/package-lock.json @@ -6703,6 +6703,15 @@ "resolved": "https://registry.npmjs.org/emittery/-/emittery-0.7.2.tgz", "integrity": "sha512-A8OG5SR/ij3SsJdWDJdkkSYUjQdCUx6APQXem0SaEePBSRg4eymGYwBkKo1Y6DU+af/Jn2dBQqDBvjnr9Vi8nQ==" }, + "emoji-mart": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/emoji-mart/-/emoji-mart-3.0.1.tgz", + "integrity": "sha512-sxpmMKxqLvcscu6mFn9ITHeZNkGzIvD0BSNFE/LJESPbCA8s1jM6bCDPjWbV31xHq7JXaxgpHxLB54RCbBZSlg==", + "requires": { + "@babel/runtime": "^7.0.0", + "prop-types": "^15.6.0" + } + }, "emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", diff --git a/frontend/syntaxmeets/package.json b/frontend/syntaxmeets/package.json index 175dab190..71450beff 100644 --- a/frontend/syntaxmeets/package.json +++ b/frontend/syntaxmeets/package.json @@ -13,6 +13,7 @@ "axios": "^0.21.1", "bootstrap": "^4.5.3", "copy-to-clipboard": "^3.3.1", + "emoji-mart": "^3.0.1", "fontsource-poppins": "^3.0.9", "react": "^16.13.1", "react-ace": "^9.1.4", diff --git a/frontend/syntaxmeets/src/components/Navbar/Navbar.js b/frontend/syntaxmeets/src/components/Navbar/Navbar.js index c749fefd0..39d189592 100644 --- a/frontend/syntaxmeets/src/components/Navbar/Navbar.js +++ b/frontend/syntaxmeets/src/components/Navbar/Navbar.js @@ -106,7 +106,7 @@ const Navbar = (props) => { severity="success" variant="filled" > - Room-ID Copied ! + Invite created ! Share with your friends and have a meet. { const [message, setMessage] = useState(""); const [messages, setMessages] = useState([]); const [typingUser, setTypingUser] = useState(); + const [emojiPickerState, SetEmojiPicker] = useState(false); const messagesEndRef = useRef(null); const [mCount, setMCount] = useState(0); const [state, setState] = useState(false); const handleMessageSubmit = () => { + SetEmojiPicker(false); if (message === "") return; let data = { name: props.name, @@ -69,7 +74,22 @@ const SyntaxChat = (props) => { } }; + function triggerPicker(event) { + event.preventDefault(); + SetEmojiPicker(!emojiPickerState); + } useEffect(scrollToBottom, [messages]); + let emojiPicker; + if (emojiPickerState) { + emojiPicker = ( + setMessage(message + emoji.native)} + // style={{width: "90%", display: "flex"}} + /> + ); + } const toggleDrawer = (open) => (event) => { if ( @@ -150,9 +170,33 @@ const SyntaxChat = (props) => { ) : undefined} - - - + + {/* */} + + {/* */} + + + {/* */} + + + { } }} /> + {/* SetMessage(event.target.value)} + /> */} - + + + + {emojiPicker} + + diff --git a/frontend/syntaxmeets/src/components/SyntaxEditor/LanguageData.js b/frontend/syntaxmeets/src/components/SyntaxEditor/LanguageData.js index 0e01a683f..62acafe5d 100644 --- a/frontend/syntaxmeets/src/components/SyntaxEditor/LanguageData.js +++ b/frontend/syntaxmeets/src/components/SyntaxEditor/LanguageData.js @@ -1,5 +1,4 @@ export const languages = [ - "c_cpp", "clojure", "csharp", @@ -18,8 +17,7 @@ export const languages = [ "sql", "swift", "typescript", - ]; - +]; export const defaultValue = `#include #define lli long long int @@ -40,14 +38,97 @@ int main() return 0; }`; +export const defaultLanguageCode = [ + { + id: 54, + code: '#include \nusing namespace std;\n\nint main() {\n\t\/\/ your code goes here\n\treturn 0;\n}\n', + }, + { + id: 50, + code: '#include \n\nint main(void) {\n\t\/\/ your code goes here\n\treturn 0;\n}\n', + }, + { + id: 86, + code: '; your code goes here\n', + }, + { + id: 62, + code: 'import java.util.*;\nimport java.lang.*;\nimport java.io.*;\n\n\/* Name of the class has to be \"Main\" only if the class is public. *\/\nclass Solution\n{\n\tpublic static void main (String[] args) throws java.lang.Exception\n\t{\n\t\t\/\/ your code goes here\n\t}\n}\n', + }, + { + id: 51, + code: 'using System;\n\npublic class Test\n{\n\tpublic static void Main()\n\t{\n\t\t\/\/ your code goes here\n\t}\n}\n', + }, + { + id: 71, + code: '# your code goes here\n', + }, + { + id: 80, + code: '\n', + }, + { + id: 72, + code: '# your code goes here\n', + }, + { + id: 82, + code: '', + }, + { + id: 83, + code: '', + }, + { + id: 74, + code: '', + }, + { + id: 68, + code: '\n\t% your code goes here\n\ttrue.\n', + }, + { + id: 77, + code: '\t\t\tIDENTIFICATION DIVISION.\n\t\t\tPROGRAM-ID. hello.\n\t\t\tPROCEDURE DIVISION.\n\t\t\tDISPLAY \"Hello World!\".\n\t\t\tSTOP RUN.', + }, + { + id: 74, + code: '', + }, + { + id: 88, + code: '', + }, + { + id: 78, + code: '', + }, + { + id: 63, + code: '', + }, +]; + export const LangOptions = [ - "C" , - "C++" , + "C", + "C++", "Python", "JAVA", "JavaScript", "Kotlin", - "Clojure" , + "Clojure", "C#", "COBOL", "Erlang", @@ -59,11 +140,10 @@ export const LangOptions = [ "Ruby", "SQL", "Swift", - "TypeScript" -] + "TypeScript", +]; export const langId = { - "C" : 50, "C++" : 54, "Clojure" : 86, @@ -83,11 +163,9 @@ export const langId = { "SQL": 82, "Swift": 83, "TypeScript": 74 - - } - +}; + export const langMode = { - "C": "c_cpp", "C++": "c_cpp", "Clojure": "clojure", @@ -107,9 +185,7 @@ export const langMode = { "SQL": "sql", "Swift": "swift", "TypeScript": "typescript", - -} - +}; export const themes = [ "monokai", @@ -123,4 +199,4 @@ export const themes = [ "solarized_dark", "solarized_light", "terminal", - ]; +]; diff --git a/frontend/syntaxmeets/src/components/SyntaxEditor/SyntaxEditor.js b/frontend/syntaxmeets/src/components/SyntaxEditor/SyntaxEditor.js index 30b5b49b5..522ff81a0 100644 --- a/frontend/syntaxmeets/src/components/SyntaxEditor/SyntaxEditor.js +++ b/frontend/syntaxmeets/src/components/SyntaxEditor/SyntaxEditor.js @@ -25,7 +25,7 @@ import Alert from "@material-ui/lab/Alert"; import localClasses from "./SyntaxEditor.module.css"; import { languages, - defaultValue, + defaultLanguageCode, langMode, LangOptions, langId, @@ -75,6 +75,7 @@ const ICE = (props) => { ); }; const SyntaxEditor = (props) => { + const defaultValue = defaultLanguageCode[0].code; const [value, setValue] = useState(defaultValue); const [currLang, setCurrLang] = useState("C++"); const [theme, setTheme] = useState("monokai"); @@ -274,6 +275,8 @@ const SyntaxEditor = (props) => { value={currLang} onChange={(e) => { setCurrLang(e.target.value); + const newCode = defaultLanguageCode.filter(x => x.id == langId[e.target.value]); + setValue(newCode[0].code); }} label="Language" style={{ fontFamily: "poppins", color: "#ffffff" }}