Skip to content

Commit

Permalink
added login page
Browse files Browse the repository at this point in the history
  • Loading branch information
StarKnightt committed Feb 2, 2024
1 parent f632770 commit 02b00fb
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 66 deletions.
116 changes: 61 additions & 55 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Load environment variables from a .env file
require('dotenv').config();
require("dotenv").config();

// Import required libraries/modules
const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const dotenv = require("dotenv");
const path = require("path")
const path = require("path");

// Create an instance of Express
const app = express();
Expand All @@ -21,14 +21,16 @@ const password = process.env.MONGODB_PASSWORD || process.env.SECRET;
const dbname = process.env.MONGODB_DBNAME || process.env.SECRET_KEY;

// Connect to MongoDB using mongoose
mongoose.connect(`mongodb+srv://${'prasenjitt4e'}:${'N0QLJsk5MVYYBuQ9'}@cluster0.j4relx6.mongodb.net/?retryWrites=true&w=majority`)
mongoose.connect(
`mongodb+srv://${"prasenjitt4e"}:${"N0QLJsk5MVYYBuQ9"}@cluster0.j4relx6.mongodb.net/?retryWrites=true&w=majority`
);

// Define the schema for user registration
const registrationSchema = new mongoose.Schema({
name: String,
email: String,
password: String,
number: String
name: String,
email: String,
password: String,
number: String,
});

// Create a model based on the registration schema
Expand All @@ -39,94 +41,98 @@ app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

// Middleware for serving static files from the 'public' directory
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, "public")));

// Define routes

// Home page route
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
res.sendFile(__dirname + "/index.html");
});

// Registration page route
app.get("/registerPage", (req, res) => {
res.sendFile(__dirname + "/pages/index.html");
res.sendFile(__dirname + "/pages/index.html");
});

// Login Page route
app.get("/loginPage", (req, res) => {
res.sendFile(__dirname + "/pages/login.html");
res.sendFile(__dirname + "/pages/login.html");
});

// Registration endpoint
app.post("/register", async (req, res) => {
try {
const { name, email, password, number } = req.body;

// Check if the user with the given email already exists
const existingUser = await Registration.findOne({ email });

if (!existingUser) {
// If user doesn't exist, create a new registration and save it
const registrationData = new Registration({ name, email, password, number });
await registrationData.save();
return res.redirect("/success");
} else {
// If user already exists, redirect to an error page
console.log("User already exists");
return res.redirect("/error");
}
} catch (error) {
// Handle any errors during registration
console.log(error);
return res.redirect("/error");
try {
const { name, email, password, number } = req.body;

// Check if the user with the given email already exists
const existingUser = await Registration.findOne({ email });

if (!existingUser) {
// If user doesn't exist, create a new registration and save it
const registrationData = new Registration({
name,
email,
password,
number,
});
await registrationData.save();
return res.redirect("/success");
} else {
// If user already exists, redirect to an error page
console.log("User already exists");
return res.redirect("/error");
}
} catch (error) {
// Handle any errors during registration
console.log(error);
return res.redirect("/error");
}
});

app.post("/login", async (req, res) => {
try {
const { email, password } = req.body;

// Check if the user with the given email and password exists
const existingUser = await Registration.findOne({ email, password });

if (existingUser) {
// If user exists, redirect to success page (you can customize this)
return res.redirect("/success");
} else {
// If user doesn't exist or password is incorrect, redirect to error page
console.log("Invalid email or password");
return res.redirect("/error");
}
} catch (error) {
// Handle any errors during login
console.log(error);
return res.redirect("/error");
try {
const { email, password } = req.body;

// Check if the user with the given email and password exists
const existingUser = await Registration.findOne({ email, password });

if (existingUser) {
// If user exists, redirect to success page (you can customize this)
return res.redirect("/");
} else {
// If user doesn't exist or password is incorrect, redirect to error page
console.log("Invalid email or password");
return res.redirect("/error");
}
} catch (error) {
// Handle any errors during login
console.log(error);
return res.redirect("/error");
}
});

// Success page route
app.get("/success", (req, res) => {
res.sendFile(__dirname + "/pages/success.html");
res.sendFile(__dirname + "/pages/success.html");
});

// Resume page route
app.get("/resume", (req, res) => {
res.sendFile(__dirname + "/resume.html");
res.sendFile(__dirname + "/resume.html");
});

// Error page route
app.get("/error", (req, res) => {
res.sendFile(__dirname + "/pages/error.html");
res.sendFile(__dirname + "/pages/error.html");
});

// Route to serve the main CSS file
app.get("/all-styles", (req, res) => {
res.sendFile(__dirname + "/public/css/main.css");
res.sendFile(__dirname + "/public/css/main.css");
});


// Start the server and listen on the specified port
app.listen(port, () => {
console.log(`Server is running http://localhost:${port}`);
console.log(`Server is running http://localhost:${port}`);
});
16 changes: 5 additions & 11 deletions pages/Login.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,8 @@
<div class="col-lg-6 mb-5 mb-lg-0" style="z-index: 10">
<h1 class="my-5 display-5 fw-bold ls-tight" style="color: hsl(218, 81%, 95%)">
Welcome to <br />
<span style="color: hsl(218, 81%, 75%)">Desphixs</span>
</h1>
<p class="mb-4 opacity-70" style="color: hsl(218, 81%, 85%)">
Lorem ipsum dolor, sit amet consectetur adipisicing elit.
Temporibus, expedita iusto veniam atque, magni tempora mollitia
dolorum consequatur nulla, neque debitis eos reprehenderit quasi
ab ipsum nisi dolorem modi. Quos?
</p>
<span style="color: hsl(218, 81%, 75%)">Resume-Builder</span>

</div>

<div class="col-lg-6 mb-5 mb-lg-0 position-relative">
Expand All @@ -86,14 +80,14 @@ <h1 class="mb-3 h3">Login</h1>

<!-- Email input -->
<div class="form-outline mb-4">
<label class="form-label" for="form3Example3">Email address</label>
<input type="email" name="email" id="form3Example3" class="form-control" />
<label class="form-label" for="form3Example3">Email address</label>
</div>

<!-- Password input -->
<div class="form-outline mb-4">
<label class="form-label" for="form3Example4">Password</label>
<input type="password" name="password" id="form3Example4" class="form-control" />
<label class="form-label" for="form3Example4">Password</label>
</div>


Expand All @@ -104,7 +98,7 @@ <h1 class="mb-3 h3">Login</h1>

<!-- Register buttons -->
<div class="text-center">
<p>Don't have an account yet? <a href="/pages/index.html">Register</a></p>
<p>Don't have an account yet? <a href="/registerPage">Register</a></p>

</div>
</form>
Expand Down

0 comments on commit 02b00fb

Please sign in to comment.