Skip to content

Commit

Permalink
Merge branch 'Ojas-Arora:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
efshaperveen authored Feb 8, 2025
2 parents 4b5210f + 7967ce7 commit 9dfeb99
Show file tree
Hide file tree
Showing 8 changed files with 363 additions and 32 deletions.
23 changes: 7 additions & 16 deletions Server/api/dbconnect.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
import mongoose from 'mongoose';
import dotenv from 'dotenv'

dotenv.config()
// Database connection
export const dbConnect = async () => {
const url = process.env.MONGO_URI;

if (!url) {
console.error('No URL received from env. Check .env file path.');
process.exit(1);
}

const dbConnect = async () => {
try {
await mongoose.connect(url);
console.log('MongoDB connected');
} catch (err) {
console.error('Database connection error:', err);
process.exit(1); // Exit process with failure
await mongoose.connect('mongodb://127.0.0.1:27017/scd_profile_db');
console.log("Database connected successfully!");
} catch (error) {
console.error("Database connection error:", error);
}
};

export default dbConnect;
2 changes: 1 addition & 1 deletion Server/api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dotenv from 'dotenv';
import { dbConnect } from './dbconnect.js';
import dbConnect from './dbconnect.js';
import { app } from './app.js';

// Load environment variables
Expand Down
2 changes: 1 addition & 1 deletion contributors/contributor.css
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ body.dark p {
position: sticky;
height: 80px;
top: 0;
z-index: 1;
z-index: 9999;
}
.navbar .logo h2{
margin-top: 10px;
Expand Down
35 changes: 35 additions & 0 deletions js/login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
document.addEventListener('DOMContentLoaded', function() {
const loginForm = document.getElementById('loginForm');
if (loginForm) {
loginForm.addEventListener('submit', handleLoginSubmit);
}
});

function handleLoginSubmit(event) {
event.preventDefault(); // Prevent the default form submission

const email = document.getElementById('email').value;
const password = document.getElementById('password').value;

const formData = { email, password };


fetch('http://localhost:3000/api/v1/auth/login', {

method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
})
.then(response => response.json())
.then(data => {
if (data.token) {
alert('Login successful!');
localStorage.setItem('authToken', data.token);
window.location.href = './index.html';
} else {
alert('Login failed: ' + data.message);
}
})
.catch(error => console.error('Error:', error));
}

2 changes: 1 addition & 1 deletion js/signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ document.addEventListener('DOMContentLoaded', function() {
if (data.token) {
alert('Signup successful! You are now logged in.');
localStorage.setItem('authToken', data.token);
window.location.href = '/SCD-Profile-Score/';
window.location.href = './index.html';
} else {
alert('Signup failed: ' + data.message);
}
Expand Down
5 changes: 3 additions & 2 deletions login.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<div class="right-section">
<h1>Members Log in</h1>
<p class="subtitle">Login to start your journey...</p>
<form id="loginForm" class="login-form">
<form id="loginForm" method="post" class="login-form">
<div class="input-group">
<label for="email"> <i class="fas fa-envelope"></i> Email </label>
<input
Expand All @@ -171,7 +171,7 @@ <h1>Members Log in</h1>
placeholder="Enter your email"
required
/>
<p class="error" id="errorMessage"></p>
<!-- <p class="error" id="errorMessage"></p> -->
</div>
<div class="input-group">
<label for="password">
Expand Down Expand Up @@ -386,5 +386,6 @@ <h1>Members Log in</h1>
window.location.href = 'index.html';
});
</script>
<script type="module" src="js/login.js"></script>
</body>
</html>
Loading

0 comments on commit 9dfeb99

Please sign in to comment.