Skip to content

Commit

Permalink
Merge branch 'Ojas-Arora:main' into rupesh10
Browse files Browse the repository at this point in the history
  • Loading branch information
rupeshv2121 authored Feb 9, 2025
2 parents f2fc606 + 8c08e0f commit 2bce6ef
Show file tree
Hide file tree
Showing 23 changed files with 1,025 additions and 422 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

node_modules
.env
.env
uploads/
12 changes: 9 additions & 3 deletions Server/api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import express from 'express';
import cors from 'cors';
import bodyParser from 'body-parser';
import authRoutes from '../routes/authRoutes.js';
import contactRoutes from '../routes/contactRoutes.js';
import contactRoutes from '../routes/contactRoutes.js';
import testimonialRoutes from '../routes/testimonialRoutes.js';
import path from 'path';

const app = express();

Expand All @@ -13,8 +15,12 @@ app.use(express.urlencoded({ extended: true, limit: '16kb' }));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

// Serve static uploads
app.use('/uploads', express.static(path.join(process.cwd(), 'uploads')));

// Routes
app.use('/api/v1/auth', authRoutes);
app.use('/api/v1/contact', contactRoutes);
app.use('/api/v1/auth', authRoutes);
app.use('/api/v1/contact', contactRoutes);
app.use('/api/v1/testimonials', testimonialRoutes);

export { app };
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
30 changes: 30 additions & 0 deletions Server/controller/testimonialController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import Testimonial from '../models/Testimonial.js';

// Add a new testimonial with image upload
const addTestimonial = async (req, res) => {
try {
const { name, profession, review, stars } = req.body;
const image = req.file ? req.file.path : ''; // Save uploaded image path

const newTestimonial = new Testimonial({ name, profession, review, stars, image });
await newTestimonial.save();

res.status(201).json({ message: 'Testimonial added successfully', testimonial: newTestimonial });
} catch (error) {
console.error('Error adding testimonial:', error);
res.status(500).json({ error: 'Failed to add testimonial' });
}
};

// Get all testimonials
const getTestimonials = async (req, res) => {
try {
const testimonials = await Testimonial.find();
res.status(200).json(testimonials);
} catch (error) {
console.error('Error fetching testimonials:', error);
res.status(500).json({ error: 'Failed to fetch testimonials' });
}
};

export { addTestimonial, getTestimonials };
30 changes: 30 additions & 0 deletions Server/middleware/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import multer from 'multer';
import path from 'path';

// Configure storage for uploaded files
const storage = multer.diskStorage({
destination: (req, file, cb) => {
cb(null, 'uploads/'); // Save files to 'uploads' folder
},
filename: (req, file, cb) => {
cb(null, `${Date.now()}-${file.originalname}`); // Unique filename
},
});

// File type filter (only images allowed)
const fileFilter = (req, file, cb) => {
const allowedTypes = /jpeg|jpg|png/;
const extName = allowedTypes.test(path.extname(file.originalname).toLowerCase());
const mimeType = allowedTypes.test(file.mimetype);

if (extName && mimeType) {
return cb(null, true);
} else {
cb(new Error('Only image files are allowed!'), false);
}
};

// Initialize multer with storage settings
const upload = multer({ storage, fileFilter });

export default upload;
34 changes: 34 additions & 0 deletions Server/models/Testimonial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import mongoose from 'mongoose';

// Testimonial schema
const testimonialSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
profession: {
type: String,
required: true,
},
review: {
type: String,
required: true,
},
stars: {
type: Number,
required: true,
min: 1,
max: 5,
},
image: {
type: String, // Image path
required: false,
},
createdOn: {
type: Date,
default: Date.now, // Automatically set to the current date and time
},
});

const Testimonial = mongoose.model('Testimonial', testimonialSchema);
export default Testimonial;
13 changes: 13 additions & 0 deletions Server/routes/testimonialRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import express from 'express';
import { addTestimonial, getTestimonials } from '../controller/testimonialController.js';
import upload from '../middleware/upload.js'; // Import multer middleware

const router = express.Router();

// Add a testimonial (with image upload)
router.post('/add', upload.single('image'), addTestimonial);

// Get all testimonials
router.get('/all', getTestimonials);

export default router;
9 changes: 8 additions & 1 deletion about.css
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,21 @@ section h2 {
left: 20px;
background-color: transparent;
border: none;
color: var(--back-button-color);
color: #333;
font-size: 24px;
cursor: pointer;
z-index: 999;
transition: color 0.3s ease;
}

.back-button:hover {
color: #d6a52b;
}
body.dark .back-button{
color: white;
}

body.dark .back-button:hover{
color: #d6a52b;
}
.about-section h1 {
Expand Down
11 changes: 9 additions & 2 deletions contact.css
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,23 @@ text-align: left; /* Adjusts text alignment, optional */
left: 20px;
background-color: transparent;
border: none;
color: var(--card-text);
color: #333;
font-size: 24px;
cursor: pointer;
z-index: 999;
transition: color 0.3s ease;
}

.back-button:hover {
color: #d6a52b;
}
body.dark .back-button{
color: white;
}

body.dark .back-button:hover{
color: #d6a52b;
}

.image-button {
position: fixed;
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
14 changes: 10 additions & 4 deletions contributors/contributor.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,23 @@ async function fetchContributors() {

// Certificate content
ctx.font = "35px Arial";
const content = `This certificate is proudly presented to ${username} for their valuable
contribution to SCD-Profile-Score (AJIVIKA) during Social Winter of Code (SWoC)
from January 1, 2025, to March 1, 2025.`;
const content = `This certificate is proudly presented to ${username} for his/her valuable
contribution to SCD-Profile-Score (AJIVIKA). Keep contributing. Best wishes
for your future endeavors.`;
const contentLines = content.split("\n");
contentLines.forEach((line, index) => {
ctx.fillText(line.trim(), canvas.width / 2, 600 + index * 40);
});

// Signature
// Signature with decorative underline
ctx.font = "italic 30px Georgia";
ctx.fillText("Ojas Arora", canvas.width / 1.5, 850);
ctx.strokeStyle = "#5a4637";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(canvas.width / 1.5 - 150, 860);
ctx.lineTo(canvas.width / 1.5 + 150, 860);
ctx.stroke();

// Generated date
const date = new Date().toLocaleString();
Expand Down
7 changes: 5 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/SplitText.min.js"></script>
<script>
(function(){if(!window.chatbase||window.chatbase("getState")!=="initialized"){window.chatbase=(...arguments)=>{if(!window.chatbase.q){window.chatbase.q=[]}window.chatbase.q.push(arguments)};window.chatbase=new Proxy(window.chatbase,{get(target,prop){if(prop==="q"){return target.q}return(...args)=>target(prop,...args)}})}const onLoad=function(){const script=document.createElement("script");script.src="https://www.chatbase.co/embed.min.js";script.id="O4Bsj_2mPuKJkReCrKXbp";script.domain="www.chatbase.co";document.body.appendChild(script)};if(document.readyState==="complete"){onLoad()}else{window.addEventListener("load",onLoad)}})();
</script>
<link rel="stylesheet" href="styles.css" />
<link rel="stylesheet" href="navbar.css" />
<style>
Expand Down Expand Up @@ -1458,9 +1461,9 @@ <h3>
</button>

<!-- Floating Chat Button -->
<button class="chat-button" onclick="window.location.href='./chatbot.html'">
<!-- <button class="chat-button" onclick="window.location.href='./chatbot.html'">
<i class="fas fa-comments"></i>
</button>
</button> -->

<!-- Floating Image Button -->
<button class="image-button">
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
30 changes: 28 additions & 2 deletions login.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,31 @@
.toggle-icon:hover {
color: #333;
}

.back-button {
position: absolute;
top: 100px;
left: 20px;
background-color: transparent;
border: none;
color: #333;
font-size: 24px;
cursor: pointer;
z-index: 999;
transition: color 0.3s ease;
}

.back-button:hover {
color: #d6a52b;
}
body.dark .back-button{
color: white;
}

body.dark .back-button:hover{
color: #d6a52b;
}

</style>
</head>
<body>
Expand Down Expand Up @@ -162,7 +187,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 +196,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 +411,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 2bce6ef

Please sign in to comment.