Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions frontend/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Welcome to LeetCode clone</h1>
</body>
</html>
26 changes: 26 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Signup Form</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h2>Signup</h2>
<form id="signupForm">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>

<label for="password">Password:</label>
<input type="password" id="password" name="password" required>

<button type="submit">Signup</button>
</form>
<p id="message"></p>
</div>
<script src="script.js"></script>
</body>
</html>

25 changes: 25 additions & 0 deletions frontend/script.js
Original file line number Diff line number Diff line change
@@ -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;
});
});
54 changes: 54 additions & 0 deletions frontend/styles.css
Original file line number Diff line number Diff line change
@@ -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;
}
54 changes: 42 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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}`)
})