Skip to content

Commit

Permalink
Merge pull request #435 from ShivanshPlays/AdminBackend
Browse files Browse the repository at this point in the history
Admin backend #435
  • Loading branch information
Anuj3553 authored Nov 10, 2024
2 parents 3306958 + f0fb36b commit 84bdc78
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 1 deletion.
3 changes: 2 additions & 1 deletion client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import ProjectState from "./context/ProjectState";
import ProfileState from "./context/ProfileState";
import CodeOfConduct from "./component/Footers/Codeofconduct";
import Feedback from "./component/Footers/Feedback";
import Faqsec from "./component/Faqsec"
import ContactUs from "./component/Footers/Contactus";
import PrivacyPolicy from "./component/Footers/Privacypolicy";
import TermOfUse from "./component/Footers/TermOfUse";
Expand Down Expand Up @@ -153,6 +154,7 @@ function App() {
<Route exact path='/uploadProject' element={<UploadProject mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
<Route exact path='/createBlogPost' element={<CreateBlog />} />
<Route exact path='/read-more-blog/:id' element={<ReadMoreBlog mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
<Route exact path='/faq' element={<Faqsec mode={mode} setProgress={setProgress} showAlert={showAlert} />} />
<Route exact path='/*' element={<NotFound />} />
</Routes>
</Layout>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions client/src/component/Faqsec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { useState } from 'react';
import faqimage from "../assets/images/vector-faq-frequently-asked-questions.png"
const FAQSection = () => {
const [activeIndex, setActiveIndex] = useState(null);

const faqs = [
{ question: "What is Bitbox?", answer: "Bitbox is a collaborative platform for developers to share and find solutions to coding projects, enhancing project development and troubleshooting." },
{ question: "Who can use Bitbox?", answer: "Bitbox is suitable for developers, students, and tech enthusiasts seeking collaboration on coding projects or guidance." },
{ question: "How can I submit a project on Bitbox?", answer: "Sign up and click 'Submit Project' to share details and engage with the community." },
{ question: "Is Bitbox free to use?", answer: "Yes, Bitbox is currently free for project submission and collaboration." },
{ question: "Can I get feedback on my code?", answer: "Yes, community members can provide feedback and suggestions on projects." },
{ question: "What types of projects are welcome on Bitbox?", answer: "All coding projects across languages and frameworks are welcome on Bitbox." },
{ question: "How do I report inappropriate content?", answer: "Click the 'Report' button on any content, and our moderators will review it." },
{ question: "Can I connect with other users?", answer: "Yes, you can comment on projects and join discussions to collaborate." },
{ question: "Is Bitbox limited to specific programming languages?", answer: "No, Bitbox supports projects in various programming languages and frameworks." },
{ question: "How do I stay updated on new projects?", answer: "Sign up for notifications or follow popular projects for updates on the latest content." }
];


const handleToggle = (index) => {
setActiveIndex(activeIndex === index ? null : index);
};

return (
<div className="p-6 bg-gray-100 rounded-lg mt-4 dark:from-gray-900 dark:to-gray-800 mb-4">
<h2 className="text-[3rem] font-semibold mb-4 mt-20">Frequently Asked Questions</h2>

<div className='flex justify-around'>
<div>
<img src={faqimage} alt="Description w-1/2" className='object-cover'style={{ width: '600px', }}/>
</div>
<div className="space-y-4 w-1/2">
{faqs.map((faq, index) => (
<div key={index} className="bg-white rounded-lg shadow-md">
<div
className="p-4 cursor-pointer bg-gray-200 rounded-t-lg hover:bg-gray-300 transition duration-200"
onClick={() => handleToggle(index)}
>
<h3 className="text-lg font-medium">{faq.question}</h3>
</div>
{activeIndex === index && (
<div className="p-4 bg-gray-50 rounded-b-lg">
<p>{faq.answer}</p>
</div>
)}
</div>
))}
</div>
</div>
</div>
);
};

export default FAQSection;
3 changes: 3 additions & 0 deletions client/src/component/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ const Footer = (props) => {
<li className="nav-item">
<Link to="/termofuse">Terms of use</Link>
</li>
<li className='nav-item'>
<Link to='/faq'>FAQs</Link>
</li>
</ul>
</div>
</div>
Expand Down
87 changes: 87 additions & 0 deletions server/Controllers/adminController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const Admin = require("../Models/Admin");
const bcrypt = require("bcrypt");
var jwt = require("jsonwebtoken");
const nodemailer = require("nodemailer");
const crypto = require("crypto");
require('dotenv').config(); // Load environment variables from .env file
const { body, validationResult } = require("express-validator");
const login= async (req, res) => {
let success = false;
console.log("see");

// Check for validation errors
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}

const { email, password } = req.body;

try {
let user = await Admin.findOne({ email });

// If user does not exist
if (!user) {
return res.status(400).json({
success,
error: "Please try to login with correct credentials",
});
}

// Compare provided password with stored password
const passwordCompare = await bcrypt.compare(password, user.password);

if (!passwordCompare) {
return res.status(400).json({
success,
error: "Please try to login with correct credentials",
});
}

// Create JWT payload
const data = {
user: {
id: user.id,
},
};

// Sign the JWT
const authtoken = jwt.sign(data, process.env.JWT_SECRET);
// Send token in response to be stored in localStorage on the client
return res.status(200).json({ success: true, authtoken });
} catch (error) {
console.error(error.message);
return res.status(500).send("Internal Server Error");
}
}
const createAdmin=async (req, res) => {
const { name, email, password } = req.body;

try {
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(password, saltRounds);

// Create a new user (save in your database)
const user = new Admin({ name, email, password: hashedPassword });

await user.save();
return res.status(201).json({ success: true, message: "Admin created successfully"})
} catch (error) {
res.status(500).json({ success: false, message: error.message });
}
};
const logout=async (req,res)=>{
// Optionally, you can clear the cookie if you're using cookies for sessions
res.clearCookie('connect.sid'); // Replace 'connect.sid' with your session cookie name

// Send a success response
return res.status(200).json({ message: 'Successfully logged out.' });

}
const dashboard= null;


module.exports = {
login,
createAdmin,
};
31 changes: 31 additions & 0 deletions server/Models/Admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const mongoose = require("mongoose");
const { Schema } = mongoose;

const AdminSchema = new Schema(
{
imageUrl: {
type: String,
required: false
},
name: {
type: String,
required: true
},
email: {
type: String,
required: true,
unique: true,
match: [/\S+@\S+\.\S+/, 'Please enter a valid email address'],
},
password: {
type: String,
required: true,
minlength: 8 // Minimum length for password
},
},
{ timestamps: true }
);

const Admin = mongoose.model('Admin', AdminSchema);
module.exports = Admin;

1 change: 1 addition & 0 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ app.use("/api/contact", require("./routes/contact"));
app.use("/api/blog", require("./routes/blog"));
app.use("/api/visitor", require("./routes/visitor"));
app.use("/api/showcaseProjects", require("./routes/projectsRoute"));
app.use("/api/admin", require("./routes/adminRoute"))
app.use("/api/discussion", require("./routes/discussionRoutes"));

// Socket.io connection handling
Expand Down
18 changes: 18 additions & 0 deletions server/routes/adminRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

const express = require("express");
var jwt = require("jsonwebtoken");
const {login,createAdmin}= require("../Controllers/adminController")
const User = require("../Models/Admin.js");
const bcrypt = require("bcrypt");
const router = express.Router();
require("dotenv").config();
const { body, validationResult } = require("express-validator");
const { OAuth2Client } = require("google-auth-library");
const rateLimit = require("express-rate-limit");
require('dotenv').config(); // Load environment variables from .env file


router.post("/login",login)
router.post("/create",createAdmin)

module.exports = router;

0 comments on commit 84bdc78

Please sign in to comment.