diff --git a/frontend/dashboard.html b/frontend/dashboard.html
new file mode 100644
index 00000000..0fc7e108
--- /dev/null
+++ b/frontend/dashboard.html
@@ -0,0 +1,11 @@
+
+
+
+
+
+ Document
+
+
+ Welcome to LeetCode clone
+
+
\ No newline at end of file
diff --git a/frontend/index.html b/frontend/index.html
new file mode 100644
index 00000000..40efad3a
--- /dev/null
+++ b/frontend/index.html
@@ -0,0 +1,26 @@
+
+
+
+
+
+ Signup Form
+
+
+
+
+
+
+
+
diff --git a/frontend/script.js b/frontend/script.js
new file mode 100644
index 00000000..76324dac
--- /dev/null
+++ b/frontend/script.js
@@ -0,0 +1,25 @@
+document.getElementById('signupForm').addEventListener('submit', function(event) {
+ event.preventDefault();
+
+ const email = document.getElementById('email').value;
+ const password = document.getElementById('password').value;
+
+ fetch('/signup', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({ email, password })
+ })
+ .then(response => response.json())
+ .then(data => {
+ if (data.redirect) {
+ window.location.href = data.redirect;
+ } else {
+ document.getElementById('message').textContent = data.message;
+ }
+ })
+ .catch(error => {
+ document.getElementById('message').textContent = 'Error: ' + error;
+ });
+});
diff --git a/frontend/styles.css b/frontend/styles.css
new file mode 100644
index 00000000..f596f892
--- /dev/null
+++ b/frontend/styles.css
@@ -0,0 +1,54 @@
+body {
+ font-family: Arial, sans-serif;
+ background-color: #f4f4f4;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ height: 100vh;
+}
+
+.container {
+ background-color: white;
+ padding: 20px;
+ border-radius: 8px;
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
+ width: 300px;
+}
+
+h2 {
+ text-align: center;
+}
+
+form {
+ display: flex;
+ flex-direction: column;
+}
+
+label {
+ margin-bottom: 5px;
+}
+
+input {
+ margin-bottom: 10px;
+ padding: 8px;
+ border: 1px solid #ccc;
+ border-radius: 4px;
+}
+
+button {
+ padding: 10px;
+ background-color: #28a745;
+ color: white;
+ border: none;
+ border-radius: 4px;
+ cursor: pointer;
+}
+
+button:hover {
+ background-color: #218838;
+}
+
+#message {
+ margin-top: 10px;
+ text-align: center;
+}
diff --git a/index.js b/index.js
index e189e725..40ab21a9 100644
--- a/index.js
+++ b/index.js
@@ -1,8 +1,10 @@
-const express = require('express')
-const app = express()
-const port = 3001
+const express = require('express');
+const app = express();
+const bodyParser = require('body-parser');
+const port = 3000;
+const path = require('path');
+
-const USERS = [];
const QUESTIONS = [{
title: "Two states",
@@ -14,21 +16,42 @@ const QUESTIONS = [{
}];
-const SUBMISSION = [
+const SUBMISSION = []
+// Middleware to parse JSON bodies
+app.use(bodyParser.json());
-]
+// Serve static files (CSS, JS)
+app.use(express.static(path.join(__dirname, 'frontend')));
+
+const USERS = [];
+//serve for signup page
+app.get('/signup',function(req,res){
+ res.sendFile(path.join(__dirname,'frontend','index.html'));
+});
+
+// Serve the dashboard page
+app.get('/dashboard', (req, res) => {
+ res.sendFile(path.join(__dirname, 'frontend', 'dashboard.html'));
+});
app.post('/signup', function(req, res) {
- // Add logic to decode body
- // body should have email and password
+ const { email, password } = req.body;
+ // Check if the email already exists in the USERS array
+ const userExists = USERS.some(user => user.email === email);
- //Store email and password (as is for now) in the USERS array above (only if the user with the given email doesnt exist)
+ if (userExists) {
+ return res.status(400).send('User with this email already exists');
+ } else {
+ // Store the new user
+ USERS.push({ email, password });
+ // Return back 200 status code to the client
+ res.status(200).json({ message: 'User registered successfully', redirect: '/dashboard' });
+ }
+
+});
- // return back 200 status code to the client
- res.send('Hello World!')
-})
app.post('/login', function(req, res) {
// Add logic to decode body
@@ -68,6 +91,13 @@ app.post("/submissions", function(req, res) {
// Create a route that lets an admin add a new problem
// ensure that only admins can do that.
+
+// Route to Get All Users:
+app.get('/users', (req, res) => { res.json(USERS); });
+// This route returns the contents of the USERS array in JSON format.
+// You can access this route by navigating to http://localhost:3000/users in your browser.
+
+
app.listen(port, function() {
console.log(`Example app listening on port ${port}`)
})
\ No newline at end of file